diff --git a/appinfo/routes.php b/appinfo/routes.php index 9824478..d691dea 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -25,6 +25,7 @@ $application->registerRoutes($this, array('routes' => array( array('name' => 'settings#get_settings', 'url'=> '/get/settings', 'verb' => 'GET'), array('name' => 'settings#set_messagelimit', 'url'=> '/set/msglimit', 'verb' => 'POST'), array('name' => 'settings#set_notification_state', 'url'=> '/set/notification_state', 'verb' => 'POST'), + array('name' => 'settings#set_contact_order', 'url' => '/set/contact_order', 'verb' => 'POST'), // Android API v1 doesn't have a version in the URL, be careful array('name' => 'api#get_api_version', 'url' => '/get/apiversion', 'verb' => 'GET'), // Android APIv1 diff --git a/controller/settingscontroller.php b/controller/settingscontroller.php index e267db1..7d75b59 100644 --- a/controller/settingscontroller.php +++ b/controller/settingscontroller.php @@ -42,7 +42,9 @@ class SettingsController extends Controller { return new JSONResponse(array("status" => true, "country" => $country, "message_limit" => $this->configMapper->getMessageLimit(), - "notification_state" => $this->configMapper->getNotificationState() + "notification_state" => $this->configMapper->getNotificationState(), + "contact_order" => $this->configMapper->getContactOrder(), + "contact_order_reverse" => $this->configMapper->getContactOrderReverse(), )); } @@ -53,7 +55,7 @@ class SettingsController extends Controller { */ function setCountry($country) { if (!array_key_exists($country, CountryCodes::$codes)) { - return new JSONResponse(array("status" => false, "msg" => "Invalid country")); + return new JSONResponse(array("status" => false, "msg" => "Invalid country"), Http::STATUS_BAD_REQUEST); } $this->configMapper->set("country", $country); return new JSONResponse(array("status" => true, "msg" => "OK")); @@ -76,9 +78,24 @@ class SettingsController extends Controller { */ function setNotificationState($notification) { if (!is_numeric($notification) || $notification < 0 || $notification > 2) { - return new JSONResponse(array("status" => false, "msg" => "Invalid notification state")); + return new JSONResponse(array("status" => false, "msg" => "Invalid notification state"), Http::STATUS_BAD_REQUEST); } $this->configMapper->set("notification_state", $notification); return new JSONResponse(array("status" => true, "msg" => "OK")); } + + /** + * @NoAdminRequired + * @param $attribute + * @param $reverse + * @return JSONResponse + */ + function setContactOrder($attribute, $reverse) { + if (!in_array($reverse, ['true','false']) || !in_array($attribute, ['lastmsg','label'])) { + return new JSONResponse(array("status" => false, "msg" => "Invalid contact ordering"), Http::STATUS_BAD_REQUEST); + } + $this->configMapper->set("contact_order", $attribute); + $this->configMapper->set("contact_order_reverse", $reverse); + return new JSONResponse(array("status" => true, "msg" => "OK")); + } } diff --git a/db/configmapper.php b/db/configmapper.php index 86c4a91..9af8f95 100644 --- a/db/configmapper.php +++ b/db/configmapper.php @@ -95,6 +95,22 @@ class ConfigMapper extends Mapper { } return $st; } + + public function getContactOrder() { + $order = $this->getKey("contact_order"); + if ($order === false) { + $order = "lastmsg"; + } + return $order; + } + + public function getContactOrderReverse() { + $rev = $this->getKey("contact_order_reverse"); + if ($rev === false) { + $rev = "true"; + } + return $rev; + } }; ?> diff --git a/js/public/app.js b/js/public/app.js index 3efa559..3643696 100644 --- a/js/public/app.js +++ b/js/public/app.js @@ -30,6 +30,27 @@ function arrayUnique(arr) { }); } +function toBool(str) { + if (str === "true") { + return true; + } + else if (str === "false") { + return false; + } + return null; +} + +app.directive('toInt', function() { + return { + require: 'ngModel', + link: function(scope, element, attrs, modelCtrl) { + modelCtrl.$parsers.push(function (inputValue) { + return parseInt(inputValue, 10); + }); + } + }; +}); + // Imported from ownCloud contact app app.filter('peerColor', function() { return function(input) { @@ -70,6 +91,8 @@ app.controller('OcSmsController', ['$scope', '$interval', '$timeout', '$compile' $scope.setting_msgLimit = 100; $scope.setting_enableNotifications = 1; + $scope.setting_contactOrder = 'lastmsg'; + $scope.setting_contactOrderReverse = true; $scope.contacts = []; $scope.messages = []; @@ -97,6 +120,15 @@ app.controller('OcSmsController', ['$scope', '$interval', '$timeout', '$compile' $.post(OC.generateUrl('/apps/ocsms/set/notification_state'),{'notification': $scope.setting_enableNotifications}); }; + $scope.setContactOrderSetting = function () { + $.post(OC.generateUrl('/apps/ocsms/set/contact_order'), + { + 'attribute': $scope.setting_contactOrder, + 'reverse': $scope.setting_contactOrderReverse + } + ); + }; + // Conversations $scope.loadConversation = function (contact) { OC.Util.History.pushState('phonenumber=' + contact.nav); @@ -314,9 +346,13 @@ app.controller('OcSmsController', ['$scope', '$interval', '$timeout', '$compile' $('input[name=setting_msg_per_page]').val(jsondata["message_limit"]); $('select[name=setting_notif]').val(jsondata["notification_state"]); + $('select[name=setting_contact_order]').val(jsondata["contact_order"]); + $('input[name=setting_contact_order_reverse').val(toBool(jsondata["contact_order_reverse"])); $scope.setting_msgLimit = jsondata["message_limit"]; $scope.setting_enableNotifications = jsondata["notification_state"]; + $scope.setting_contactOrder = jsondata["contact_order"]; + $scope.setting_contactOrderReverse = toBool(jsondata["contact_order_reverse"]); } }); }; diff --git a/templates/main.php b/templates/main.php index b460cd9..2311bed 100644 --- a/templates/main.php +++ b/templates/main.php @@ -9,7 +9,7 @@ use \OCA\OcSms\Lib\CountryCodes;
- - Invalid message limit + + Invalid message limit
- - + +
- - + + + + +
+ +
+ +