Basic mailbox loading, no server data loading yet.
authorJan Schneider <jan@horde.org>
Tue, 16 Nov 2010 18:01:30 +0000 (19:01 +0100)
committerJan Schneider <jan@horde.org>
Tue, 16 Nov 2010 23:35:49 +0000 (00:35 +0100)
imp/js/mobile.js [new file with mode: 0644]
imp/mobile.php
imp/templates/mobile/head.html.php
imp/templates/mobile/javascript_defs.php [new file with mode: 0644]
imp/templates/mobile/mailbox.html.php

diff --git a/imp/js/mobile.js b/imp/js/mobile.js
new file mode 100644 (file)
index 0000000..12a31b5
--- /dev/null
@@ -0,0 +1,86 @@
+/**
+ * jQuery Mobile UI application logic.
+ *
+ * Copyright 2005-2010 The Horde Project (http://www.horde.org/)
+ *
+ * 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');
+    },
+
+    /**
+     * Switches to the mailbox view and loads a mailbox.
+     *
+     * @param string mailbox  A mailbox name.
+     * @param string label    A mailbox label.
+     */
+    toMailbox: function(mailbox, label)
+    {
+        $('#imp-mailbox-header').text(label);
+        $.mobile.changePage('#mailbox', 'slide', false, true);
+    },
+
+    /**
+     * Catch-all event handler for the click event.
+     *
+     * @param object e  An event object.
+     */
+    clickHandler: function(e)
+    {
+        var elt = $(e.target),
+            orig = $(e.target),
+            id;
+
+        while (elt) {
+            id = elt.attr('id');
+
+            switch (id) {
+            }
+
+            if (elt.hasClass('imp-folder')) {
+                var link = elt.find('a[mailbox]');
+                ImpMobile.toMailbox(link.attr('mailbox'), link.text());
+                break;
+            }
+
+            elt = elt.parent();
+        }
+    },
+
+    /**
+     * Event handlder for the document-ready event, responsible for the inital
+     * setup.
+     */
+    onDocumentReady: function()
+    {
+        // Global ajax options.
+        $.ajaxSetup({
+            dataFilter: function(data, type)
+            {
+                // Remove json security token
+                filter = /^\/\*-secure-([\s\S]*)\*\/s*$/;
+                return data.replace(filter, "$1");
+            }
+        });
+
+        $(document).click(ImpMobile.clickHandler);
+    }
+
+};
+
+// JQuery Mobile setup
+$(ImpMobile.onDocumentReady);
index 2cad3be..d07de70 100644 (file)
@@ -39,6 +39,7 @@ $view->logout = Horde::getServiceLink('logout')->setRaw(false);
 $title = _("Mobile Mail");
 
 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');
index 9ca38d2..1d0cc9c 100644 (file)
@@ -1,3 +1,4 @@
   <link type="text/css" rel="stylesheet" href="<?php echo $GLOBALS['registry']->get('themesuri', 'imp') ?>/mobile.css" />
+  <script type="text/javascript" src="<?php echo $GLOBALS['registry']->get('jsuri') ?>/mobile.js"></script>
 </head>
 <body>
diff --git a/imp/templates/mobile/javascript_defs.php b/imp/templates/mobile/javascript_defs.php
new file mode 100644 (file)
index 0000000..f98b177
--- /dev/null
@@ -0,0 +1,55 @@
+<?php
+/**
+ * IMP Mobile base JS file.
+ *
+ * Copyright 2005-2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ */
+
+$code = $flags = array();
+
+/* Generate flag array. */
+foreach ($GLOBALS['injector']->getInstance('IMP_Imap_Flags')->getList(array('fgcolor' => true)) as $val) {
+    $flags[$val['flag']] = array_filter(array(
+        'b' => isset($val['b']) ? $val['b'] : null,
+        'c' => $val['c'],
+        'f' => $val['f'],
+        'l' => $val['l'],
+        'n' => isset($val['n']) ? $val['n'] : null,
+        // Indicate if this is a user *P*ref flag
+        'p' => intval($val['t'] == 'imapp'),
+        // Indicate if this is a flag that can be *S*earched for
+        's' => intval(in_array($val['t'], array('imapp', 'imapu')))
+    ));
+}
+
+/* Variables used in core javascript files. */
+$code['conf'] = array_filter(array(
+    // URL variables
+    'URI_AJAX' => Horde::getServiceLink('ajax', 'imp')->url,
+    'URI_COMPOSE' => strval(Horde::url('compose-dimp.php')->setRaw(true)->add('ajaxui', 1)),
+    'URI_DIMP' => strval(Horde::url('index-dimp.php')),
+    'URI_MESSAGE' => strval(Horde::url('message-dimp.php')->setRaw(true)->add('ajaxui', 1)),
+    'URI_PREFS_IMP' => strval(Horde::getServiceLink('prefs', 'imp')->setRaw(true)->add('ajaxui', 1)),
+    'URI_SEARCH' => strval(Horde::url('search.php')),
+    'URI_VIEW' => strval(Horde::url('view.php')),
+
+    'IDX_SEP' => IMP_Dimp::IDX_SEP,
+    'SESSION_ID' => defined('SID') ? SID : '',
+
+    // Other variables
+    'flags' => $flags,
+    /* Needed to maintain flag ordering. */
+    'flags_o' => array_keys($flags),
+    'refresh_time' => intval($GLOBALS['prefs']->getValue('refresh_time')),
+));
+
+/* Gettext strings used in core javascript files. */
+$code['text'] = array(
+);
+
+Horde::addInlineJsVars(array(
+    'var IMP' => $code
+), array('top' => true));
index 2598c51..797744d 100644 (file)
@@ -3,7 +3,7 @@
     <?php if (!$this->allowFolders): ?>
     <a rel="external" href="<?php echo $this->portal ?>"><?php echo _("Portal")?></a>
     <?php endif ?>
-    <h1><?php echo _("Inbox") ?></h1>
+    <h1 id="imp-mailbox-header"></h1>
     <?php if ($this->logout): ?>
     <a href="<?php echo $this->logout ?>" rel="external" data-theme="e" data-icon="delete" class="ui-btn-right"><?php echo _("Log out") ?></a>
     <?php endif ?>