From a97a35b17ec2884b85b10503c7f795b1811d7719 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Wed, 17 Feb 2010 02:37:43 -0700 Subject: [PATCH] Improve identity selection javascript --- framework/Prefs/lib/Horde/Prefs/Ui.php | 2 +- horde/js/identityselect.js | 73 +++++++++++++++++ horde/templates/prefs/deleteidentity.inc | 23 +++--- horde/templates/prefs/identityselect.inc | 133 ++++++++++++------------------- 4 files changed, 135 insertions(+), 96 deletions(-) create mode 100644 horde/js/identityselect.js diff --git a/framework/Prefs/lib/Horde/Prefs/Ui.php b/framework/Prefs/lib/Horde/Prefs/Ui.php index c7fa086b6..75972714e 100644 --- a/framework/Prefs/lib/Horde/Prefs/Ui.php +++ b/framework/Prefs/lib/Horde/Prefs/Ui.php @@ -296,7 +296,7 @@ class Horde_Prefs_Ui $title = _("User Options"); if ($group == 'identities' && !$prefs->isLocked('default_identity')) { - $notification->push('newChoice()', 'javascript'); + Horde::addInlineScript(array('IdentitySelect.newChoice()'), 'dom'); } $GLOBALS['bodyId'] = 'services_prefs'; if (!$chunk) { diff --git a/horde/js/identityselect.js b/horde/js/identityselect.js new file mode 100644 index 000000000..f5cb8a92a --- /dev/null +++ b/horde/js/identityselect.js @@ -0,0 +1,73 @@ +/** + * Horde identity selection javascript. + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + */ + +var IdentitySelect = { + + newChoice: function() + { + var id = $('identity').down('[value=' + $F('identity') + ']').value; + + if (id < 0) { + $('prefs').reset(); + $('identity').setValue(id); + return; + } + + this.identities[id].each(function(a) { + var field = $(a[0]); + if (!field) { + return; + } + + switch (a[1]) { + case "enum": + for (var j = 0; j < field.options.length; ++j) { + if (field.options[j].value == a[2]) { + field.selectedIndex = j; + break; + } + } + break; + + case "implicit": + eval("newChoice_" + a[0] + "(" + a[2] + ")"); + break; + + case "checkbox": + default: + field.setValue(a[2]); + break; + } + }); + }, + + deleteIdentity: function() + { + var params, q, + id = $('identity').down('[value=' + $F('identity') + ']').value; + + if (id >= 0) { + q = this.deleteurl.indexOf('?'); + params = this.deleteurl.toQueryParams(); + params.id = id; + window.location.assign(this.deleteurl.substring(0, q) + '?' + params.toQueryString()); + } + }, + + onDomLoad: function() + { + if ($('identity')) { + $('identity').observe('change', this.newChoice.bind(this)); + } + if ($('deleteidentity')) { + $('deleteidentity').observe('click', this.deleteIdentity.bind(this)); + } + } + +}; + +document.observe('dom:loaded', IdentitySelect.onDomLoad.bind(IdentitySelect)); diff --git a/horde/templates/prefs/deleteidentity.inc b/horde/templates/prefs/deleteidentity.inc index 6fca6350a..1ef76beba 100644 --- a/horde/templates/prefs/deleteidentity.inc +++ b/horde/templates/prefs/deleteidentity.inc @@ -1,15 +1,12 @@ isLocked('default_identity')): ?> - -
-" />

+setRaw(true)->add('actionID', 'delete_identity')), Horde_Serialize::JSON) + )); +?> +
+

+ " /> +

+
diff --git a/horde/templates/prefs/identityselect.inc b/horde/templates/prefs/identityselect.inc index b2635414e..b4606e453 100644 --- a/horde/templates/prefs/identityselect.inc +++ b/horde/templates/prefs/identityselect.inc @@ -1,99 +1,68 @@ isLocked('default_identity')): ?> - + - -
-
- - + -
+ + -- 2.11.0