1
0
mirror of https://github.com/nerzhul/ocsms.git synced 2025-06-07 07:56:23 +00:00

Try to migrate settings to a better model

This commit is contained in:
Loic Blot 2017-12-28 18:18:03 +01:00
parent 167643c8df
commit fd0f221d64
No known key found for this signature in database
GPG Key ID: EFAA458E8C153987
3 changed files with 36 additions and 26 deletions

View File

@ -41,10 +41,7 @@ app.controller('OcSmsController', ['$scope', '$interval', '$timeout', '$compile'
{text: "Send"} {text: "Send"}
]; ];
$scope.setting_msgLimit = 100; $scope.vsettings = SmsSettings;
$scope.setting_enableNotifications = 1;
$scope.setting_contactOrder = 'lastmsg';
$scope.setting_contactOrderReverse = true;
$scope.contacts = []; $scope.contacts = [];
$scope.messages = []; $scope.messages = [];
@ -68,25 +65,22 @@ app.controller('OcSmsController', ['$scope', '$interval', '$timeout', '$compile'
}; };
$scope.setMessageLimit = function () { $scope.setMessageLimit = function () {
if ($scope.setting_msgLimit === null || $scope.setting_msgLimit === undefined) { $.post($scope.generateUrl('/set/msglimit'), {'limit': SmsSettings.messageLimit});
return;
}
$.post($scope.generateUrl('/set/msglimit'), {'limit': $scope.setting_msgLimit});
}; };
$scope.setNotificationSetting = function () { $scope.setNotificationSetting = function () {
if ($scope.setting_enableNotifications < 0 || $scope.setting_enableNotifications > 2) { $.post($scope.generateUrl('/set/notification_state'),
$scope.setting_enableNotifications = 0; {
return; 'notification': SmsSettings.enableNotifications ? 1 : 0
} }
$.post($scope.generateUrl('/set/notification_state'), {'notification': $scope.setting_enableNotifications}); );
}; };
$scope.setContactOrderSetting = function () { $scope.setContactOrderSetting = function () {
$.post($scope.generateUrl('/set/contact_order'), $.post($scope.generateUrl('/set/contact_order'),
{ {
'attribute': $scope.setting_contactOrder, 'attribute': SmsSettings.contactOrderBy,
'reverse': $scope.setting_contactOrderReverse 'reverse': SmsSettings.reverseContactOrder
} }
); );
}; };
@ -334,10 +328,10 @@ app.controller('OcSmsController', ['$scope', '$interval', '$timeout', '$compile'
$('select[name=setting_contact_order]').val(jsondata["contact_order"]); $('select[name=setting_contact_order]').val(jsondata["contact_order"]);
$('input[name=setting_contact_order_reverse]').val(toBool(jsondata["contact_order_reverse"])); $('input[name=setting_contact_order_reverse]').val(toBool(jsondata["contact_order_reverse"]));
$scope.setting_msgLimit = parseInt(jsondata["message_limit"]); SmsSettings.messageLimit = parseInt(jsondata["message_limit"]);
$scope.setting_enableNotifications = jsondata["notification_state"]; SmsSettings.enableNotifications = parseInt(jsondata["notification_state"]) !== 0;
$scope.setting_contactOrder = jsondata["contact_order"]; SmsSettings.contactOrderBy = jsondata["contact_order"];
$scope.setting_contactOrderReverse = toBool(jsondata["contact_order_reverse"]); SmsSettings.reverseContactOrder = toBool(jsondata["contact_order_reverse"]);
} }
}); });
}; };
@ -426,7 +420,7 @@ app.controller('OcSmsController', ['$scope', '$interval', '$timeout', '$compile'
}; };
$scope.desktopNotify = function (msg) { $scope.desktopNotify = function (msg) {
if ($scope.setting_enableNotifications === 0) { if (!SmsSettings.enableNotifications) {
return; return;
} }

16
js/devel/settings.js Normal file
View File

@ -0,0 +1,16 @@
/**
* Nextcloud - Phone Sync
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Loic Blot <loic.blot@unix-experience.fr>
* @copyright Loic Blot 2014-2017
*/
var SmsSettings = {
messageLimit: 100,
enableNotifications: true,
contactOrderBy: 'lastmsg',
reverseContactOrder: true
};

View File

@ -12,7 +12,7 @@ use \OCA\OcSms\Lib\CountryCodes;
<div id="app-contacts-loader" class="icon-loading" ng-show="isContactsLoading"> <div id="app-contacts-loader" class="icon-loading" ng-show="isContactsLoading">
</div> </div>
<ul class="contact-list" ng-show="!isContactsLoading"> <ul class="contact-list" ng-show="!isContactsLoading">
<li ng-repeat="contact in contacts | orderBy:setting_contactOrder:setting_contactOrderReverse" peer-label="{{ contact.label }}" ng-click="loadConversation(contact);" href="#"> <li ng-repeat="contact in contacts | orderBy:vsettings.contactOrderBy:vsettings.reverseContactOrder" peer-label="{{ contact.label }}" ng-click="loadConversation(contact);" href="#">
<img class="ocsms-plavatar" ng-src="{{ contact.avatar }}" ng-show="contact.avatar !== undefined" /> <img class="ocsms-plavatar" ng-src="{{ contact.avatar }}" ng-show="contact.avatar !== undefined" />
<div class="ocsms-plavatar" ng-show="contact.avatar === undefined" ng-style="{'background-color': (contact.uid | peerColor)}">{{ contact.label | firstCharacter }}</div> <div class="ocsms-plavatar" ng-show="contact.avatar === undefined" ng-style="{'background-color': (contact.uid | peerColor)}">{{ contact.label | firstCharacter }}</div>
<a class="ocsms-plname" style="{{ contact.unread > 0 ? 'font-weight:bold;' : ''}}" mailbox-label="{{ contact.label }}" mailbox-navigation="{{ contact.nav }}">{{ contact.label }}{{ contact.unread > 0 ? ' (' + contact.unread + ') ' : '' }}</a> <a class="ocsms-plname" style="{{ contact.unread > 0 ? 'font-weight:bold;' : ''}}" mailbox-label="{{ contact.label }}" mailbox-navigation="{{ contact.nav }}">{{ contact.label }}{{ contact.unread > 0 ? ' (' + contact.unread + ') ' : '' }}</a>
@ -25,8 +25,8 @@ use \OCA\OcSms\Lib\CountryCodes;
</div> </div>
<div id="app-settings-content"> <div id="app-settings-content">
<div><label for="setting_msg_per_page">Max messages on tab loading</label> <div><label for="setting_msg_per_page">Max messages on tab loading</label>
<input type="number" min="10" max="10000" name="setting_msg_per_page" ng-model="setting_msgLimit" ng-change="setMessageLimit()" to-int /> <input type="number" min="10" max="10000" name="setting_msg_per_page" ng-model="vsettings.messageLimit" ng-change="setMessageLimit()" to-int />
<span class="label-invalid-input" ng-if="setting_msgLimit == null || setting_msgLimit == undefined">Invalid message limit</span> <span class="label-invalid-input" ng-if="vsettings.messageLimit == null || vsettings.messageLimit == undefined">Invalid message limit</span>
</div> </div>
<div><label for="intl_phone">Country code</label> <div><label for="intl_phone">Country code</label>
@ -40,17 +40,17 @@ use \OCA\OcSms\Lib\CountryCodes;
<div> <div>
<label for="setting_contact_order">Contact ordering</label> <label for="setting_contact_order">Contact ordering</label>
<select name="setting_contact_order" ng-model="setting_contactOrder" ng-change="setContactOrderSetting()"> <select name="setting_contact_order" ng-model="vsettings.contactOrderBy" ng-change="setContactOrderSetting()">
<option value="lastmsg">Last message</option> <option value="lastmsg">Last message</option>
<option value="label">Label</option> <option value="label">Label</option>
</select> </select>
<label for "setting_contact_order_reverse">Reverse ?</label> <label for "setting_contact_order_reverse">Reverse ?</label>
<input type="checkbox" ng-model="setting_contactOrderReverse" ng-change="setContactOrderSetting()" /> <input type="checkbox" ng-model="vsettings.reverseContactOrder" ng-change="setContactOrderSetting()" />
</div> </div>
<div> <div>
<label for"setting_notif">Notification settings</label> <label for"setting_notif">Notification settings</label>
<select name="setting_notif" ng-model="setting_enableNotifications" ng-change="setNotificationSetting()"> <select name="setting_notif" ng-model="vsetting.enableNotifications" ng-change="setNotificationSetting()">
<option value="1">Enable</option> <option value="1">Enable</option>
<option value="0">Disable</option> <option value="0">Disable</option>
</select> </select>