Add a base object for common jQuery Mobile stuff.
authorJan Schneider <jan@horde.org>
Mon, 29 Nov 2010 14:32:19 +0000 (15:32 +0100)
committerJan Schneider <jan@horde.org>
Mon, 29 Nov 2010 14:32:43 +0000 (15:32 +0100)
horde/js/mobile.js [new file with mode: 0644]
horde/package.xml
imp/js/mobile.js
imp/mobile.php
imp/templates/mobile/notice.html.php [new file with mode: 0644]
kronolith/js/mobile.js
kronolith/mobile.php

diff --git a/horde/js/mobile.js b/horde/js/mobile.js
new file mode 100644 (file)
index 0000000..f78c809
--- /dev/null
@@ -0,0 +1,93 @@
+/**
+ * Base logic for all jQuery Mobile applications.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @author   Michael J. Rubinsky <mrubinsk@horde.org>
+ * @author   Jan Schneider <jan@horde.org>
+ * @category Horde
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @package  Horde
+ */
+ var HordeMobile = {
+
+    serverError: 0,
+
+    /**
+     * Common URLs.
+     *
+     * Required properties to be set from calling applications:
+     * - ajax: AJAX endpoint.
+     */
+    urls: {},
+
+    /**
+     * Perform an Ajax action
+     *
+     * @param string action      The AJAX request
+     * @param object params      The parameter hash
+     * @param function callback  The callback function
+     */
+    doAction: function(action, params, callback)
+    {
+        $.mobile.pageLoading();
+        var options = {
+            'url': HordeMobile.urls.ajax + action,
+            'data': params,
+            'error': HordeMobile.errorCallback,
+            'success': function(d, t, x) { HordeMobile.doActionComplete(d, callback); },
+            'type': 'post'
+        };
+        $.ajax(options);
+    },
+
+    doActionComplete: function(d, callback)
+    {
+        var r = d.response;
+        if (r && $.isFunction(callback)) {
+            callback(r);
+        }
+
+        HordeMobile.server_error = 0;
+        HordeMobile.showNotifications(d.msgs || []);
+        HordeMobile.inAjaxCallback = false;
+        $.mobile.pageLoading(true);
+    },
+
+    showNotifications: function(m)
+    {
+        $.each(m, function(key, msg) {
+            if (msg.type == 'horde.ajaxtimeout') {
+                HordeMobile.logout(msg.message);
+            }
+        });
+    },
+
+    logout: function(url)
+    {
+        HordeMobile.is_logout = true;
+        window.location = (url || HordeMobile.urls.ajax + 'logOut');
+    },
+
+    errorCallback: function(x, t, e)
+    {
+
+    },
+
+    onDocumentReady: function()
+    {
+        // Global ajax options.
+        $.ajaxSetup({
+            dataFilter: function(data, type)
+            {
+                // Remove json security token
+                filter = /^\/\*-secure-([\s\S]*)\*\/s*$/;
+                return data.replace(filter, "$1");
+            }
+        });
+    }
+};
+$(HordeMobile.onDocumentReady);
index 26300bf..5b9b281 100644 (file)
@@ -19,8 +19,8 @@ applications.</description>
   <email>jan@horde.org</email>
   <active>yes</active>
  </lead>
- <date>2010-11-25</date>
- <time>15:30:20</time>
+ <date>2010-11-29</date>
+ <time>15:17:50</time>
  <version>
   <release>4.0.0</release>
   <api>4.0.0</api>
@@ -331,6 +331,7 @@ applications.</description>
     <file name="login.js" role="horde" />
     <file name="logintasks.js" role="horde" />
     <file name="md5.js" role="horde" />
+    <file name="mobile.js" role="horde" />
     <file name="popup.js" role="horde" />
     <file name="prototype.js" role="horde" />
     <file name="quickfinder.js" role="horde" />
@@ -2242,6 +2243,7 @@ applications.</description>
    <install as="js/login.js" name="js/login.js" />
    <install as="js/logintasks.js" name="js/logintasks.js" />
    <install as="js/md5.js" name="js/md5.js" />
+   <install as="js/mobile.js" name="js/mobile.js" />
    <install as="js/popup.js" name="js/popup.js" />
    <install as="js/prototype.js" name="js/prototype.js" />
    <install as="js/quickfinder.js" name="js/quickfinder.js" />
@@ -3806,7 +3808,7 @@ applications.</description>
     <release>alpha</release>
     <api>alpha</api>
    </stability>
-   <date>2010-11-25</date>
+   <date>2010-11-29</date>
    <license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
    <notes>
 * Initial package.xml.
index 33d257e..4a101ea 100644 (file)
@@ -6,22 +6,8 @@
  * See the enclosed file COPYING for license information (GPL). If you
  * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
  */
-
-/* ImpMobile object. */
 var ImpMobile = {
 
-    /**
-     * Perform an Ajax action
-     *
-     * @param string action      The AJAX request
-     * @param object params      The parameter hash
-     * @param function callback  The callback function
-     */
-    doAction: function(action, params, callback)
-    {
-        $.post(IMP.conf.URI_AJAX + action, params, callback, 'json');
-    },
-
     // Convert object to an IMP UID Range string. See IMP::toRangeString()
     // ob = (object) mailbox name as keys, values are array of uids.
     toRangeString: function(ob)
@@ -64,8 +50,7 @@ var ImpMobile = {
         $('#imp-mailbox-header').text(label);
         $('#imp-mailbox-list').empty();
         $.mobile.changePage('#mailbox', 'slide', false, true);
-        $.mobile.pageLoading();
-        ImpMobile.doAction(
+        HordeMobile.doAction(
             'viewPort',
             {
                 view: mailbox,
@@ -85,9 +70,8 @@ var ImpMobile = {
     mailboxLoaded: function(r)
     {
         var list = $('#imp-mailbox-list');
-        $.mobile.pageLoading(true);
-        if (r.response && r.response.ViewPort) {
-            $.each(r.response.ViewPort.data, function(key, data) {
+        if (r && r.ViewPort) {
+            $.each(r.ViewPort.data, function(key, data) {
                 list.append(
                     $('<li class="imp-message" data-imp-mailbox="' + data.view + '" data-imp-uid="' + data.imapuid + '">').append(
                         $('<h3>').append(
@@ -120,8 +104,7 @@ var ImpMobile = {
         $('#imp-message-more').parent().show();
         $('#imp-message-less').parent().hide();
         $.mobile.changePage('#message', 'slide', false, true);
-        $.mobile.pageLoading();
-        ImpMobile.doAction(
+        HordeMobile.doAction(
             'showMessage',
             {
                 uid: ImpMobile.toRangeString(o),
@@ -137,9 +120,8 @@ var ImpMobile = {
      */
     messageLoaded: function(r)
     {
-        $.mobile.pageLoading(true);
-        if (r.response && r.response.message && !r.response.message.error) {
-            var data = r.response.message,
+        if (r && r.message && !r.message.error) {
+            var data = r.message,
                 headers = $('#imp-message-headers tbody');
             $('#imp-message-title').html(data.title);
             $('#imp-message-subject').html(data.subject);
@@ -206,15 +188,8 @@ var ImpMobile = {
      */
     onDocumentReady: function()
     {
-        // Global ajax options.
-        $.ajaxSetup({
-            dataFilter: function(data, type)
-            {
-                // Remove json security token
-                filter = /^\/\*-secure-([\s\S]*)\*\/s*$/;
-                return data.replace(filter, "$1");
-            }
-        });
+        // Set up HordeMobile.
+        HordeMobile.urls.ajax = IMP.conf.URI_AJAX;
 
         IMP.iframeInject = function(id, data)
         {
index 67f028b..a15cf20 100644 (file)
@@ -38,15 +38,18 @@ $view->portal = Horde::getServiceLink('portal', 'horde')->setRaw(false);
 $view->logout = Horde::getServiceLink('logout')->setRaw(false);
 $title = _("Mobile Mail");
 
+require $registry->get('templates', 'horde') . '/common-header-mobile.inc';
+
 Horde::addScriptFile('horde-jquery.js', 'horde');
+Horde::addScriptFile('mobile.js', 'horde');
 Horde::addScriptFile('mobile.js', 'imp');
-
-require $registry->get('templates', 'horde') . '/common-header-mobile.inc';
 include IMP_TEMPLATES . '/mobile/javascript_defs.php';
+
 echo $view->render('head.html.php');
 if (!empty($conf['user']['allow_folders'])) {
     echo $view->render('folders.html.php');
 }
 echo $view->render('mailbox.html.php');
 echo $view->render('message.html.php');
+echo $view->render('notice.html.php');
 require $registry->get('templates', 'horde') . '/common-footer-mobile.inc';
diff --git a/imp/templates/mobile/notice.html.php b/imp/templates/mobile/notice.html.php
new file mode 100644 (file)
index 0000000..b00cab5
--- /dev/null
@@ -0,0 +1,7 @@
+<div id="notification" data-role="dialog">
+  <div data-role="header">
+    <h1><?php echo _("Notice")?></h1>
+  </div>
+  <div data-role="content" class="ui-body">
+  </div>
+</div>
\ No newline at end of file
index 01ada93..72ea125 100644 (file)
      */
     date: null,
 
-    serverError: 0,
-
-    /**
-     * Perform an Ajax action
-     *
-     * @param string action      The AJAX request
-     * @param object params      The parameter hash
-     * @param function callback  The callback function
-     */
-    doAction: function(action, params, callback)
-    {
-        $.mobile.pageLoading();
-        var options = {
-            'url': Kronolith.conf.URI_AJAX + action,
-            'data': params,
-            'error': KronolithMobile.errorCallback,
-            'success': function(d, t, x) { KronolithMobile.doActionComplete(d, callback); },
-            'type': 'post'
-        };
-        $.ajax(options);
-    },
-
-    doActionComplete: function(d, callback)
-    {
-        var r = d.response;
-        if (r && $.isFunction(callback)) {
-          callback(r);
-        }
-
-        KronolithMobile.server_error = 0;
-        KronolithMobile.showNotifications(d.msgs || []);
-        KronolithMobile.inAjaxCallback = false;
-        $.mobile.pageLoading(true);
-    },
-
-    showNotifications: function(m)
-    {
-        $.each(m, function(key, msg) {
-            if (msg.type == 'horde.ajaxtimeout') {
-                KronolithMobile.logout(msg.message);
-            }
-        });
-    },
-
-    logout: function(url)
-    {
-        KronolithMobile.is_logout = true;
-        window.location = (url || (Kronolith.conf.URI_AJAX + 'logOut'));
-    },
-
-    errorCallback: function(x, t, e)
-    {
-
-    },
-
     /**
      * Load all events between start and end time.
      *
             }
 
             var start = startDay.dateString(), end = endDay.dateString();
-            KronolithMobile.doAction('listEvents',
-                                     {
-                                       'start': start,
-                                       'end': end,
-                                       'cal': cal.join('|'),
-                                       'view': view,
-                                       'sig': start + end + (Math.random() + '').slice(2)
-                                     },
-                                     KronolithMobile.loadEventsCallback
+            HordeMobile.doAction('listEvents',
+                                 {
+                                   'start': start,
+                                   'end': end,
+                                   'cal': cal.join('|'),
+                                   'view': view,
+                                   'sig': start + end + (Math.random() + '').slice(2)
+                                 },
+                                 KronolithMobile.loadEventsCallback
             );
         });
     },
      */
     loadEvent: function(cal, id, d)
     {
-        KronolithMobile.doAction('getEvent',
-                                 {'cal': cal, 'id': id, 'date': d.toString('yyyyMMdd')},
-                                 KronolithMobile.loadEventCallback);
+        HordeMobile.doAction('getEvent',
+                             {'cal': cal, 'id': id, 'date': d.toString('yyyyMMdd')},
+                             KronolithMobile.loadEventCallback);
     },
 
     /**
 
     onDocumentReady: function()
     {
+        // Set up HordeMobile.
+        HordeMobile.urls.ajax = Kronolith.conf.URI_AJAX;
+
         // Build list of calendars we want.
         $.each(Kronolith.conf.calendars, function(key, value) {
             $.each(value, function(cal, info) {
             });
         });
 
-        // Global ajax options.
-        $.ajaxSetup({
-            dataFilter: function(data, type)
-            {
-                // Remove json security token
-                filter = /^\/\*-secure-([\s\S]*)\*\/s*$/;
-                return data.replace(filter, "$1");
-            }
-        });
-
         // Day View
         $('.kronolithDayHeader .kronolithPrevDay').bind('click', KronolithMobile.showPrevDay);
         $('.kronolithDayHeader .kronolithNextDay').bind('click', KronolithMobile.showNextDay);
         $('body').bind('swiperight', KronolithMobile.handleSwipe);
     }
 };
-$(KronolithMobile.onDocumentReady);
\ No newline at end of file
+$(KronolithMobile.onDocumentReady);
index b1391f6..87fef30 100644 (file)
@@ -27,13 +27,16 @@ $datejs = str_replace('_', '-', $GLOBALS['language']) . '.js';
 if (!file_exists($GLOBALS['registry']->get('jsfs', 'horde') . '/date/' . $datejs)) {
     $datejs = 'en-US.js';
 }
+
+require $registry->get('templates', 'horde') . '/common-header-mobile.inc';
+
 Horde::addScriptFile('horde-jquery.js', 'horde');
+Horde::addScriptFile('mobile.js', 'horde');
 Horde::addScriptFile('date/' . $datejs, 'horde');
 Horde::addScriptFile('date/date.js', 'horde');
 Horde::addScriptFile('mobile.js', 'kronolith');
-
-require $registry->get('templates', 'horde') . '/common-header-mobile.inc';
 require KRONOLITH_TEMPLATES . '/mobile/javascript_defs.php';
+
 echo $view->render('head');
 echo $view->render('day');
 echo $view->render('event');