From 77a9e9cccf306d87d468b4edc3079b80e1a7021e Mon Sep 17 00:00:00 2001 From: Loic Blot Date: Mon, 16 Feb 2015 13:18:48 +0000 Subject: [PATCH] Load the country settings at app load --- appinfo/routes.php | 1 + controller/smscontroller.php | 11 +++++++++++ js/public/app.js | 10 ++++++++++ templates/main.php | 2 +- 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/appinfo/routes.php b/appinfo/routes.php index 818cad5..4e892e9 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -25,4 +25,5 @@ $application->registerRoutes($this, array('routes' => array( array('name' => 'sms#check_new_messages', 'url' => '/get/new_messages', 'verb' => 'GET'), array('name' => 'sms#get_api_version', 'url' => '/get/apiversion', 'verb' => 'GET'), array('name' => 'sms#set_country', 'url'=> '/set/country', 'verb' => 'POST'), + array('name' => 'sms#get_country', 'url'=> '/get/country', 'verb' => 'GET'), ))); diff --git a/controller/smscontroller.php b/controller/smscontroller.php index 29fe031..654110d 100644 --- a/controller/smscontroller.php +++ b/controller/smscontroller.php @@ -314,4 +314,15 @@ class SmsController extends Controller { $this->configMapper->set("country", $country); return new JSONResponse(array("status" => true, "msg" => "OK")); } + + /** + * @NoAdminRequired + */ + function getCountry() { + $country = $this->configMapper->getKey("country"); + if ($country === false) { + return new JSONResponse(array("status" => false)); + } + return new JSONResponse(array("status" => true, "country" => $country)); + } } diff --git a/js/public/app.js b/js/public/app.js index 7e91188..5813c8b 100644 --- a/js/public/app.js +++ b/js/public/app.js @@ -368,6 +368,15 @@ function desktopNotify(msg) { } } +function fetchInitialSettings() { + $.getJSON(OC.generateUrl('/apps/ocsms/get/country'), function(jsondata, status) { + if (jsondata['status'] == true) { + $('#sel_intl_phone').val(jsondata["country"]); + } + else { + } + }); +} (function ($, OC) { $(document).ready(function () { // Register real title @@ -393,6 +402,7 @@ function desktopNotify(msg) { } }); + fetchInitialSettings(); initDesktopNotifies(); setInterval(refreshConversation, 10000); setInterval(checkNewMessages, 10000); diff --git a/templates/main.php b/templates/main.php index aff6c9d..ae7ef8a 100644 --- a/templates/main.php +++ b/templates/main.php @@ -20,7 +20,7 @@ use \OCA\OcSms\Lib\CountryCodes;
- $cval) { ?>