Event.observe(window, 'load', function() {
website = 0;
updateToolzMenuDynamic();
updateToolzMenu();
updateToolzMenuEventsStatic();
updateToolzMenuEventsDynamic();
updateToolzMenuEventsDynamicWebsites();
});
updateToolzMenu = function() {
$('selectedWebsite').selectedIndex = website;
ajaxObj.updateToolzMenuLanguages();
ajaxObj.updateToolzMenuLanguageRef();
ajaxObj.updateToolzMenuModules();
}
updateToolzMenuDynamic = function() {
ajaxObj.getWebsites();
}
updateToolzMenuEventsStatic = function() {
Event.observe('btnAddLanguage', 'click', eventObj.addLanguage.bindAsEventListener(eventObj));
Event.observe('btnAddModule', 'click', eventObj.addModule.bindAsEventListener(eventObj));
Event.observe('btnAddWebsite', 'click', eventObj.addWebsite.bindAsEventListener(eventObj));
Event.observe('addedLanguage', 'focus', eventObj.clearInput.bindAsEventListener(eventObj));
Event.observe('addedModule', 'focus', eventObj.clearInput.bindAsEventListener(eventObj));
Event.observe('addedWebsite', 'focus', eventObj.clearInput.bindAsEventListener(eventObj));
Event.observe('uploadFileBtn', 'click', eventObj.startUpload.bindAsEventListener(eventObj));
Event.observe('helpBtn', 'click', eventObj.getHelp.bindAsEventListener(eventObj));
}
updateToolzMenuEventsDynamic = function() {
Event.observe('availableLanguages', 'change', eventObj.getList.bindAsEventListener(eventObj));
Event.observe('availableLanguageRef', 'change', eventObj.getList.bindAsEventListener(eventObj));
Event.observe('availableModules', 'change', eventObj.getList.bindAsEventListener(eventObj));
}
updateToolzMenuEventsDynamicWebsites = function() {
Event.observe('selectedWebsite', 'change', eventObj.getWebsite.bindAsEventListener(eventObj));
}
updateListEventsDynamic = function() {
$$('.transformable').each(function(e) {
Event.observe(e, 'click', eventObj.getTransformation.bindAsEventListener(eventObj));
});
$$('.magicalInput').each(function(e) {
Event.observe(e, 'blur', eventObj.getTransformationBack.bindAsEventListener(eventObj));
});
$$('.delConstantBtn').each(function(e) {
Event.observe(e, 'click', eventObj.delConstant.bindAsEventListener(eventObj));
});
Event.observe('addConstantBtn', 'click', eventObj.addNewConstant.bindAsEventListener(eventObj));
}
var eventObj = {
getHelp: function() {
$('help').toggle();
},
startUpload: function() {
$('uplFrm').submit();
},
addNewConstant: function() {
if('' !== $F('addNewConstant') && '0' !== $F('selectedWebsite')) {
ajaxObj.addNewConstant($F('addNewConstant'), $F('availableModules'));
} else if ('' === $F('addNewConstant')) {
$('toolzMenuMainMessage').update('Constant name is empty');
} else {
$('toolzMenuMainMessage').update('You must select a website first');
}
},
delConstant: function(e) {
var sConst = Event.element(e).id.substring(Event.element(e).id.indexOf('_') + 1);
ajaxObj.delConstant(sConst, $F('availableModules'));
},
addLanguage: function () {
if('' !== $F('addedLanguage') && '0' !== $F('selectedWebsite')) {
ajaxObj.addLanguage($F('addedLanguage'));
} else if ('' === $F('addedLanguage')) {
$('toolzMenuMainMessage').update('Language name is empty');
} else {
$('toolzMenuMainMessage').update('You must select a website first');
}
},
addModule: function () {
if('' !== $F('addedModule') && '0' !== $F('selectedWebsite')) {
ajaxObj.addModule($F('addedModule'), $F('moduleEncoding'));
} else if ('' === $F('addedModule')) {
$('toolzMenuMainMessage').update('Module name is empty');
} else {
$('toolzMenuMainMessage').update('You must select a website first');
}
},
addWebsite: function () {
if('' !== $F('addedWebsite')) {
ajaxObj.addWebsite($F('addedWebsite'));
} else {
$('toolzMenuMainMessage').update('Website name is empty');
}
},
getWebsite: function() {
eventObj.resetList();
website = $('selectedWebsite').selectedIndex;
updateToolzMenu();
updateToolzMenuEventsDynamic();
},
getList: function() {
if($F('availableModules') === '0' || $F('availableLanguages') === '0' || $F('availableLanguageRef') === '0' || $F('selectedWebsite') === '0') {
var sMsg = '';
if($F('availableModules') === '0') {
sMsg += 'You must select a module<br />';
}
if($F('availableLanguages') === '0') {
sMsg += 'You must select a base language<br />';
}
if($F('availableLanguageRef') === '0') {
sMsg += 'You must select a reference language<br />';
}
if($F('selectedWebsite') === '0') {
sMsg += 'You must select a website<br />';
}
$('toolzMenuMainMessage').update(sMsg);
return false;
}
$('toolzMenuMainMessage').update('');
eventObj.resetList();
ajaxObj.getList($F('availableLanguages'), $F('availableModules'), $F('availableLanguageRef'), $F('selectedWebsite'));
},
resetList: function() {
$('toolzMenuTr').nextSiblings().each(function(e) {
e.remove();
});
var tr = document.createElement('tr');
var td = document.createElement('td');
var trId = document.createAttribute('id');
var tdColspan = document.createAttribute('colspan');
var tdId = document.createAttribute('id');
trId.nodeValue = 'toBeReplaced';
tr.setAttributeNode(trId);
tdColspan.nodeValue = '4';
tdId.nodeValue = 'toBeReplacedTd';
td.setAttributeNode(tdColspan);
td.setAttributeNode(tdId);
tr.appendChild(td);
$('list').appendChild(tr);
},
getTransformation: function(e) {
e = Event.element(e);
e.nextSiblings().each (function (e2) {
e2.setStyle ({
height: e.getHeight()+'px',
width: e.getWidth()+'px',
overflow: 'visible'
});
e.hide();
e2.show();
e2.focus();
});
},
getTransformationBack: function(e) {
e = Event.element(e);
e.previousSiblings().each (function (e2) {
var sSavedValue = $(e2).firstChild.data;
e2.update(e.value);
e.hide();
e2.show();
if($F(e) !== sSavedValue) {
ajaxObj.updateValue(e.id);
}
});
},
clearInput : function(e) {
$(Event.element(e)).clear();
}
};
var ajaxObj = {
updateToolzMenuLanguages: function() {
var oAjax = new Ajax.Request(
'ajax/ajax.back.office.update.toolz.menu.php', {
method: 'post',
parameters: {'TYPE': 'language', 'WEB': $F('selectedWebsite')},
onSuccess: ajaxObj.updateToolzMenuLanguages_onSuccess,
onError: ajaxObj.onError,
asynchronous: false
}
);
},
updateToolzMenuLanguageRef: function() {
var oAjax = new Ajax.Request(
'ajax/ajax.back.office.update.toolz.menu.php', {
method: 'post',
parameters: {'TYPE': 'languageRef', 'WEB': $F('selectedWebsite')},
onSuccess: ajaxObj.updateToolzMenuLanguageRef_onSuccess,
onError: ajaxObj.onError,
asynchronous: false
}
);
},
updateToolzMenuModules: function() {
var oAjax = new Ajax.Request(
'ajax/ajax.back.office.update.toolz.menu.php', {
method: 'post',
parameters: {'TYPE': 'module', 'WEB': $F('selectedWebsite')},
onSuccess: ajaxObj.updateToolzMenuModules_onSuccess,
onError: ajaxObj.onError,
asynchronous: false
}
);
},
addLanguage: function(sLng) {
var oAjax = new Ajax.Request(
'ajax/ajax.back.office.update.toolz.menu.php', {
method: 'post',
parameters: {'TYPE': 'addLanguage', 'LNG': sLng, 'WEB': $F('selectedWebsite')},
onSuccess: ajaxObj.addToolzMenu_onSuccess,
onError: ajaxObj.onError,
asynchronous: false
}
);
},
addModule: function(sMod, sEncoding) {
var oAjax = new Ajax.Request(
'ajax/ajax.back.office.update.toolz.menu.php', {
method: 'post',
parameters: {'TYPE': 'addModule', 'MOD': sMod, 'ENCODING': sEncoding,'WEB': $F('selectedWebsite')},
onSuccess: ajaxObj.addToolzMenu_onSuccess,
onError: ajaxObj.onError,
asynchronous: false
}
);
},
addWebsite: function(sWeb) {
var oAjax = new Ajax.Request(
'ajax/ajax.back.office.update.toolz.menu.php', {
method: 'post',
parameters: {'TYPE': 'addWebsite', 'WEB': sWeb},
onSuccess: ajaxObj.addToolzMenu_onSuccess,
onError: ajaxObj.onError,
asynchronous: false
}
);
},
getList: function(sLng, sMod, sRef, sWebsite) {
var oAjax = new Ajax.Request(
'ajax/ajax.back.office.display.list.php', {
method: 'post',
parameters: {'LNG': sLng, 'MOD': sMod, 'REF': sRef, 'WEB': sWebsite},
onSuccess: ajaxObj.getList_onSuccess,
onError: ajaxObj.onError,
asynchronous: false
}
);
},
updateValue: function(iId) {
var oAjax = new Ajax.Request(
'ajax/ajax.back.office.update.value.php', {
method: 'post',
parameters: {'CLEF': iId, 'VAL': $F(iId), 'WEB': $F('selectedWebsite')},
onSuccess: ajaxObj.updateValue_onSuccess,
onError: ajaxObj.onError,
asynchronous: false
}
);
},
addNewConstant: function(sConst, sMod) {
var oAjax = new Ajax.Request(
'ajax/ajax.back.office.add.constant.php', {
method: 'post',
parameters: {'CONST': sConst, 'MOD': sMod, 'WEB': $F('selectedWebsite')},
onSuccess: ajaxObj.addNewConstant_onSuccess,
onError: ajaxObj.onError,
asynchronous: false
}
);
},
delConstant: function(sConst, sMod) {
var oAjax = new Ajax.Request(
'ajax/ajax.back.office.del.constant.php', {
method: 'post',
parameters: {'CONST': sConst, 'MOD': sMod, 'WEB': $F('selectedWebsite')},
onSuccess: ajaxObj.delConstant_onSuccess,
onError: ajaxObj.onError,
asynchronous: false
}
);
},
getWebsites: function() {
var oAjax = new Ajax.Request(
'ajax/ajax.back.office.get.websites.php', {
method: 'post',
onSuccess: ajaxObj.getWebsites_onSuccess,
onError: ajaxObj.onError,
asynchronous: false
}
);
},
onError: function() {
$('toolzMenuMainMessage').update('Unexpected error!');
},
getWebsites_onSuccess: function(xhr) {
if(xhr.responseText.substr(0,4) === 'ERR_') {
$('toolzMenuMainMessage').update(xhr.responseText.substring(4));
} else {
$('toolzMenuSelectWebsite').update(xhr.responseText);
}
},
addNewConstant_onSuccess: function(xhr) {
if(xhr.responseText.substr(0,4) === 'ERR_') {
$('toolzMenuMainMessage').update(xhr.responseText.substring(4));
} else {
$('toolzMenuMainMessage').update(xhr.responseText);
eventObj.getList();
}
},
delConstant_onSuccess: function(xhr) {
if(xhr.responseText.substr(0,4) === 'ERR_') {
$('toolzMenuMainMessage').update(xhr.responseText.substring(4));
} else {
$('toolzMenuMainMessage').update(xhr.responseText);
eventObj.getList();
}
},
addToolzMenu_onSuccess: function(xhr) {
if(xhr.responseText.substr(0,4) === 'ERR_') {
$('toolzMenuMainMessage').update(xhr.responseText.substring(4));
} else {
$('toolzMenuMainMessage').update(xhr.responseText);
updateToolzMenuDynamic();
updateToolzMenu();
updateToolzMenuEventsDynamic();
updateToolzMenuEventsDynamicWebsites();
$('addedLanguage').clear();
$('addedModule').clear();
$('addedWebsite').clear();
eventObj.resetList();
}
},
updateValue_onSuccess: function(xhr) {
if(xhr.responseText.substr(0,4) === 'ERR_') {
$('toolzMenuMainMessage').update(xhr.responseText.substring(4));
} else {
$('toolzMenuMainMessage').update(xhr.responseText);
eventObj.getList();
}
},
getList_onSuccess: function(xhr) {
if(xhr.responseText.substr(0,4) === 'ERR_') {
$('toolzMenuMainMessage').update(xhr.responseText.substring(4));
} else {
$('toBeReplaced').replace(xhr.responseText);
updateListEventsDynamic();
}
},
updateToolzMenuLanguages_onSuccess: function(xhr) {
if(xhr.responseText.substr(0,4) === 'ERR_') {
$('toolzMenuMainMessage').update(xhr.responseText.substring(4));
} else {
$('toolzMenuLanguages').update(xhr.responseText);
}
},
updateToolzMenuLanguageRef_onSuccess: function(xhr) {
if(xhr.responseText.substr(0,4) === 'ERR_') {
$('toolzMenuMainMessage').update(xhr.responseText.substring(4));
} else {
$('toolzMenuLanguageRef').update(xhr.responseText);
}
},
updateToolzMenuModules_onSuccess: function(xhr) {
if(xhr.responseText.substr(0,4) === 'ERR_') {
$('toolzMenuMainMessage').update(xhr.responseText.substring(4));
} else {
$('toolzMenuModules').update(xhr.responseText);
}
}
}
|