From bd397c0db622da9eeb9859ce9c112dca19d3a4b2 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Wed, 11 Feb 2009 01:30:33 -0700 Subject: [PATCH] Use new JS event style for this code --- imp/js/mailbox.js | 2 +- imp/js/message.js | 2 +- imp/js/src/mailbox.js | 12 ++++++++---- imp/js/src/message.js | 18 ++++++++++++++++-- imp/mailbox.php | 8 ++------ imp/message.php | 8 ++------ 6 files changed, 30 insertions(+), 20 deletions(-) diff --git a/imp/js/mailbox.js b/imp/js/mailbox.js index 22dce6eff..f5a27cb1c 100644 --- a/imp/js/mailbox.js +++ b/imp/js/mailbox.js @@ -1 +1 @@ -var ImpMessage={keyId:null,startrange:null,anySelected:function(){return $H(this.messagelist).keys().detect(function(a){return $("check"+a).checked})},selectRow:function(c,a){var b=$(c.replace(/check/,"row"));if(a){b.addClassName("selectedRow")}else{b.removeClassName("selectedRow").removeClassName("selectedRow-over")}$(c).checked=a},confirmDialog:function(a,b){RedBox.overlay=true;RedBox.showHtml('

'+b+'

')},submit:function(a){if(!this.anySelected()){alert(IMP.text.mailbox_submit);return}switch(a){case"delete_messages":if(IMP.conf.pop3&&!confirm(IMP.text.mailbox_delete)){return}break;case"spam_report":if(!confirm(IMP.text.spam_report)){return}break;case"nostpam_report":if(!confirm(IMP.text.notspam_report)){return}break}$("actionID").setValue(a);$("messages").submit()},makeSelection:function(b){var a="";switch(parseInt(b)){case-1:if($("checkAll").checked){a="!"}a+=IMP.conf.IMP_ALL;break;case 1:a=$F("filter1");break;default:a=$F("filter2")}if(a.empty()){return}else{if(a.startsWith("!")){this.selectFlagged(parseInt(a.substring(1)),false)}else{if(a.startsWith("+")){this.selectFlagged(a.substring(0,1),null)}else{this.selectFlagged(parseInt(a),true)}}}switch(parseInt(b)){case 1:$("select1").reset();break;default:$("select2").reset()}},selectRange:function(f){var g=f.element().readAttribute("id"),c=$(g),b=0,a,d;if(!c){return}a=c.checked;if(this.startrange!==null&&f.shiftKey){d=[$(this.startrange).readAttribute("id"),c.readAttribute("id")];$H(this.messagelist).keys().detect(function(e){e="check"+e;if(d.indexOf(e)!=-1){++b}if(b){this.selectRow(e,a);if(b==2){return true}}},this)}else{this.selectRow(g,a)}this.startrange=g},updateFolders:function(c){var b=$("targetMailbox1"),a=$("targetMailbox2");if(a){if((c==1&&$F(b)!="")||(c==2&&$F(a)!="")){b.selectedIndex=a.selectedIndex=(c==1)?b.selectedIndex:a.selectedIndex}}},transfer:function(d,b){var c,a;if(this.anySelected()){a=$("targetMbox");a.setValue((b==1)?$F("targetMailbox1"):$F("targetMailbox2"));if($F(a)=="*new*"){c=prompt(IMP.text.newfolder,"");if(c!=null&&c!=""){$("newMbox").setValue(1);a.setValue(c);this.submit(d)}}else{if($F(a)==""){alert(IMP.text.target_mbox)}else{this.submit(d)}}}else{alert(IMP.text.mailbox_selectone)}},selectFlagged:function(a,b){$H(this.messagelist).keys().each(function(f){var c,d=$("check"+f);if(a=="+"){c=!d.checked}else{if(a&this.messagelist[f]){c=b}else{c=!b}}this.selectRow(d.id,c)},this)},flagMessages:function(b){var a=$("flag1"),c=$("flag2");if((b==1&&$F(a)!="")||(b==2&&$F(c)!="")){if(this.anySelected()){document.messages.flag.value=(b==1)?$F(a):$F(c);this.submit("flag_messages")}else{if(b==1){a.selectedIndex=0}else{c.selectedIndex=0}alert(IMP.text.mailbox_selectone)}}},getMessage:function(e,d){if(!d){return e}var a=$H(this.messagelist).keys(),c=a.indexOf(e),b=c+d;if(c!=-1){if(b>=0&&b0)?$H(this.messagelist).keys().first():$H(this.messagelist).keys().last();if(Event.KEY_UP||Event.KEY_DOWN){g=$("subject"+this.keyId)}}}}else{if(j==32&&b.id.indexOf("subject")==0&&b.tagName=="A"){this.startrange="check"+this.keyId;this.selectRow(this.startrange,!$(this.startrange).checked)}else{if(!i.shiftKey){if(j==Event.KEY_LEFT&&$("prev")){h=$("prev").href}else{if(j==Event.KEY_RIGHT&&$("next")){h=$("next").href}}if(h){document.location.href=h}return}else{return}}}if(g){g.focus();k=$("row"+this.keyId);if(i.altKey){a=g.id.replace(/subject/,"check");this.selectRow(a,!$(a).checked)}else{if(c!=g.id&&k.className.indexOf("-over")==-1){k.className+="-over"}}if(c){k=$("row"+c);if(c!=g.id){k.className=k.className.replace(/-over/,"")}}}i.stop()},submitHandler:function(a){if(a.element().readAttribute("id").startsWith("select")){a.stop()}}};document.observe("change",ImpMessage.changeHandler.bindAsEventListener(ImpMessage));document.observe("click",ImpMessage.clickHandler.bindAsEventListener(ImpMessage));document.observe("keydown",ImpMessage.keyDownHandler.bindAsEventListener(ImpMessage));document.observe("submit",ImpMessage.submitHandler.bindAsEventListener(ImpMessage));Event.observe(window,"load",function(){if(window.fluid){try{window.fluid.setDockBadge(ImpMessage.unread)}catch(a){}}}); \ No newline at end of file +var ImpMessage={keyId:null,startrange:null,anySelected:function(){return $H(this.messagelist).keys().detect(function(a){return $("check"+a).checked})},selectRow:function(c,a){var b=$(c.replace(/check/,"row"));if(a){b.addClassName("selectedRow")}else{b.removeClassName("selectedRow").removeClassName("selectedRow-over")}$(c).checked=a},confirmDialog:function(a,b){RedBox.overlay=true;RedBox.showHtml('

'+b+'

')},submit:function(a){if(!this.anySelected()){alert(IMP.text.mailbox_submit);return}switch(a){case"delete_messages":if(IMP.conf.pop3&&!confirm(IMP.text.mailbox_delete)){return}break;case"spam_report":if(!confirm(IMP.text.spam_report)){return}break;case"nostpam_report":if(!confirm(IMP.text.notspam_report)){return}break}$("actionID").setValue(a);$("messages").submit()},makeSelection:function(b){var a="";switch(parseInt(b)){case-1:if($("checkAll").checked){a="!"}a+=IMP.conf.IMP_ALL;break;case 1:a=$F("filter1");break;default:a=$F("filter2")}if(a.empty()){return}else{if(a.startsWith("!")){this.selectFlagged(parseInt(a.substring(1)),false)}else{if(a.startsWith("+")){this.selectFlagged(a.substring(0,1),null)}else{this.selectFlagged(parseInt(a),true)}}}switch(parseInt(b)){case 1:$("select1").reset();break;default:$("select2").reset()}},selectRange:function(f){var g=f.element().readAttribute("id"),c=$(g),b=0,a,d;if(!c){return}a=c.checked;if(this.startrange!==null&&f.shiftKey){d=[$(this.startrange).readAttribute("id"),c.readAttribute("id")];$H(this.messagelist).keys().detect(function(e){e="check"+e;if(d.indexOf(e)!=-1){++b}if(b){this.selectRow(e,a);if(b==2){return true}}},this)}else{this.selectRow(g,a)}this.startrange=g},updateFolders:function(c){var b=$("targetMailbox1"),a=$("targetMailbox2");if(a){if((c==1&&$F(b)!="")||(c==2&&$F(a)!="")){b.selectedIndex=a.selectedIndex=(c==1)?b.selectedIndex:a.selectedIndex}}},_transfer:function(c){var b,a;if(this.anySelected()){a=$("targetMbox");a.setValue($("targetMailbox1"));if($F(a)=="*new*"){b=prompt(IMP.text.newfolder,"");if(b!=null&&b!=""){$("newMbox").setValue(1);a.setValue(b);this.submit(c)}}else{if($F(a)==""){alert(IMP.text.target_mbox)}else{this.submit(c)}}}else{alert(IMP.text.mailbox_selectone)}},selectFlagged:function(a,b){$H(this.messagelist).keys().each(function(f){var c,d=$("check"+f);if(a=="+"){c=!d.checked}else{if(a&this.messagelist[f]){c=b}else{c=!b}}this.selectRow(d.id,c)},this)},flagMessages:function(b){var a=$("flag1"),c=$("flag2");if((b==1&&$F(a)!="")||(b==2&&$F(c)!="")){if(this.anySelected()){document.messages.flag.value=(b==1)?$F(a):$F(c);this.submit("flag_messages")}else{if(b==1){a.selectedIndex=0}else{c.selectedIndex=0}alert(IMP.text.mailbox_selectone)}}},getMessage:function(e,d){if(!d){return e}var a=$H(this.messagelist).keys(),c=a.indexOf(e),b=c+d;if(c!=-1){if(b>=0&&b0)?$H(this.messagelist).keys().first():$H(this.messagelist).keys().last();if(Event.KEY_UP||Event.KEY_DOWN){g=$("subject"+this.keyId)}}}}else{if(j==32&&b.id.indexOf("subject")==0&&b.tagName=="A"){this.startrange="check"+this.keyId;this.selectRow(this.startrange,!$(this.startrange).checked)}else{if(!i.shiftKey){if(j==Event.KEY_LEFT&&$("prev")){h=$("prev").href}else{if(j==Event.KEY_RIGHT&&$("next")){h=$("next").href}}if(h){document.location.href=h}return}else{return}}}if(g){g.focus();k=$("row"+this.keyId);if(i.altKey){a=g.id.replace(/subject/,"check");this.selectRow(a,!$(a).checked)}else{if(c!=g.id&&k.className.indexOf("-over")==-1){k.className+="-over"}}if(c){k=$("row"+c);if(c!=g.id){k.className=k.className.replace(/-over/,"")}}}i.stop()},submitHandler:function(a){if(a.element().readAttribute("id").startsWith("select")){a.stop()}}};document.observe("change",ImpMessage.changeHandler.bindAsEventListener(ImpMessage));document.observe("click",ImpMessage.clickHandler.bindAsEventListener(ImpMessage));document.observe("keydown",ImpMessage.keyDownHandler.bindAsEventListener(ImpMessage));document.observe("submit",ImpMessage.submitHandler.bindAsEventListener(ImpMessage));Event.observe(window,"load",function(){if(window.fluid){try{window.fluid.setDockBadge(ImpMessage.unread)}catch(a){}}}); \ No newline at end of file diff --git a/imp/js/message.js b/imp/js/message.js index d275b25d6..b2546129f 100644 --- a/imp/js/message.js +++ b/imp/js/message.js @@ -1 +1 @@ -var ImpMessage={_arrowHandler:function(a){if(a.altKey||a.shiftKey||a.ctrlKey){return}switch(a.keyCode||a.charCode){case Event.KEY_LEFT:if($("prev")){document.location.href=$("prev").href}break;case Event.KEY_RIGHT:if($("next")){document.location.href=$("next").href}break}},submit:function(a){switch(a){case"spam_report":if(!window.confirm(IMP.text.spam_report)){return}break;case"notspam_report":if(!window.confirm(IMP.text.notspam_report)){return}break}$("actionID").setValue(a);$("messages").submit()},flagMessage:function(b){var a=$("flag1"),c=$("flag2");if((b==1&&$F(a))||(b==2&&$F(c))){$("flag").setValue((b==1)?$F(a):$F(c));this.submit("flag_message")}},transfer:function(d,b){var c,a=$("targetMbox");a.setValue((b==1)?$F("target1"):$F("target2"));if($F(a)=="*new*"){c=window.prompt(IMP.text.newfolder,"");if(c!=null&&c!=""){$("newMbox").setValue(1);a.setValue(c);this.submit(d)}}else{if(!$F(a)){window.alert(IMP.text.target_mbox)}else{this.submit(d)}}},updateFolders:function(a){var b=(a==1)?2:1;$("target"+b).selectedIndex=$("target"+a).selectedIndex},_messageActionsHover:function(){var a=new Element("IFRAME",{scrolling:"no",frameborder:0}).setStyle({position:"absolute"}).hide();a.writeAttribute("src","javascript:false;");$$("UL.msgactions LI").each(function(b){var c,e=b.down("UL"),d;if(!e){return}c=a.cloneNode(false);b.insert(c);c.clonePosition(e);d=b.getStyle("zIndex");if(d==""){b.setStyle({zIndex:2});c.setStyle({zIndex:1})}else{c.setStyle({zIndex:parseInt(d)-1})}b.observe("mouseout",function(){this.removeClassName("hover");b.down("iframe").hide()});b.observe("mouseover",function(){this.addClassName("hover");b.down("iframe").show()})})},onDomLoad:function(){if(!this.printmode){document.observe("keydown",this._arrowHandler.bindAsEventListener(this));document.observe("change",this._changeHandler.bindAsEventListener(this));if(Prototype.Browser.IE){this._messageActionsHover()}}},onLoad:function(){if(this.printmode){Event.observe(window,"afterprint",function(){window.close()});try{window.print()}catch(a){}}},_changeHandler:function(a){var b=a.element().readAttribute("id");if(b.startsWith("flag")){this.flagMessage(b.substring(4))}else{if(b.startsWith("target")){this.updateFolders(b.substring(6))}}}};document.observe("dom:loaded",ImpMessage.onDomLoad.bind(ImpMessage));Event.observe(window,"load",ImpMessage.onLoad.bind(ImpMessage)); \ No newline at end of file +var ImpMessage={_arrowHandler:function(a){if(a.altKey||a.shiftKey||a.ctrlKey){return}switch(a.keyCode||a.charCode){case Event.KEY_LEFT:if($("prev")){document.location.href=$("prev").href}break;case Event.KEY_RIGHT:if($("next")){document.location.href=$("next").href}break}},submit:function(a){switch(a){case"spam_report":if(!window.confirm(IMP.text.spam_report)){return}break;case"notspam_report":if(!window.confirm(IMP.text.notspam_report)){return}break}$("actionID").setValue(a);$("messages").submit()},flagMessage:function(b){var a=$("flag1"),c=$("flag2");if((b==1&&$F(a))||(b==2&&$F(c))){$("flag").setValue((b==1)?$F(a):$F(c));this.submit("flag_message")}},_transfer:function(c){var b,a=$("targetMbox");a.setValue($F("target1"));if($F(a)=="*new*"){b=window.prompt(IMP.text.newfolder,"");if(b!=null&&b!=""){$("newMbox").setValue(1);a.setValue(b);this.submit(c)}}else{if(!$F(a)){window.alert(IMP.text.target_mbox)}else{this.submit(c)}}},updateFolders:function(a){var b=(a==1)?2:1;$("target"+b).selectedIndex=$("target"+a).selectedIndex},_messageActionsHover:function(){var a=new Element("IFRAME",{scrolling:"no",frameborder:0}).setStyle({position:"absolute"}).hide();a.writeAttribute("src","javascript:false;");$$("UL.msgactions LI").each(function(b){var c,e=b.down("UL"),d;if(!e){return}c=a.cloneNode(false);b.insert(c);c.clonePosition(e);d=b.getStyle("zIndex");if(d==""){b.setStyle({zIndex:2});c.setStyle({zIndex:1})}else{c.setStyle({zIndex:parseInt(d)-1})}b.observe("mouseout",function(){this.removeClassName("hover");b.down("iframe").hide()});b.observe("mouseover",function(){this.addClassName("hover");b.down("iframe").show()})})},onDomLoad:function(){if(!this.printmode){document.observe("keydown",this._arrowHandler.bindAsEventListener(this));document.observe("change",this._changeHandler.bindAsEventListener(this));document.observe("click",this._clickHandler.bindAsEventListener(this));if(Prototype.Browser.IE){this._messageActionsHover()}}},onLoad:function(){if(this.printmode){Event.observe(window,"afterprint",function(){window.close()});try{window.print()}catch(a){}}},_changeHandler:function(a){var b=a.element().readAttribute("id");if(b.startsWith("flag")){this.flagMessage(b.substring(4))}else{if(b.startsWith("target")){this.updateFolders(b.substring(6))}}},_clickHandler:function(b){var a=b.element();if(a.match(".msgactions A.widget")){if(a.hasClassName("moveAction")){this._transfer("move_message")}else{if(a.hasClassName("copyAction")){this._transfer("copy_message")}}}}};document.observe("dom:loaded",ImpMessage.onDomLoad.bind(ImpMessage));Event.observe(window,"load",ImpMessage.onLoad.bind(ImpMessage)); \ No newline at end of file diff --git a/imp/js/src/mailbox.js b/imp/js/src/mailbox.js index 0a22fa9af..cdcbd431a 100644 --- a/imp/js/src/mailbox.js +++ b/imp/js/src/mailbox.js @@ -161,13 +161,13 @@ var ImpMessage = { } }, - transfer: function(actID, form) + _transfer: function(actID) { var newFolder, tmbox; if (this.anySelected()) { tmbox = $('targetMbox'); - tmbox.setValue((form == 1) ? $F('targetMailbox1') : $F('targetMailbox2')); + tmbox.setValue($('targetMailbox1')); // Check for a mailbox actually being selected. if ($F(tmbox) == '*new*') { @@ -264,7 +264,11 @@ var ImpMessage = { id = elt.readAttribute('id'); if (elt.match('.msgactions A.widget')) { - if (elt.hasClassName('permdeleteAction')) { + if (elt.hasClassName('moveAction')) { + this._transfer('move_messages'); + } else if (elt.hasClassName('copyAction')) { + this._transfer('copy_messages'); + } else if (elt.hasClassName('permdeleteAction')) { if (confirm(IMP.text.mailbox_delete)) { this.submit('delete_messages'); } @@ -276,7 +280,7 @@ var ImpMessage = { this.submit('blacklist'); } else if (elt.hasClassName('whitelistAction')) { this.submit('whitelist'); - } else if (elt.hasClassName('whitelistAction')) { + } else if (elt.hasClassName('forwardAction')) { this.submit('fwd_digest'); } else if (elt.hasClassName('spamAction')) { this.submit('spam_report'); diff --git a/imp/js/src/message.js b/imp/js/src/message.js index 2dbe9f0d6..349763cc1 100644 --- a/imp/js/src/message.js +++ b/imp/js/src/message.js @@ -60,10 +60,10 @@ var ImpMessage = { } }, - transfer: function(actID, form) + _transfer: function(actID) { var newFolder, tmbox = $('targetMbox'); - tmbox.setValue((form == 1) ? $F('target1') : $F('target2')); + tmbox.setValue($F('target1')); // Check for a mailbox actually being selected. if ($F(tmbox) == '*new*') { @@ -131,6 +131,7 @@ var ImpMessage = { // Set up left and right arrows to go to the previous/next page. document.observe('keydown', this._arrowHandler.bindAsEventListener(this)); document.observe('change', this._changeHandler.bindAsEventListener(this)); + document.observe('click', this._clickHandler.bindAsEventListener(this)); if (Prototype.Browser.IE) { this._messageActionsHover(); @@ -157,6 +158,19 @@ var ImpMessage = { } else if (id.startsWith('target')) { this.updateFolders(id.substring(6)); } + }, + + _clickHandler: function(e) + { + var elt = e.element(); + + if (elt.match('.msgactions A.widget')) { + if (elt.hasClassName('moveAction')) { + this._transfer('move_message'); + } else if (elt.hasClassName('copyAction')) { + this._transfer('copy_message'); + } + } } }; diff --git a/imp/mailbox.php b/imp/mailbox.php index 479d1b901..ffcec3717 100644 --- a/imp/mailbox.php +++ b/imp/mailbox.php @@ -515,8 +515,8 @@ if ($pageOb['msgcount']) { $n_template->set('imp_personal', IMP::FLAG_PERSONAL); $n_template->set('imp_forwarded', IMP::FLAG_FORWARDED); if ($n_template->get('use_folders')) { - $n_template->set('move', Horde::widget('#', _("Move to folder"), 'widget', '', "ImpMessage.transfer('move_messages', 1); return false;", _("Move"), true)); - $n_template->set('copy', Horde::widget('#', _("Copy to folder"), 'widget', '', "ImpMessage.transfer('copy_messages', 1); return false;", _("Copy"), true)); + $n_template->set('move', Horde::widget('#', _("Move to folder"), 'widget moveAction', '', '', _("Move"), true)); + $n_template->set('copy', Horde::widget('#', _("Copy to folder"), 'widget copyAction', '', '', _("Copy"), true)); $n_template->set('folder_options', $folder_options); } @@ -879,10 +879,6 @@ echo $mf_template->fetch(IMP_TEMPLATES . '/mailbox/message_footers.html'); if (($pageOb['end'] - $pageOb['begin']) >= 20) { $a_template->set('isbottom', true); echo $a_template->fetch(IMP_TEMPLATES . '/mailbox/actions.html'); - if ($n_template->get('use_folders')) { - $n_template->set('move', Horde::widget('#', _("Move to folder"), 'widget', '', "transfer('move_messages', 2); return false;", _("Move"), true)); - $n_template->set('copy', Horde::widget('#', _("Copy to folder"), 'widget', '', "transfer('copy_messages', 2); return false;", _("Copy"), true)); - } $n_template->set('id', 2); $n_template->set('isbottom', true); echo $n_template->fetch(IMP_TEMPLATES . '/mailbox/navbar.html'); diff --git a/imp/message.php b/imp/message.php index 839948068..9408386ad 100644 --- a/imp/message.php +++ b/imp/message.php @@ -450,8 +450,8 @@ if (!IMP::$printMode) { $n_template->set('id', 1); if ($conf['user']['allow_folders']) { - $n_template->set('move', Horde::widget('#', _("Move to folder"), 'widget', '', "transfer('move_message', 1); return false;", _("Move"), true)); - $n_template->set('copy', Horde::widget('#', _("Copy to folder"), 'widget', '', "transfer('copy_message', 1); return false;", _("Copy"), true)); + $n_template->set('move', Horde::widget('#', _("Move to folder"), 'widget moveAction', '', '', _("Move"), true)); + $n_template->set('copy', Horde::widget('#', _("Copy to folder"), 'widget copyAction', '', '', _("Copy"), true)); $n_template->set('options', IMP::flistSelect(array('heading' => _("This message to"), 'new_folder' => true, 'inc_tasklists' => true, 'inc_notepads' => true))); } @@ -752,10 +752,6 @@ if (!IMP::$printMode) { $n_template->set('id', 2); $n_template->set('isbottom', true); - if ($n_template->get('move')) { - $n_template->set('move', Horde::widget('#', _("Move to folder"), 'widget', '', "ImpMessage.transfer('move_message', 2); return false;", _("Move"), true), true); - $n_template->set('copy', Horde::widget('#', _("Copy to folder"), 'widget', '', "ImpMessage.transfer('copy_message', 2); return false;", _("Copy"), true)); - } echo $n_template->fetch(IMP_TEMPLATES . '/message/navbar_navigate.html'); } -- 2.11.0