Skip to content
Snippets Groups Projects
Commit ccbb8336 authored by Reinhold Kainhofer's avatar Reinhold Kainhofer
Browse files

Make Joomla translations available to JS

parent af1166d8
No related branches found
No related tags found
No related merge requests found
......@@ -60,13 +60,21 @@ class JFormFieldVmOrdernumberCounters extends JFormField {
}
protected function makeJSTranslationsAvailable() {
JText::script('PLG_ORDERNUMBER_COUNTER_QUERY_NAME');
JText::script('PLG_ORDERNUMBER_JS_NOT_AUTHORIZED');
JText::script('PLG_ORDERNUMBER_JS_NEWCOUNTER');
JText::script('PLG_ORDERNUMBER_JS_EDITCOUNTER');
JText::script('PLG_ORDERNUMBER_JS_INVALID_COUNTERVALUE');
JText::script('PLG_ORDERNUMBER_JS_MODIFY_FAILED');
JText::script('PLG_ORDERNUMBER_JS_DELETECOUNTER');
JText::script('PLG_ORDERNUMBER_JS_DELETE_FAILED');
JText::script('PLG_ORDERNUMBER_JS_ADD_FAILED');
}
protected function getInput() {
$pluginpath = '/plugins/vmshopper/ordernumber/ordernumber/';
$doc = JFactory::getDocument()->addStyleSheet(JURI::root(true) . $pluginpath . 'assets/css/ordernumber.css');
$doc->addScript(JURI::root(true).$pluginpath . 'assets/js/ordernumber.js');
vmJsApi::jQuery();
$this->makeJSTranslationsAvailable();
// Look up the current counters
$db = JFactory::getDBO();
......
......@@ -55,3 +55,14 @@ PLG_ORDERNUMBER_COUNTERLIST_EXISTS="Counter '%s' already exists."
PLG_ORDERNUMBER_FIELDSET_ORDERNUMBER="Order Numbers"
PLG_ORDERNUMBER_FIELDSET_INVOICENUMBER="Invoice Numbers"
PLG_ORDERNUMBER_FIELDSET_CUSTOMERNUMBER="Customer Numbers"
PLG_ORDERNUMBER_JS_NOT_AUTHORIZED="You are not authorized to modify order number counters."
PLG_ORDERNUMBER_JS_NEWCOUNTER="Please enter the format/name of the new counter:"
PLG_ORDERNUMBER_JS_DELETECOUNTER="Really delete counter '{0}' with value '{1}'?"
PLG_ORDERNUMBER_JS_EDITCOUNTER="{0}Please enter the new value for the counter '{1}' (current value: {2}):"
PLG_ORDERNUMBER_JS_INVALID_COUNTERVALUE="You entered an invalid value for the counter.\n\n"
PLG_ORDERNUMBER_JS_MODIFY_FAILED="Failed modifying counter {0}"
PLG_ORDERNUMBER_JS_DELETE_FAILED="Failed deleting counter {0}"
PLG_ORDERNUMBER_JS_ADD_FAILED="Failed adding counter {0}"
......@@ -55,3 +55,14 @@ PLG_ORDERNUMBER_COUNTERLIST_EXISTS="Counter '%s' already exists."
PLG_ORDERNUMBER_FIELDSET_ORDERNUMBER="Order Numbers"
PLG_ORDERNUMBER_FIELDSET_INVOICENUMBER="Invoice Numbers"
PLG_ORDERNUMBER_FIELDSET_CUSTOMERNUMBER="Customer Numbers"
PLG_ORDERNUMBER_JS_NOT_AUTHORIZED="You are not authorized to modify order number counters."
PLG_ORDERNUMBER_JS_NEWCOUNTER="Please enter the format/name of the new counter:"
PLG_ORDERNUMBER_JS_DELETECOUNTER="Really delete counter '{0}' with value '{1}'?"
PLG_ORDERNUMBER_JS_EDITCOUNTER="{0}Please enter the new value for the counter '{1}' (current value: {2}):"
PLG_ORDERNUMBER_JS_INVALID_COUNTERVALUE="You entered an invalid value for the counter.\n\n"
PLG_ORDERNUMBER_JS_MODIFY_FAILED="Failed modifying counter {0}"
PLG_ORDERNUMBER_JS_DELETE_FAILED="Failed deleting counter {0}"
PLG_ORDERNUMBER_JS_ADD_FAILED="Failed adding counter {0}"
......@@ -13,6 +13,15 @@ var updateMessages = function(messages, area) {
}
newmessages.appendTo( "#system-message-container #system-message");
}
String.Format = function() {
var s = arguments[0];
for (var i = 0; i < arguments.length - 1; i++) {
var reg = new RegExp("\\{" + i + "\\}", "gm");
s = s.replace(reg, arguments[i + 1]);
}
return s;
}
var getCounterData = function (btn) {
var row=jQuery(btn).parents("tr.counter_row");
return { row: row };
......@@ -20,7 +29,7 @@ var getCounterData = function (btn) {
var handleJSONResponse = function (json, counter) {
updateMessages(json['messages'], "ordernumber");
if (!json.authorized) {
alert("You are not authorized to modify order number counters.");
alert(Joomla.JText._('PLG_ORDERNUMBER_JS_NOT_AUTHORIZED', "You are not authorized to modify order number counters."));
} else if (json.error) {
alert(json.error);
} else {
......@@ -35,11 +44,12 @@ var ajaxEditCounter = function (btn, nrtype, ctr, value) {
var value = NaN;
var msgprefix = "";
while (isNaN(value) && (value != null)) {
value = prompt (msgprefix+"Please enter the new value for the counter '" + counter.counter + "' (current value: " + counter.value + "):", counter.value);
var editprompt = Joomla.JText._('PLG_ORDERNUMBER_JS_EDITCOUNTER', "{0}Please enter the new value for the counter '{1}' (current value: {2}):");
value = prompt (String.Format(editprompt, msgprefix, counter.counter, counter.value), counter.value);
if (value != null)
value = parseInt(value);
if (isNaN(value))
msgprefix = "You entered an invalid value for the counter.\n\n";
msgprefix = Joomla.JText._('PLG_ORDERNUMBER_JS_INVALID_COUNTERVALUE', "You entered an invalid value for the counter.\n\n");
}
if (value != null) {
var loading = jQuery("img.vm-ordernumber-loading").first().clone().insertAfter(btn).show();
......@@ -55,10 +65,10 @@ var ajaxEditCounter = function (btn, nrtype, ctr, value) {
if (json.success>0) {
jQuery(counter.row).children(".counter_value").text(value);
} else {
alert ("Failed modifying counter "+counter.counter);
alert (String.Format(Joomla.JText._('PLG_ORDERNUMBER_JS_MODIFY_FAILED', "Failed modifying counter {0}"), counter.counter));
}
},
error: function() { alert ("ERROR: Failed modifying counter "+counter.counter); },
error: function() { alert (String.Format(Joomla.JText._('PLG_ORDERNUMBER_JS_MODIFY_FAILED', "Failed modifying counter {0}"), counter.counter)); },
complete: function() { jQuery(loading).remove(); },
});
}
......@@ -68,7 +78,7 @@ var ajaxDeleteCounter = function (btn, nrtype, ctr, value) {
counter.type=nrtype;
counter.counter=ctr;
counter.value=value;
var proceed = confirm ("Really delete counter '"+counter.counter+"' with value '"+counter.value+"'?");
var proceed = confirm (String.Format(Joomla.JText._('PLG_ORDERNUMBER_JS_DELETECOUNTER', "Really delete counter '{0}' with value '{1}'?"), counter.counter, counter.value));
if (proceed == true) {
var loading = jQuery("img.vm-ordernumber-loading").first().clone().insertAfter(btn).show();
jQuery.ajax({
......@@ -83,17 +93,17 @@ var ajaxDeleteCounter = function (btn, nrtype, ctr, value) {
if (json.success>0) {
jQuery(counter.row).fadeOut(1500, function() { $(this).remove(); });
} else {
alert ("Failed modifying counter "+counter.counter);
alert (String.Format(Joomla.JText._('PLG_ORDERNUMBER_JS_DELETE_FAILED', "Failed deleting counter {0}"), counter.counter));
}
},
error: function() { alert ("ERROR: Failed modifying counter "+counter.counter); },
error: function() { alert (String.Format(Joomla.JText._('PLG_ORDERNUMBER_JS_DELETE_FAILED', "Failed deleting counter {0}"), counter.counter)); },
complete: function() { jQuery(loading).remove(); },
});
}
}
var ajaxAddCounter = function (btn, nrtype) {
var row = jQuery(btn).parents("tr.addcounter_row");
var countername = prompt ("Please enter the format/name of the new counter:");
var countername = prompt (Joomla.JText._('PLG_ORDERNUMBER_JS_NEWCOUNTER', "Please enter the format/name of the new counter:"));
if (countername != null) {
var loading = jQuery("img.vm-ordernumber-loading").first().clone().insertAfter(jQuery(btn).find("img.vmordernumber-counter-addbtn")).show();
jQuery.ajax({
......@@ -109,9 +119,11 @@ var ajaxAddCounter = function (btn, nrtype) {
if (json.newrow) {
jQuery(row).before(jQuery(json.newrow));
}
} else {
alert (String.Format(Joomla.JText._('PLG_ORDERNUMBER_JS_ADD_FAILED', "Failed adding counter {0}"), counter.counter));
}
},
error: function() { alert ("ERROR: Failed adding counter "+countername); },
error: function() { alert (String.Format(Joomla.JText._('PLG_ORDERNUMBER_JS_ADD_FAILED', "Failed adding counter {0}"), counter.counter)); },
complete: function() { jQuery(loading).remove(); },
});
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment