mirror of
				https://github.com/nerzhul/ocsms.git
				synced 2025-10-31 02:17:38 +00:00 
			
		
		
		
	Cleanup global variables to add a selectedContact selector directly to angular app
This commit is contained in:
		
							parent
							
								
									74c365f1f7
								
							
						
					
					
						commit
						1a1c2e5136
					
				| @ -11,8 +11,6 @@ | |||||||
| 
 | 
 | ||||||
| // Some global vars to improve performances
 | // Some global vars to improve performances
 | ||||||
| var g_selectedConversation = null; | var g_selectedConversation = null; | ||||||
| var g_curPhoneNumber = null; |  | ||||||
| var g_curContactName = ''; |  | ||||||
| var g_lastMsgDate = 0; | var g_lastMsgDate = 0; | ||||||
| var g_unreadCountCurrentConv = 0; | var g_unreadCountCurrentConv = 0; | ||||||
| var g_unreadCountAllConv = 0; | var g_unreadCountAllConv = 0; | ||||||
| @ -74,6 +72,8 @@ app.controller('OcSmsController', ['$scope', '$interval', '$timeout', '$compile' | |||||||
| 		$scope.messages = []; | 		$scope.messages = []; | ||||||
| 		$scope.totalMessageCount = 0; | 		$scope.totalMessageCount = 0; | ||||||
| 		$scope.photoVersion = 1; | 		$scope.photoVersion = 1; | ||||||
|  | 		$scope.selectedContact = {}; | ||||||
|  | 
 | ||||||
| 		// Settings
 | 		// Settings
 | ||||||
| 		$scope.sendCountry = function () { | 		$scope.sendCountry = function () { | ||||||
| 			$.post(OC.generateUrl('/apps/ocsms/set/country'),{'country': $('select[name=intl_phone]').val()}); | 			$.post(OC.generateUrl('/apps/ocsms/set/country'),{'country': $('select[name=intl_phone]').val()}); | ||||||
| @ -119,26 +119,16 @@ app.controller('OcSmsController', ['$scope', '$interval', '$timeout', '$compile' | |||||||
| 					$scope.formatConversation(jsondata); | 					$scope.formatConversation(jsondata); | ||||||
| 
 | 
 | ||||||
| 					if (typeof jsondata['contactName'] == 'undefined' || jsondata['contactName'] == '') { | 					if (typeof jsondata['contactName'] == 'undefined' || jsondata['contactName'] == '') { | ||||||
| 						$('#ocsms-phone-label').html(phoneNumberLabel); | 						$scope.selectedContact.label = phoneNumberLabel; | ||||||
| 						g_curContactName = phoneNumberLabel; | 						$scope.selectedContact.opt_numbers = ""; | ||||||
| 						$('#ocsms-phone-opt-number').html(''); |  | ||||||
| 					} | 					} | ||||||
| 					else { | 					else { | ||||||
| 						$('#ocsms-phone-label').html(jsondata['contactName']); | 						$scope.selectedContact.label = jsondata['contactName']; | ||||||
| 						g_curContactName = jsondata['contactName']; | 						$scope.selectedContact.opt_numbers = phoneNumberLabel; | ||||||
| 						$('#ocsms-phone-opt-number').html(phoneNumberLabel); |  | ||||||
| 					} | 					} | ||||||
| 
 | 
 | ||||||
| 					$scope.totalMessageCount = jsondata['msgCount'] !== undefined ? jsondata['msgCount'] : 0; | 					$scope.totalMessageCount = jsondata['msgCount'] !== undefined ? jsondata['msgCount'] : 0; | ||||||
| 
 | 
 | ||||||
| 					if ($('#app-content-header').is(':hidden')) { |  | ||||||
| 						$('#app-content-header').show(); |  | ||||||
| 					} |  | ||||||
| 
 |  | ||||||
| 					if ($('#ocsms-conversation-removal').is(':hidden')) { |  | ||||||
| 						$('#ocsms-conversation-removal').show(); |  | ||||||
| 					} |  | ||||||
| 
 |  | ||||||
| 					$('#app-content').scrollTop(1E10); | 					$('#app-content').scrollTop(1E10); | ||||||
| 
 | 
 | ||||||
| 					g_curPhoneNumber = phoneNumber; | 					g_curPhoneNumber = phoneNumber; | ||||||
| @ -167,20 +157,12 @@ app.controller('OcSmsController', ['$scope', '$interval', '$timeout', '$compile' | |||||||
| 						if (document.hasFocus() == false) { | 						if (document.hasFocus() == false) { | ||||||
| 							g_unreadCountCurrentConv += fmt[0]; | 							g_unreadCountCurrentConv += fmt[0]; | ||||||
| 							document.title = g_originalTitle + " (" + g_unreadCountCurrentConv + ")"; | 							document.title = g_originalTitle + " (" + g_unreadCountCurrentConv + ")"; | ||||||
| 							$scope.desktopNotify(g_unreadCountCurrentConv + " unread message(s) in conversation with " + g_curContactName); | 							$scope.desktopNotify(g_unreadCountCurrentConv + " unread message(s) in conversation with " + $scope.selectedContact.label); | ||||||
| 						} | 						} | ||||||
| 						 | 						 | ||||||
| 					} | 					} | ||||||
| 					 | 					 | ||||||
| 					$scope.totalMessageCount = jsondata['msgCount'] !== undefined ? jsondata['msgCount'] : 0; | 					$scope.totalMessageCount = jsondata['msgCount'] !== undefined ? jsondata['msgCount'] : 0; | ||||||
| 
 |  | ||||||
| 					if ($('#ocsms-conversation-removal').is(':hidden')) { |  | ||||||
| 						$('#ocsms-conversation-removal').show(); |  | ||||||
| 					} |  | ||||||
| 
 |  | ||||||
| 					if ($('#app-content-header').is(':hidden')) { |  | ||||||
| 						$('#app-content-header').show(); |  | ||||||
| 					} |  | ||||||
| 				} | 				} | ||||||
| 			); | 			); | ||||||
| 		}; | 		}; | ||||||
| @ -189,7 +171,6 @@ app.controller('OcSmsController', ['$scope', '$interval', '$timeout', '$compile' | |||||||
| 			$.getJSON(OC.generateUrl('/apps/ocsms/get/new_messages'), | 			$.getJSON(OC.generateUrl('/apps/ocsms/get/new_messages'), | ||||||
| 				{ 'lastDate': g_lastMsgDate }, | 				{ 'lastDate': g_lastMsgDate }, | ||||||
| 				function(jsondata, status) { | 				function(jsondata, status) { | ||||||
| 					var peerListBuf = ''; |  | ||||||
| 					var bufferedContacts = []; | 					var bufferedContacts = []; | ||||||
| 
 | 
 | ||||||
| 					$.each(jsondata['phonelist'], function(id, val) { | 					$.each(jsondata['phonelist'], function(id, val) { | ||||||
| @ -197,7 +178,6 @@ app.controller('OcSmsController', ['$scope', '$interval', '$timeout', '$compile' | |||||||
| 						idxVal = id.replace(/\//g,' '); | 						idxVal = id.replace(/\//g,' '); | ||||||
| 						idxVal2 = idxVal.replace('/ /g',''); | 						idxVal2 = idxVal.replace('/ /g',''); | ||||||
| 						if (typeof jsondata['contacts'][id] == 'undefined') { | 						if (typeof jsondata['contacts'][id] == 'undefined') { | ||||||
| 							fn = ''; |  | ||||||
| 							peerLabel = idxVal; | 							peerLabel = idxVal; | ||||||
| 						} | 						} | ||||||
| 						else { | 						else { | ||||||
| @ -253,12 +233,10 @@ app.controller('OcSmsController', ['$scope', '$interval', '$timeout', '$compile' | |||||||
| 		}; | 		}; | ||||||
| 
 | 
 | ||||||
| 		$scope.removeConversation = function() { | 		$scope.removeConversation = function() { | ||||||
| 			$.post(OC.generateUrl('/apps/ocsms/delete/conversation'), {"contact": g_curContactName}, function(data) { | 			$.post(OC.generateUrl('/apps/ocsms/delete/conversation'), {"contact": $scope.selectedContact.label}, function(data) { | ||||||
| 				// Reinit main window
 | 				// Reinit main window
 | ||||||
| 				$('#ocsms-phone-label').html(''); | 				$scope.selectedContact.label = ""; | ||||||
| 				$('#ocsms-phone-opt-number').html(''); | 				$scope.selectedContact.opt_numbers = ""; | ||||||
| 				$('#ocsms-conversation-removal').hide(); |  | ||||||
| 				$('#app-content-header').hide(); |  | ||||||
| 				$scope.removeContact({'nav': g_curPhoneNumber}); | 				$scope.removeContact({'nav': g_curPhoneNumber}); | ||||||
| 				$scope.$apply(function () { | 				$scope.$apply(function () { | ||||||
| 					$scope.messages = []; | 					$scope.messages = []; | ||||||
| @ -307,7 +285,8 @@ app.controller('OcSmsController', ['$scope', '$interval', '$timeout', '$compile' | |||||||
| 			for (var i=0; i < len; i++) { | 			for (var i=0; i < len; i++) { | ||||||
| 				var curMsg = $scope.messages[i]; | 				var curMsg = $scope.messages[i]; | ||||||
| 				if (curMsg['id'] == msgId) { | 				if (curMsg['id'] == msgId) { | ||||||
| 					$.post(OC.generateUrl('/apps/ocsms/delete/message'), {"messageId": msgId, "phoneNumber": g_curContactName}, function(data) { | 					$.post(OC.generateUrl('/apps/ocsms/delete/message'), | ||||||
|  | 						{"messageId": msgId, "phoneNumber": $scope.selectedContact.label}, function(data) { | ||||||
| 						$scope.$apply(function () { | 						$scope.$apply(function () { | ||||||
| 							$scope.messages.splice(i, 1); | 							$scope.messages.splice(i, 1); | ||||||
| 						}); | 						}); | ||||||
|  | |||||||
| @ -46,8 +46,9 @@ use \OCA\OcSms\Lib\CountryCodes; | |||||||
| 	</div> | 	</div> | ||||||
| 
 | 
 | ||||||
| 	<div id="app-content"> | 	<div id="app-content"> | ||||||
| 		<div id="app-content-header" style="display: none;">	 | 		<div id="app-content-header" ng-show="selectedContact.label !== undefined && selectedContact.label !== ''"> | ||||||
| 			<div id="ocsms-phone-label"></div><div id="ocsms-conversation-removal" class="icon-delete svn delete action" ng-click="removeConversation();"></div> | 			<div id="ocsms-phone-label">{{ selectedContact.label }} </div> | ||||||
|  | 			<div id="ocsms-conversation-removal" class="icon-delete svn delete action" ng-click="removeConversation();">{{ selectedContact.opt_numbers }}</div> | ||||||
| 			<div id="ocsms-phone-opt-number"></div> | 			<div id="ocsms-phone-opt-number"></div> | ||||||
| 			<div id="ocsms-phone-msg-nb">{{ messages.length }} message(s) shown. {{ totalMessageCount }} message(s) stored in database.</div> | 			<div id="ocsms-phone-msg-nb">{{ messages.length }} message(s) shown. {{ totalMessageCount }} message(s) stored in database.</div> | ||||||
| 			 | 			 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user