resources.tools_javascript_ait_manager.js Maven / Gradle / Ivy
/* appNG JS */
var app = {
markup: {
dialogWindow:'\
\
\
\
<#label#>
\
\
\
\
',
dialogWindowButtons: '<#buttonAbort#><#buttonOk#>',
dialogWindowButtonsWithLoader: '<#buttonAbort#><#buttonOk#>',
ajaxLoader: '\
\
\
\
\
\
Operation is running. Please wait ...
\
\
\
\
\
\
\
\
',
externalContentWindow: '\
\
\
\
Content of \'<#contentId#>\'.\'<#type#>\'
\
\
\
\
'
},
label: {
inProcess: 'The process is carried out. Please wait ...',
isRunning: 'Operation is running. Please wait ...',
areYouSure: 'Are you sure?',
buttonYes: 'Yes',
buttonNo: 'No',
buttonAbort: 'Cancel',
buttonRejectUpdates: 'Discard changes',
uploadedItem: 'Media element uploaded',
uploadedItems: 'Media elements uploaded',
buttonClose: 'Close'
},
richTextEditors: new Array(),
mstConfigDefault: {
onOrderChange: function(table, row) {
app.updateTableDate(table, row);
},
onMouseOverClass: 'tDnD_whileDrag'
},
init: function(){
this.initForms();
this.initTables();
this.initFormUndoButtons();
this.initLoader();
this.initMultiSelect();
$('.autosize').autosize();
this.initLightwindowContents();
},
initButton: function(id, imageOver){
if (jQuery('#'+id).get(0)) {
var imageNormal = jQuery('#'+id).get(0).src;
jQuery('#'+id).bind('mouseover', function(){ jQuery('#'+id).get(0).src = imageOver });
jQuery('#'+id).bind('mouseout', function(){ jQuery('#'+id).get(0).src = imageNormal });
}
},
initDisableButton: function(id,divId){
if (jQuery('#'+id).get(0)) {
jQuery('#'+id).bind('click', function(){
app.toggleDisableButton(id,divId);
});
app.toggleDisableButton(id,divId);
}
},
toggleDisableButton: function(id,divId){
if (jQuery('#'+id).attr('checked') == true) {
jQuery('#'+ divId + ' label').each(function(){ jQuery(this).removeClass('disabled'); });
jQuery('#'+ divId + ' input').each(function(){
jQuery(this).removeAttr('disabled');
jQuery(this).removeAttr('readonly');
});
}
else {
jQuery('#'+ divId + ' label').each(function(){ jQuery(this).addClass('disabled'); });
jQuery('#'+ divId + ' input').each(function(){
jQuery(this).attr({disabled:'disabled'});
jQuery(this).attr({readonly:'readonly'});
});
jQuery('label[for='+id+']').removeClass('disabled');
jQuery('#'+id).removeAttr('disabled');
jQuery('#'+id).removeAttr('readonly');
}
},
updateTableDate: function(table, row){
var hitstart = jQuery('#hitstart').attr('value');
hitstart = hitstart ? parseInt(hitstart) : 0;
jQuery('tbody tr', jQuery(table)).each( function(index){
jQuery(this).attr('rel', index);
jQuery('td span.index', this).html(index + 1 + hitstart);
jQuery('.order', this).attr('value', index + 1 + hitstart);
});
},
initForms: function(){
jQuery('form').bind('submit', function(){
if (!jQuery(this).hasClass('without-submit-control')) return false;
});
jQuery('form').bind('reset', function(){
if (!jQuery(this).hasClass('without-submit-control')) return false;
});
if (typeof(formsArr) == 'object'){
for (var i=0; i < formsArr.length; i++) {
// hide form buttons if all elements are disabled
if(this.areAllElementsDisabled(formsArr[i].obj.elements)) {
jQuery(formsArr[i].obj).find('div.buttons_panel').hide();
}
}
}
},
areAllElementsDisabled: function(elements){
for (var i=0; i < elements.length; i++) {
switch (elements[i].tagName.toLowerCase()) {
case 'input':
switch (elements[i].type.toLowerCase()) {
case 'text':
case 'password':
case 'radio':
case 'checkbox':
case 'file':
case 'hidden':
if ((typeof(elements[i].disabled) == 'undefined') || ((typeof(elements[i].disabled) != 'undefined') && (elements[i].disabled == false))) return false;
break;
}
break;
case 'select':
case 'textarea':
if ((typeof(elements[i].disabled) == 'undefined') || ((typeof(elements[i].disabled) != 'undefined') && (elements[i].disabled == false))) return false;
break;
}
}
return true;
},
submitForm: function(formName){
if (formName) {
var jForm = jQuery(document.forms[formName]);
if ((typeof(jForm.attr('data-submitted')) != 'undefined') && (jForm.attr('data-submitted') == 'true')) return false;
jForm.attr('data-submitted','true');
//save data from RichText Edirors
if (typeof(jQuery().tinymce()) != 'undefined') {
for(var i=0;i0) {
jQuery('#'+id).hide().fadeIn(500, function(){
if (jQuery(this).hasClass('fade-ok') || jQuery(this).hasClass('ok')) {
var obj = this;
setTimeout(function(){jQuery(obj).fadeOut("slow");}, 4000);
}
});
}
},
addTimeLabelInUrl: function(url){
var currentDate = new Date();
var timeLabel = currentDate.getFullYear() + '' + (currentDate.getMonth() + 1) + currentDate.getDate() + currentDate.getHours() + currentDate.getMinutes() + currentDate.getSeconds() + currentDate.getMilliseconds() ;
var items = url.split('#');
if (items[0].indexOf('?') != -1) items[0] = items[0] + '&' + 'tl=' + timeLabel; else items[0] = items[0] + '?' + 'tl=' + timeLabel;
if (items[1] != null) url = items[0] + '#' +items[1]; else url = items[0];
return url;
},
getDialogWindowMarkup: function(label, buttons, width) {
return string.replacePlaceHolders(this.markup.dialogWindow, {
width: width,
label: label,
buttons: buttons
});
},
showUndoDialog: function(url){
url = this.addTimeLabelInUrl(url);
var width = '445px';
var buttons = string.replacePlaceHolders(this.markup.dialogWindowButtons, {
buttonAbort: this.label.buttonAbort,
buttonOk: this.label.buttonRejectUpdates,
url: url
});
var html = this.getDialogWindowMarkup(this.label.areYouSure, buttons, width);
lightwindow.show(html);
},
showAbortDialog: function(url){
url = this.addTimeLabelInUrl(url);
var width = '445px';
var buttons = string.replacePlaceHolders(this.markup.dialogWindowButtons, {
buttonAbort: this.label.buttonNo,
buttonOk: this.label.buttonYes,
url: url
});
var html = this.getDialogWindowMarkup(this.label.areYouSure, buttons, width);
lightwindow.show(html);
},
showDialog: function(url,dialogMessage){
url = this.addTimeLabelInUrl(url);
var width = '445px';
var buttons = string.replacePlaceHolders(this.markup.dialogWindowButtonsWithLoader, {
buttonAbort: this.label.buttonNo,
buttonOk: this.label.buttonYes,
url: url
});
var html = this.getDialogWindowMarkup(dialogMessage, buttons, width);
lightwindow.show(html);
},
getAnchorFromURL: function(){
var value = window.location.hash;
if ((value.indexOf('#') != -1) && (value.length > 1)) value = value.substring(1, value.length);
else value = '';
return value;
},
submitFormByFieldValue: function(objSubmitField, selectorField){
var jParent = jQuery(objSubmitField).parent('form');
var fieldValue = jParent.find(selectorField).attr('value');
var pattern = /^\w+$/;
if (pattern.test(fieldValue)) {
location.href = jParent.attr('action') + '/' + fieldValue;
return false;
} else return false;
},
setLabels: function(labels){
this.labels = jQuery.extend(this.label,labels);
},
setCheckboxesRelation: function(masterItemSelector, slaveItemSelector, slaveLabelSelector){
//init
toggleState = function(){
if (jQuery(masterItemSelector).get(0).checked) {
jQuery(slaveItemSelector).removeAttr('disabled');
jQuery(slaveLabelSelector).removeClass('disabled');
} else {
jQuery(slaveItemSelector).attr('disabled','disabled');
jQuery(slaveItemSelector).get(0).checked = false;
jQuery(slaveLabelSelector).addClass('disabled');
}
}
toggleState();
//Event
jQuery(masterItemSelector).bind('click',toggleState);
},
initLoader: function(){
var self = this;
jQuery('a').each(function(){
if (!jQuery(this).attr('href')) return;
if ((jQuery(this).attr('href').indexOf('javascript') != -1) || (jQuery(this).attr('href').indexOf('#') == 0) || (jQuery(this).attr('href').indexOf('mailto') == 0) || ((jQuery(this).attr('target') != null) && (jQuery(this).attr('target').indexOf('_blank') == 0))) return;
//a-Tag - href-Normalisierung
var aHref = jQuery(this).attr('href');
var urlPort = (window.location.port != '') ? ':' + window.location.port : '' ;
if ((aHref.slice(0,7) != 'http://') || (aHref.slice(0,8) != 'https://')) {
if (aHref.slice(0,1) == '/') {
aHref = window.location.protocol+'//'+window.location.hostname+urlPort+aHref;
} else {
var pathNameArray = window.location.pathname.split('/');
var pathName = '';
for(var i=0; i<(pathNameArray.length-1); i++){
if (pathNameArray[i] != '') pathName += '/'+pathNameArray[i];
}
aHref = window.location.protocol+'//'+window.location.hostname+urlPort+pathName+'/'+aHref;
}
}
var temp = aHref.split('#');
aHref = temp[0];
var aHrefAnchor = (temp[1] != 'undefined') ? temp[1] : null ;
temp = window.location.href.split('#');
var locationHref = temp[0];
var changeTab = false; var tabName = '';
if ((aHref == locationHref) && (aHrefAnchor != null)) {
changeTab = true;
tabName = aHrefAnchor;
}
jQuery(this).bind('click', function(){
if (changeTab) tabBox.activateTabByName(tabName);
else self.showLoader();
});
});
},
showLoader: function(interval){
var self = this;
interval = typeof(interval) == 'undefined' ? 1000 : interval;
var showLoader = function(){
var loader = $('#communicationLoader');
loader = (loader.length==0) ? $(self.markup.ajaxLoader).appendTo('body') : loader;
loader.height($(document).height());
loader.show();
loader.find('>div').css('padding-top', ($(window).height()/2-150) + 'px');
}
if (interval > 0) {
window.setTimeout(function(){
showLoader();
}, interval);
} else showLoader();
},
removeLoader: function() {
$('#communicationLoader').hide();
},
copyToClipboard: function(txt) {
if (!txt) return;
if (window.clipboardData) {
window.clipboardData.clearData();
window.clipboardData.setData("Text", txt);
} else if (window.netscape) {
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
} catch (e) {
alert("In order to use this function, please enable 'signed.applets.codebase_principal_support' in about:config'.");
return false;
}
var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
if (!str) return false;
str.data = txt;
var trans = Components.classes["@mozilla.org/widget/transferable;1"].createInstance(Components.interfaces.nsITransferable);
if (!trans) return;
trans.addDataFlavor('text/unicode');
trans.setTransferData("text/unicode", str, txt.length * 2);
var clipid = Components.interfaces.nsIClipboard;
var clip = Components.classes["@mozilla.org/widget/clipboard;1"].getService(clipid);
if (!clip) return false;
clip.setData(trans,null,clipid.kGlobalClipboard);
} else if (navigator.appVersion.indexOf('Chrome') != -1) {
alert('The functionality is not supported by chrome.');
}
},
showExternalContent: function(parameters){ //[url, contentId, type, callback]
var p = {
url: null,
contentId: null,
type: 'xml',
callback: null
};
p = jQuery.extend(p, parameters);
var self = this;
this.showLoader(0);
var wrapper = document.createElement("div");
var pageSize = lightwindow.getPageSize();
var html = string.replacePlaceHolders(self.markup.externalContentWindow, {
contentId: p.contentId,
type: p.type,
url: p.url,
width: Math.round(pageSize[2]*0.8)+'px',
height: Math.round(pageSize[3]*0.7)+'px',
buttons: (((navigator.appVersion.indexOf('MSIE') != -1) || (navigator.appVersion.indexOf('Mozilla') != -1)) ? 'Copy to clipboard' : '')+'Close'
});
jQuery(wrapper).addClass('wrapper').append(html);
this.getExternalContent(p.url, function(data, textStatus){
if (textStatus != 'success') return;
jQuery(wrapper).find('.copyToClipboard').bind('click', function(){
self.copyToClipboard(data);
});
var previewHtml = data;
previewHtml = previewHtml.replace(//g, ">");
if (navigator.appVersion.indexOf('MSIE') != -1) jQuery(wrapper).find('[rel="externalContent"]').get(0).innerText = data;
else jQuery(wrapper).find('[rel="externalContent"]').get(0).innerHTML = previewHtml;
window.setTimeout(function(){
lightwindow.clear();
lightwindow.show(wrapper);
syntaxHighlighter.init();
if (typeof(p.callback) == 'function') p.callback.apply();
}, 50);
});
},
getExternalContent: function(url, callback){
jQuery.get(url,{},callback,'text');
},
preloadImages: function(images){
for (var i=0; iSelected options