573 lines
22 KiB
JavaScript
573 lines
22 KiB
JavaScript
/*
|
|
* Cms blank JavaScript Library v1.0
|
|
*/
|
|
(function() {
|
|
CBlank = (function() {
|
|
|
|
function CBlank(id, oTable){
|
|
CBase.oForm = this;
|
|
|
|
this.url = window.location;
|
|
this.jqBlank = $(($.isDefined(id) ? "#" + (this.id = id) + " " : "") + ".doc");
|
|
this.oTable = oTable;
|
|
}
|
|
|
|
CBlank.prototype.url = "";
|
|
CBlank.prototype.jqBlank = {};
|
|
CBlank.prototype.oBtnPan = {};
|
|
CBlank.prototype.validator = false;
|
|
CBlank.prototype.isVisible = false;
|
|
CBlank.prototype.disableShow = false;
|
|
|
|
CBlank.prototype.isModiffied = false;
|
|
CBlank.prototype.reloadOnSave = false;
|
|
|
|
CBlank.prototype.sData = {}; // Save data array
|
|
CBlank.prototype.lData = {}; // Loaded ajax data array
|
|
|
|
CBlank.prototype.oMessage = false;
|
|
|
|
// Load blank data via Ajax
|
|
CBlank.prototype.loadBlankView = function(){
|
|
var _this = this;
|
|
CBase.ajax(this.getAjaxData(), this.url, function(d){
|
|
if(d && d.html){
|
|
_this.lData = d;
|
|
_this.isVisible = true;
|
|
_this.isModiffied = false;
|
|
var obj = $(d.html);
|
|
|
|
_this.populateButtons(d);
|
|
_this.showBlankObjects(d);
|
|
_this.viewCallback(obj, d);
|
|
}
|
|
});
|
|
|
|
// Position save header top
|
|
$(".save-status a").click(function(){
|
|
_this.oMessage.hide();
|
|
});
|
|
};
|
|
// Ajax load cfg object
|
|
CBlank.prototype.getAjaxData = function(){
|
|
return {
|
|
action : "selfLoad"
|
|
}
|
|
};
|
|
// Ajax load populate blank buttons - if needed then to rewrite
|
|
CBlank.prototype.populateButtons = function(d){
|
|
var _this = this;
|
|
// Add button to form for back
|
|
if($.isDefined(d.btn)){
|
|
d.btn = $.extend(d.btn, { tback : {
|
|
id : "tback",
|
|
liclass : "fleft",
|
|
lbl : ($.isDefined(CBase.dt.back)?CBase.dt.back:"Back"),
|
|
click : function(){
|
|
_this.oMessage.hide();
|
|
if(_this.isModiffied)
|
|
_this.oTable.filterTableData(true);
|
|
else
|
|
_this.oTable.show();
|
|
}
|
|
}});
|
|
}
|
|
_this.populateButtonsConstruct(d);
|
|
};
|
|
// Ajax load populate blank buttons
|
|
CBlank.prototype.populateButtonsConstruct = function(d){
|
|
|
|
this.oBtnPan = $(".cnt-shadow .btn > ul");
|
|
this.oBtnPan.html("");
|
|
|
|
this.appendButtons(d);
|
|
};
|
|
// Append form action button
|
|
CBlank.prototype.appendButtons = function(d){
|
|
if($.isDefined(d.btn)){
|
|
var i, oLi;
|
|
for(i in d.btn){
|
|
if($.isDefined(d.btn[i].lbl) && $.isDefined(d.btn[i].id)){
|
|
oLi = $("<li class='" + ($.isDefined(d.btn[i].liclass)?d.btn[i].liclass:"") + "'><a " + ($.isDefined(d.btn[i].b)?"target='_blank'":"") + " href='" + ($.isDefined(d.btn[i].href)?d.btn[i].href:"javascript:;") + "' id='" + d.btn[i].id + "' class='sbtn" + ($.isDefined(d.btn[i].class)?" " + d.btn[i].class:"") + "'><span>" + d.btn[i].lbl + "</span></a></li>");
|
|
if($.isDefined(d.btn[i].click)){
|
|
oLi.find("> a").click(function(){
|
|
d.btn[i].click();
|
|
});
|
|
}
|
|
this.oBtnPan.append(oLi);
|
|
}
|
|
}
|
|
this.oBtnPan.append('<li class="clear" style="display: block;"></li>');
|
|
}
|
|
};
|
|
// Ajax load view call back - if needed then to rewrite
|
|
CBlank.prototype.viewCallback = function(obj){
|
|
this.bindBlankActions(obj);
|
|
};
|
|
// Ajax load view call back on object append - if needed then to rewrite
|
|
CBlank.prototype.viewCallbackAfterAppend = function(obj, d){};
|
|
// Ajax load view call back on object append - if needed then to rewrite
|
|
CBlank.prototype.viewCallbackAfterShow = function(obj, d){};
|
|
// Ajax base call back - if rewritten things wont work
|
|
CBlank.prototype.bindBlankActions = function(obj){
|
|
var _this = this;
|
|
|
|
// Bind Data events
|
|
obj = _this.jqBlank.hide().find(".form-data").show().html("").append(obj);
|
|
if($.isObject(_this.oTable))
|
|
_this.oTable.hide();
|
|
// Set message class
|
|
_this.oMessage = new FormMsg();
|
|
|
|
_this.viewCallbackAfterAppend(obj, _this.lData);
|
|
delete(_this.lData);
|
|
|
|
// Bind custom events
|
|
obj.find("ul.col1, ul.col2, ul.col3, ul.col4, ul.colX, ul.pblocks").find("> li").each(function(){
|
|
var jqLi = $(this);
|
|
jqLi.bind({
|
|
mouseover : function(){
|
|
jqLi.addClass("lih");
|
|
},
|
|
mouseout : function(){
|
|
jqLi.removeClass("lih");
|
|
}
|
|
}).find("input,textarea").bind({
|
|
focus : function(){
|
|
jqLi.addClass("lia");
|
|
},
|
|
blur : function(){
|
|
jqLi.removeClass("lia");
|
|
}
|
|
});
|
|
|
|
});
|
|
|
|
// Bind validator
|
|
// ---------------------------------------------------------
|
|
if(typeof Validator === 'function' && $.isDefined(CBase.dt.vcfg)){
|
|
_this.validator = new Validator(CBase.dt.vcfg, ".doc .form-data", CBase.gM);
|
|
}
|
|
|
|
// Bind submit on Enter
|
|
/*$(".form-data").find("input, textarea, select").keyup(function(event) {
|
|
if (event.which == 13) {
|
|
_this.saveBlankView();
|
|
}
|
|
});*/
|
|
|
|
// Bind Chosen controllers if plugin exists
|
|
// ---------------------------------------------------------
|
|
if($.fn.chosen){
|
|
_this.chosenCreateDummyForMobile(obj.find("select.chz:not(.search)").chosen({
|
|
width : "100%",
|
|
disable_search : true
|
|
}));
|
|
_this.chosenCreateDummyForMobile(obj.find("select.chz.search").chosen({
|
|
width : "100%"
|
|
}));
|
|
}
|
|
|
|
// Bind multi-select controller
|
|
// ---------------------------------------------------------
|
|
var jqMultiBoxes = obj.find(".selector");
|
|
if(jqMultiBoxes.length){
|
|
if(typeof SelMultiBox === 'function'){
|
|
jqMultiBoxes.each(function(){
|
|
new SelMultiBox(this);
|
|
});
|
|
}else pr("Error : selMultiBox class not loaded...");
|
|
}
|
|
|
|
// Bind checkboxes
|
|
CBase.checkboxes.bindSliderCheckboxes(obj);
|
|
CBase.checkboxes.bindBaseCheckboxes(obj);
|
|
|
|
|
|
// Move header title if top buttons set to visible
|
|
// ---------------------------------------------------------
|
|
var btnTitle = _this.jqBlank.find(".buttons_top.objShown");
|
|
if(btnTitle.length){
|
|
obj.find("h2.title").hide();
|
|
btnTitle.find(".title h2").html(obj.find("h2.title").html()).parent().show();
|
|
}
|
|
|
|
var jqReqT = $("a.req_time");
|
|
if(jqReqT.length && time.length)
|
|
jqReqT.html(time);
|
|
|
|
// Hide content & append to fade in
|
|
_this.show();
|
|
|
|
// Do resizing
|
|
// CBase.resizeForm();
|
|
|
|
_this.viewCallbackAfterShow(obj, _this.lData);
|
|
};
|
|
// Save blank data via Ajax
|
|
CBlank.prototype.saveBlankView = function(oAddData, fCallback){
|
|
var _this = this;
|
|
_this.oMessage.hide();
|
|
oAddData = defaultVal(oAddData, {});
|
|
fCallback = defaultVal(fCallback, false);
|
|
|
|
// Check if save button available
|
|
if(_this.jqBlank.find(".buttons_bottom #fsave").length){
|
|
// Remove input focus
|
|
var eMsg = _this.jqBlank.find(":focus").closest(".v-error");
|
|
if(eMsg.length){
|
|
eMsg.attr("original-title", "");
|
|
//eMsg.tipsy("hide");
|
|
}
|
|
_this.jqBlank.find(":focus").blur();
|
|
|
|
|
|
// Validate & save
|
|
if($.isDefined(this.validator) && this.validator.isFormValid()){
|
|
CBase.ajax(this.getSAjaxData(oAddData), this.url, function(d){
|
|
if($.isDefined(d.jsonok)){
|
|
_this.isModiffied = true;
|
|
// Add new id if got
|
|
if($.isDefined(d.newid))
|
|
$(".form-data input#id").val(d.newid);
|
|
if(_this.reloadOnSave){
|
|
_this.loadBlankView();
|
|
}
|
|
|
|
_this.oMessage.hideChecks = true;
|
|
_this.oMessage.show();
|
|
}else if($.isDefined(d.error)){
|
|
if($.isDefined(d.data)){
|
|
_this.validator.showErrorsByObject(d.data);
|
|
}
|
|
_this.oMessage.show(true, false, (d.msg ? d.msg : false));
|
|
}
|
|
_this.saveBlankViewCallback(d);
|
|
if($.isFunction(fCallback))
|
|
fCallback(d);
|
|
});
|
|
}else{
|
|
_this.saveBlankErrorCallback();
|
|
}
|
|
}
|
|
};
|
|
// Save blank data callback function
|
|
CBlank.prototype.saveBlankViewCallback = function(d){
|
|
|
|
};
|
|
// Save error callback function
|
|
CBlank.prototype.saveBlankErrorCallback = function(d){
|
|
|
|
};
|
|
|
|
// Get Ajax save cfg object
|
|
CBlank.prototype.getSAjaxData = function(oAddData){
|
|
var obj = {
|
|
action : "selfSave",
|
|
fields : toBase64encode($.toJSON(this.gatherSaveData()))
|
|
};
|
|
var jqId = $(".form-data input#id");
|
|
if(jqId.length){
|
|
$.extend(obj, {id : jqId.val()});
|
|
}
|
|
// Extend additional data
|
|
$.extend(obj,oAddData);
|
|
|
|
return obj;
|
|
};
|
|
// Get Ajax save cfg object
|
|
CBlank.prototype.gatherSaveData = function(){
|
|
this.sData = {};
|
|
|
|
this.gatherGbox();
|
|
this.gatherSbox();
|
|
|
|
var data = this.sData;
|
|
$.extend(data, this.addAdditionalSaveData());
|
|
this.sData = {};
|
|
if(CBase.debug) pr(data);
|
|
return data;
|
|
};
|
|
CBlank.prototype.addAdditionalSaveData = function(){
|
|
return {};
|
|
};
|
|
// Show blank data object
|
|
CBlank.prototype.gatherGbox = function(){
|
|
var id, _this = this;
|
|
$(".gbox").each(function(){
|
|
if(id = $(this).attr("id")){
|
|
if($.isDefined(_this.sData[id])){
|
|
_this.sData[id] = _this.gatherSbox(this, true, _this.sData[id]);
|
|
}else{
|
|
_this.sData[id] = _this.gatherSbox(this, true);
|
|
}
|
|
}
|
|
});
|
|
return true;
|
|
};
|
|
// Show blank data object
|
|
CBlank.prototype.gatherSbox = function(obj, ret, data){
|
|
|
|
var id, gbox = true, _this = this;
|
|
ret = $.isDefined(ret)?ret:false;
|
|
data = $.isDefined(data)?data:{};
|
|
|
|
if(!$.isDefined(obj)){
|
|
gbox = false;
|
|
obj = ".cnt";
|
|
}
|
|
|
|
$(obj).find(".sbox").each(function(){
|
|
if(!gbox && $(this).closest(".gbox").length){
|
|
}else{
|
|
if(id = $(this).attr("id")){
|
|
if(ret){
|
|
if($.isDefined(data[id])){
|
|
data[id] = $.extend(data[id], CBase.getFields($(this)));
|
|
}else{
|
|
data[id] = CBase.getFields($(this));
|
|
}
|
|
}else{
|
|
if($.isDefined(_this.sData[id])){
|
|
_this.sData[id] = $.extend(_this.sData[id], CBase.getFields($(this)));
|
|
}else{
|
|
_this.sData[id] = CBase.getFields($(this));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
if(ret)
|
|
return data;
|
|
return true;
|
|
};
|
|
// Show blank data object
|
|
CBlank.prototype.showBlankObjects = function(d){
|
|
if($.isDefined(d.show)){
|
|
var s = "";
|
|
for(var i in d.show){
|
|
if(d.show[i])
|
|
s += ", ." + i;
|
|
}
|
|
$(s.substring(1)).addClass("objShown").show();
|
|
}
|
|
};
|
|
CBlank.prototype.hide = function(){
|
|
this.isVisible = false;
|
|
this.jqBlank.parent().addClass("cnt-shadow-hidden").hide();
|
|
this.jqBlank.hide();
|
|
};
|
|
CBlank.prototype.show = function(){
|
|
if(!this.disableShow){
|
|
this.isVisible = true;
|
|
|
|
|
|
if(this.jqBlank.parent().is(":visible")){
|
|
this.jqBlank.show();
|
|
}else{
|
|
this.jqBlank.show();
|
|
}
|
|
|
|
this.jqBlank.parent().removeClass("cnt-shadow-hidden").fadeIn();
|
|
}
|
|
};
|
|
// Function to load subContent
|
|
CBlank.prototype.loadBlankBlockSubContent = function(jqObj, fnCallback){
|
|
var _this = this;
|
|
if(jqObj.hasClass("load")){
|
|
var data = {
|
|
action : jqObj.attr("id")
|
|
};
|
|
// Check for hidden fields to add
|
|
jqObj.find("input:hidden").each(function(){
|
|
if($(this).attr("id"))
|
|
data[$(this).attr("id")] = $(this).val();
|
|
});
|
|
CBase.ajax(data, _this.url, function(d){
|
|
jqObj.removeClass("load");
|
|
if(d && $.isDefined(d.html)){
|
|
|
|
// Append data
|
|
jqObj.find(".dd-before").before($(d.html));
|
|
|
|
// Set variable to higher nesting place
|
|
// ---------------------------------------------------------
|
|
var jqHtml = jqObj.find(".dd-before").parent();
|
|
|
|
CBase.checkboxes.bindBaseCheckboxes(jqHtml);
|
|
_this.bindSearch(jqHtml);
|
|
|
|
// Bind multi-select controller
|
|
// ---------------------------------------------------------
|
|
var jqMultiBoxes = jqHtml.find(".selector");
|
|
if(jqMultiBoxes.length){
|
|
if(typeof SelMultiBox === 'function'){
|
|
jqMultiBoxes.each(function(){
|
|
new SelMultiBox(this);
|
|
});
|
|
}else pr("Error : selMultiBox class not loaded...");
|
|
}
|
|
|
|
// Bind Validator to loaded container
|
|
// ---------------------------------------------------------
|
|
if(typeof Validator === 'function' && $.isDefined(CBase.dt.vcfg) && _this.validator)
|
|
_this.validator.bindSubs(jqHtml);
|
|
else pr("Error : Validator class not loaded...");
|
|
|
|
|
|
// Call callback function
|
|
if($.isFunction(fnCallback))
|
|
fnCallback(jqHtml, d)
|
|
}
|
|
_this.showHideSubContentPanel(jqObj);
|
|
});
|
|
}else{
|
|
_this.showHideSubContentPanel(jqObj);
|
|
}
|
|
};
|
|
// Function to show/hide subContent
|
|
CBlank.prototype.showHideSubContentPanel = function(jqObj, bShow){
|
|
var oCnt = jqObj.find("> div");
|
|
var noSkip = jqObj.hasClass("noskip") ? true : false;
|
|
|
|
var hide = oCnt.is(":visible");
|
|
if($.isDefined(bShow))
|
|
hide = !bShow;
|
|
|
|
if(hide){
|
|
jqObj.addClass("show").removeClass("hide");
|
|
oCnt.stop(true, true).fadeOut("fast", function(){
|
|
if(!noSkip) oCnt.find("input, textarea").addClass("skip");
|
|
});
|
|
}else{
|
|
jqObj.addClass("hide").removeClass("show");
|
|
oCnt.stop(true, true).fadeIn("fast", function(){
|
|
oCnt.find("input, textarea").removeClass("skip");
|
|
});
|
|
}
|
|
};
|
|
CBlank.prototype.bindSearch = function(jqObj){
|
|
var _this = this;
|
|
jqObj.find(".pp-search").each(function(){
|
|
var _pps = $(this), jqDiv = _pps.next();
|
|
var _cls = _pps.find("a.clf");
|
|
_pps.click(function(){
|
|
if(!_pps.hasClass("open")){
|
|
_pps.toggleClass("open");
|
|
_pps.find("input:text").focus();
|
|
}
|
|
});
|
|
_pps.find(".pp-close").click(function(e){
|
|
e.stopImmediatePropagation();
|
|
_pps.toggleClass("open");
|
|
if(!_pps.hasClass("open")){
|
|
_pps.find("input:text").val("").keyup();
|
|
_cls.hide();
|
|
}
|
|
});
|
|
_pps.find("input:text").keyup(function(event){
|
|
_this.filterPPSearch($(this), event.which == 27, jqDiv);
|
|
}).change(function(){
|
|
if($(this).val() && !_cls.is(":visible")){
|
|
_cls.fadeIn("fast");
|
|
}else if(!$(this).val() && _cls.is(":visible")){
|
|
_cls.fadeOut("fast");
|
|
}
|
|
});
|
|
_cls.bind({
|
|
click : function(){
|
|
_pps.find("input:text").val("").keyup();
|
|
}
|
|
});
|
|
|
|
/* CHK ALL NEXT TO SEARCH */
|
|
_pps.parent().find(".ckh_all").find(".chk").click(function(e){
|
|
e.stopImmediatePropagation();
|
|
var jqChkAll = $(this);
|
|
|
|
jqChkAll.toggleClass("chkedall");
|
|
if(jqChkAll.hasClass("chkedall")){
|
|
jqChkAll.addClass("chked").closest(".sbox").find(".ncheckbox .chk:not(.no-sbox-sel)").not(jqChkAll).addClass("chked");
|
|
}else{
|
|
jqChkAll.removeClass("chked").closest(".sbox").find(".ncheckbox .chk:not(.no-sbox-sel)").not(jqChkAll).removeClass("chked");
|
|
}
|
|
});
|
|
|
|
/* SHOW ONLY SELECTED ITEMS */
|
|
_pps.parent().find(".only_sel .chk").click(function(e){
|
|
e.stopImmediatePropagation();
|
|
$(this).toggleClass("chked");
|
|
_this.filterPPSearch(_pps.find("input:text"), false, jqDiv);
|
|
});
|
|
|
|
});
|
|
};
|
|
// Private function for pp search fields
|
|
CBlank.prototype.filterPPSearch = function(jqObj, bEscKey, jqDiv){
|
|
if(bEscKey){
|
|
jqDiv.find("li.noresults").hide();
|
|
jqDiv.find("li:not(.noresults)").fadeIn("fast");
|
|
jqObj.val("").change();
|
|
return false;
|
|
}
|
|
|
|
var matches, filter = jqObj.val();
|
|
var bShowSel = jqDiv.find(".only_sel .chk.chked").length;
|
|
if(filter) {
|
|
// Check if jQuery expressions enabled
|
|
if(!$.expr[":"].IContains){
|
|
pr("Error : Jquery expressions IContains not loaded...");
|
|
return false;
|
|
}
|
|
matches = jqDiv.find('label:IContains(' + filter + ')').closest("li");
|
|
if(bShowSel){
|
|
matches = matches.find(".chked").parent();
|
|
}
|
|
$('li', jqDiv).not(".dummy").not(matches).fadeOut("fast");
|
|
matches.fadeIn("fast");
|
|
} else {
|
|
matches = jqDiv.find("li:not(.noresults)");
|
|
if(bShowSel){
|
|
jqDiv.find("li:not(.dummy)").hide();
|
|
matches = matches.find(".chked").parent();
|
|
}
|
|
matches.fadeIn("fast");
|
|
}
|
|
|
|
// Check if any node visible
|
|
if(!matches.length){
|
|
jqDiv.find("li.noresults").fadeIn("fast");
|
|
}else{
|
|
jqDiv.find("li.noresults").hide();
|
|
}
|
|
|
|
jqObj.change();
|
|
};
|
|
// Create dummy container for chosen on mobile devices
|
|
CBlank.prototype.chosenCreateDummyForMobile = function(jqObj){
|
|
/*if(ekoKue.browser.mobile){
|
|
jqObj.each(function(){
|
|
var jqSelect = $(this);
|
|
var o, sId = jqSelect.attr("id");
|
|
// If chosen disabled create dummy controls
|
|
if(!jqSelect.parent().find("#" + sId + "_chosen").length){
|
|
jqSelect.addClass("m-workaround").before(o = $('<div class="chosen-container chosen-container-single chosen-container-single-nosearch" title="" id="user_lang_chosen"><a tabindex="-1" class="chosen-single"><span></span><div><b></b></div></a></div>'));
|
|
o.find("span").html(jqSelect.find("option:selected").html());
|
|
jqSelect.bind({
|
|
change : function(){
|
|
o.find("span").html(jqSelect.find("option:selected").html());
|
|
}
|
|
});
|
|
}
|
|
});
|
|
}else{
|
|
jqObj.each(function(){
|
|
$(this).next().append("<div class='bottom-border'></div>");
|
|
});
|
|
}*/
|
|
};
|
|
return CBlank;
|
|
|
|
})();
|
|
}).call(this);
|