From 7b810ec227b704b1daf7d7d76eaa65aaf12c86e7 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Mon, 9 Nov 2009 13:28:53 -0800 Subject: [PATCH] i18n the template attachments, fixes bug #11186 Also, rework some of the JS code according to jslint. --- docs/changelog/7.x.x.txt | 1 + lib/WebGUI/Asset/Template.pm | 9 +++-- lib/WebGUI/i18n/English/Asset_Template.pm | 11 ++++++ www/extras/templateAttachments.js | 44 +++++++++++++++++------ 4 files changed, 52 insertions(+), 13 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 5c7967ee8..9153e603b 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -4,6 +4,7 @@ - fixed #11203: Manage groups in group: everyone added on save - fixed #11101: 7.6.35-7.7 upgrade leaves packages - fixed #11209: Form::HTMLArea uses invalid javascript identifier + - fixed #11186: Template Attachments i18n 7.8.4 - Fixed a compatibility problem between WRE and new Spectre code. diff --git a/lib/WebGUI/Asset/Template.pm b/lib/WebGUI/Asset/Template.pm index dc242d5f8..41771e009 100644 --- a/lib/WebGUI/Asset/Template.pm +++ b/lib/WebGUI/Asset/Template.pm @@ -372,9 +372,12 @@ sub getEditForm { ); my ($style, $url) = $self->session->quick(qw(style url)); - $style->setScript($url->extras('yui/build/yahoo/yahoo-min.js'), {type => 'text/javascript'}); - $style->setScript($url->extras('yui/build/json/json-min.js'), {type => 'text/javascript'}); - $style->setScript($url->extras('yui/build/dom/dom-min.js'), {type => 'text/javascript'}); + $style->setScript($url->extras('yui/build/yahoo/yahoo-min.js'), {type => 'text/javascript'}); + $style->setScript($url->extras('yui/build/json/json-min.js'), {type => 'text/javascript'}); + $style->setScript($url->extras('yui/build/dom/dom-min.js'), {type => 'text/javascript'}); + $style->setScript($url->extras('yui/build/event/event-min.js'), {type => 'text/javascript'}); + $style->setScript($url->extras('yui/build/connect/connect-min.js'), {type => 'text/javascript'}); + $style->setScript($url->extras('yui-webgui/build/i18n/i18n.js'), {type => 'text/javascript'}); pop(@headers); my $scriptUrl = $url->extras('templateAttachments.js'); diff --git a/lib/WebGUI/i18n/English/Asset_Template.pm b/lib/WebGUI/i18n/English/Asset_Template.pm index f381d584e..d8c994178 100644 --- a/lib/WebGUI/i18n/English/Asset_Template.pm +++ b/lib/WebGUI/i18n/English/Asset_Template.pm @@ -379,6 +379,17 @@ Any scratch variables will be available in the template with this syntax:
message => q|Template in clipboard|, lastUpdated => 0, }, + + 'Already attached!' => { + message => q|Already attached!|, + lastUpdated => 0, + }, + + 'No url!' => { + message => q|No url!|, + lastUpdated => 0, + }, + }; 1; diff --git a/www/extras/templateAttachments.js b/www/extras/templateAttachments.js index 7c94014ee..594f1bbaa 100644 --- a/www/extras/templateAttachments.js +++ b/www/extras/templateAttachments.js @@ -1,6 +1,27 @@ // Really only used by the Template editor, but it doesn't belong in perl // code. It's too long. +if ( typeof WebGUI == "undefined" ) { + WebGUI = {}; +} +if ( typeof WebGUI.TemplateAttachments == "undefined" ) { + WebGUI.TemplateAttachments = {}; +} +if ( typeof WebGUI.TemplateAttachments.i18n == "undefined" ) { + WebGUI.TemplateAttachments.i18n = new WebGUI.i18n( { + namespaces : { + 'Asset_Template' : [ + "attachment header remove", + "Already attached!", + "No url!" + ] + }, + onpreload : { + fn : function(){} + } + } ); +} + var addClick = (function() { var uniqueId = 1; var count = 0; @@ -57,12 +78,15 @@ var addClick = (function() { function nameFields(u) { var id = uniqueId++; var obj = urls[u]; - if (!obj.index.name) + if (!obj.index.name) { obj.index.name = 'attachmentIndex' + id; - if (!obj.type.name) + } + if (!obj.type.name) { obj.type.name = 'attachmentType' + id; - if (!obj.url.name) + } + if (!obj.url.name) { obj.url.name = 'attachmentUrl' + id; + } } // Make a function which will remove an attachment (remove the table row @@ -77,7 +101,7 @@ var addClick = (function() { if (--count == 0) { displayTable.style.display = 'none'; } - } + }; } // Add a new attachment (proper table row, etc). Attachments that already @@ -85,7 +109,7 @@ var addClick = (function() { // to the backend. function add(d) { if (urls[d.url]) { - alert('Already attached!'); + alert(WebGUI.TemplateAttachments.i18n.get('Asset_Template','Already attached!')); return; } @@ -120,7 +144,7 @@ var addClick = (function() { var oldValue = url.oldValue; if (urls[newValue]) { url.value = oldValue; - alert('Already attached!'); + alert(WebGUI.TemplateAttachments.i18n.get('Asset_Template','Already attached!')); } else { url.oldValue = newValue; @@ -134,7 +158,7 @@ var addClick = (function() { var btn = document.createElement('input'); btn.type = 'button'; - btn.value = 'Remove'; + btn.value = WebGUI.TemplateAttachments.i18n.get('Asset_Template','attachment header remove'); btn.onclick = remover(d.url); var tr = document.createElement('tr'); @@ -149,7 +173,7 @@ var addClick = (function() { tr : tr, index : index, type : type, - url : url, + url : url }; nameFields(d.url); @@ -165,9 +189,9 @@ var addClick = (function() { url: nodes.url.value }; - d.url = d.url.replace(/^\s+|\s+$/g, '') + d.url = d.url.replace(/^\s+|\s+$/g, ''); if (d.url == '') { - alert('No url!'); + alert(WebGUI.TemplateAttachments.i18n.get('Asset_Template','No url!')); return; } add(d);