Update fetchmailprefs javascript
authorMichael M Slusarz <slusarz@curecanti.org>
Mon, 9 Feb 2009 22:51:16 +0000 (15:51 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Tue, 10 Feb 2009 02:07:31 +0000 (19:07 -0700)
imp/fetchmailprefs.php
imp/js/fetchmailprefs.js
imp/js/src/fetchmailprefs.js
imp/templates/fetchmail/fetchmailprefs.html

index 82e33d7..f3535f5 100644 (file)
@@ -187,6 +187,11 @@ if (empty($actionID)) {
 Prefs_UI::generateHeader(null, $chunk);
 Horde::addScriptFile('prototype.js', 'horde', true);
 Horde::addScriptFile('fetchmailprefs.js', 'imp', true);
+IMP::addInlineScript(array(
+    'ImpFetchmailprefs.fetchurl = \'' . $fetch_url . '\'',
+    'ImpFetchmailprefs.prefsurl = \'' . $prefs_url . '\''
+));
+
 echo $t->fetch(IMP_TEMPLATES . '/fetchmail/fetchmailprefs.html');
 if (!$chunk) {
     require $registry->get('templates', 'horde') . '/common-footer.inc';
index e043545..c8cc4b3 100644 (file)
@@ -1 +1 @@
-var fmprefs_loading=false;function accountSubmit(a){if(!fmprefs_loading&&((a!=null)||!$F("account").empty())){fmprefs_loading=true;$("fm_switch").submit()}}function driverSubmit(){if(!fmprefs_loading&&$F("fm_driver")){fmprefs_loading=true;$("fm_driver_form").submit()}};
\ No newline at end of file
+var ImpFetchmailprefs={fmprefs_loading:false,_accountSubmit:function(a){if(!this.fmprefs_loading&&((a!=null)||!$F("account").empty())){this.fmprefs_loading=true;$("fm_switch").submit()}},_driverSubmit:function(){if(!this.fmprefs_loading&&$F("fm_driver")){this.fmprefs_loading=true;$("fm_driver_form").submit()}},onDomLoad:function(){document.observe("change",this._changeHandler.bindAsEventListener(this));document.observe("click",this._clickHandler.bindAsEventListener(this))},_changeHandler:function(a){switch(a.element().readAttribute("id")){case"account":this._accountSubmit();break;case"fm_driver":this._driverSubmit();break}},_clickHandler:function(a){switch(a.element().readAttribute("id")){case"btn_delete":$("actionID").setValue("fetchmail_prefs_delete");break;case"btn_create":$("actionID").setValue("fetchmail_create");this._accountSubmit(true);break;case"btn_return":document.location.href=this.prefsurl;break;case"btn_save":$("actionID").setValue("fetchmail_prefs_save");break;case"btn_select":document.location.href=this.fetchurl;break}}};document.observe("dom:loaded",ImpFetchmailprefs.onDomLoad.bind(ImpFetchmailprefs));
\ No newline at end of file
index c83344b..7bb6615 100644 (file)
@@ -5,21 +5,74 @@
  * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
  */
 
-var fmprefs_loading = false;
-
-function accountSubmit(isnew)
-{
-    if (!fmprefs_loading &&
-        ((isnew != null) || !$F('account').empty())) {
-        fmprefs_loading = true;
-        $('fm_switch').submit();
-    }
-}
+var ImpFetchmailprefs = {
+
+    // The following variables are defined in fetchmailprefs.php:
+    //   fetchurl, prefsurl
+    fmprefs_loading: false,
+
+    _accountSubmit: function(isnew)
+    {
+        if (!this.fmprefs_loading &&
+            ((isnew != null) || !$F('account').empty())) {
+            this.fmprefs_loading = true;
+            $('fm_switch').submit();
+        }
+    },
+
+    _driverSubmit: function()
+    {
+        if (!this.fmprefs_loading && $F('fm_driver')) {
+            this.fmprefs_loading = true;
+            $('fm_driver_form').submit();
+        }
+    },
+
+    onDomLoad: function()
+    {
+        document.observe('change', this._changeHandler.bindAsEventListener(this));
+        document.observe('click', this._clickHandler.bindAsEventListener(this));
+    },
+
+    _changeHandler: function(e)
+    {
+        switch (e.element().readAttribute('id')) {
+        case 'account':
+            this._accountSubmit();
+            break;
+
+        case 'fm_driver':
+            this._driverSubmit();
+            break;
+        }
+    },
 
-function driverSubmit()
-{
-    if (!fmprefs_loading && $F('fm_driver')) {
-        fmprefs_loading = true;
-        $('fm_driver_form').submit();
+    _clickHandler: function(e)
+    {
+        switch (e.element().readAttribute('id')) {
+        case 'btn_delete':
+            $('actionID').setValue('fetchmail_prefs_delete');
+            break;
+
+        case 'btn_create':
+            $('actionID').setValue('fetchmail_create');
+            this._accountSubmit(true);
+            break;
+
+        case 'btn_return':
+            document.location.href = this.prefsurl;
+            break;
+
+        case 'btn_save':
+            $('actionID').setValue('fetchmail_prefs_save');
+            break;
+
+        case 'btn_select':
+            document.location.href = this.fetchurl;
+            break;
+        }
     }
-}
+
+};
+
+document.observe('dom:loaded', ImpFetchmailprefs.onDomLoad.bind(ImpFetchmailprefs));
index 40631a5..27ad6c8 100644 (file)
@@ -17,7 +17,7 @@
 <if:accounts>
       <label for="account"><gettext>Your accounts:</gettext></label>&nbsp;
       <br />
-      <select id="account" name="account" onchange="accountSubmit()">
+      <select id="account" name="account">
        <option value=""><gettext>Select an account:</gettext></option>
 <loop:accounts>
        <option value="<tag:accounts.i />"><tag:accounts.val /></option>
       </select>
       <gettext>or</gettext>
 </if:accounts>
-      <input type="button" class="button" onclick="$('actionID').setValue('fetchmail_create');accountSubmit(true);return true;" value="<gettext>Create a New Account</gettext>" />
+      <input id="btn_create" type="button" class="button" value="<gettext>Create a New Account</gettext>" />
 </if:accountselect>
 <if:driverselect>
       <label for="fm_driver"><gettext>Mail server type to connect to:</gettext></label>&nbsp;
       <br />
-      <select id="fm_driver" name="fm_driver" onchange="driverSubmit()">
+      <select id="fm_driver" name="fm_driver">
        <option value=""><gettext>Select the mail server type:</gettext></option>
 <loop:drivers>
        <option value="<tag:drivers.key />"><tag:drivers.val /></option>
  <tr>
   <td nowrap="nowrap">
 <if:manage>
-   <input type="submit" name="save" class="button" onclick="$('actionID').setValue('fetchmail_prefs_save')" value="<if:fm_create><gettext>Create</gettext><else:fm_create><gettext>Save</gettext></else:fm_create></if:fm_create>" />
-   <input type="submit" name="delete" class="button" onclick="$('actionID').setValue('fetchmail_prefs_delete')" value="<gettext>Delete</gettext>" />
-   <input type="button" name="select" class="button" onclick="document.location.href='<tag:fetchurl />'" value="<gettext>Select Another Account</gettext>" />
+   <input id="btn_save" type="submit" name="save" class="button" value="<if:fm_create><gettext>Create</gettext><else:fm_create><gettext>Save</gettext></else:fm_create></if:fm_create>" />
+   <input id="btn_delete" type="submit" name="delete" class="button" value="<gettext>Delete</gettext>" />
+   <input id="btn_select" type="button" name="select" class="button" value="<gettext>Select Another Account</gettext>" />
 </if:manage>
-   <input type="button" name="back" class="button" onclick="document.location.href='<tag:prefsurl />'" value="<gettext>Return to Fetch Mail</gettext>" />
+   <input id="btn_return" type="button" name="back" class="button" value="<gettext>Return to Fetch Mail</gettext>" />
   </td>
  </tr>
 </table>