From f44695f022d78be026b9bdfb060f9f8fe78c33b4 Mon Sep 17 00:00:00 2001 From: Jan Schneider Date: Mon, 29 Nov 2010 15:32:19 +0100 Subject: [PATCH] Add a base object for common jQuery Mobile stuff. --- horde/js/mobile.js | 93 +++++++++++++++++++++++++++++++++++ horde/package.xml | 8 +-- imp/js/mobile.js | 41 +++------------- imp/mobile.php | 7 ++- imp/templates/mobile/notice.html.php | 7 +++ kronolith/js/mobile.js | 94 ++++++------------------------------ kronolith/mobile.php | 7 ++- 7 files changed, 139 insertions(+), 118 deletions(-) create mode 100644 horde/js/mobile.js create mode 100644 imp/templates/mobile/notice.html.php diff --git a/horde/js/mobile.js b/horde/js/mobile.js new file mode 100644 index 000000000..f78c80957 --- /dev/null +++ b/horde/js/mobile.js @@ -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 + * @author Jan Schneider + * @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); diff --git a/horde/package.xml b/horde/package.xml index 26300bfd0..5b9b28158 100644 --- a/horde/package.xml +++ b/horde/package.xml @@ -19,8 +19,8 @@ applications. jan@horde.org yes - 2010-11-25 - + 2010-11-29 + 4.0.0 4.0.0 @@ -331,6 +331,7 @@ applications. + @@ -2242,6 +2243,7 @@ applications. + @@ -3806,7 +3808,7 @@ applications. alpha alpha - 2010-11-25 + 2010-11-29 LGPL * Initial package.xml. diff --git a/imp/js/mobile.js b/imp/js/mobile.js index 33d257e4c..4a101ea4b 100644 --- a/imp/js/mobile.js +++ b/imp/js/mobile.js @@ -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( $('
  • ').append( $('

    ').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) { diff --git a/imp/mobile.php b/imp/mobile.php index 67f028b25..a15cf20b7 100644 --- a/imp/mobile.php +++ b/imp/mobile.php @@ -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 index 000000000..b00cab50e --- /dev/null +++ b/imp/templates/mobile/notice.html.php @@ -0,0 +1,7 @@ +
    +
    +

    +
    +
    +
    +
    \ No newline at end of file diff --git a/kronolith/js/mobile.js b/kronolith/js/mobile.js index 01ada93cf..72ea12542 100644 --- a/kronolith/js/mobile.js +++ b/kronolith/js/mobile.js @@ -41,61 +41,6 @@ */ 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. * @@ -140,15 +85,15 @@ } 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 ); }); }, @@ -298,9 +243,9 @@ */ 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); }, /** @@ -737,6 +682,9 @@ 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) { @@ -746,16 +694,6 @@ }); }); - // 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); @@ -796,4 +734,4 @@ $('body').bind('swiperight', KronolithMobile.handleSwipe); } }; -$(KronolithMobile.onDocumentReady); \ No newline at end of file +$(KronolithMobile.onDocumentReady); diff --git a/kronolith/mobile.php b/kronolith/mobile.php index b1391f648..87fef3095 100644 --- a/kronolith/mobile.php +++ b/kronolith/mobile.php @@ -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'); -- 2.11.0