<\/div>/g, ""); /* remove empty div.row */
apiGridster.updateSerializInDB(id, ["serialize", "html_generated"], [val, generatedBsgridster], val);
};
},
updateSerializInDB: function(id, name, value, seriali) {
var tmpValueSerialise = seriali;
if(id.length > 0 && name.length > 0 && value.length > 0){
jQuery.ajax({
url: "/in/rest/KUModelSVC/UpdateValue?_=" + (new Date()).getTime(),
data: { iid:id, name:name, value:value },
type: 'POST',
traditional: true,
success: function(status, a, b) {
if(status && status.StatusInformation && ( status.StatusInformation.code == "OK" || status.StatusInformation[0].code == "OK" )){
apiGridster.currentSerializeData = tmpValueSerialise;
alertify.success("Mise à jour de la grille, réussi!");
}else{
alertify.error("Mise à jour de la grille, erreur.01"); console.log("KUModelSVC error", status, a, b);
};
},
error: function(status, a, b) { alertify.error("Mise à jour de la grille, erreur.02"); console.log("KUModelSVC error", status, a, b); }
}); //end ajax
}; //end if length
},
openEditContent: function(id) {
dialogManager.open("Chargement en cours", "/in/faces/kueditmetadlg.xhtml?id="+ id +"", 900, 600, function(complete){});
},
openDeleteContent: function(id) {
dialogManager.open("Chargement en cours", "/in/faces/kuconfirmdeletedlg.xhtml?showDeleteOnly=true&id="+ id +"", 400, 300, function(complete){});
},
openAddContent: function(id, propertyType, contentType){
var duplicateOriginalContentFound = false;
$(apiGridster.lstDuplicateContents).each(function(i, j){
if( contentType == j.type ){
duplicateOriginalContentFound = true;
var duplicateOriginalContent = j;
return false;
};
});
if(duplicateOriginalContentFound){
//idContenu, propertyType, idDuplicateContent
//apiGridster.duplicateContent(apiGridster.idContenu, );
}else{
};
var contentWysiwyg = "0fd66c61-44b8-444d-be9d-25f4ce2172eb";
var contentCode = "7f1510b0-f8f9-4a18-8c9e-75607c4ee92f";
if(propertyType == "contents"){
dialogManager.open("Chargement en cours", apiGridster.kueditMeta_Contents, 900, 600, function(callback){ apiGridster.openAddContentComplete(callback, propertyType, id); });
}else if(propertyType == "contentscodes"){
dialogManager.open("Chargement en cours", apiGridster.kueditMeta_ContentsCodes, 900, 600, function(callback){ apiGridster.openAddContentComplete(callback, propertyType, id); });
}else if(propertyType == "widgets"){/* with domain */
dialogManager.open("Chargement en cours", apiGridster.kueditMeta_Widget, 900, 600, function(callback){ apiGridster.openAddContentComplete(callback, propertyType, id); });
}else if(propertyType == "widget"){
dialogManager.open("Chargement en cours", "/in/faces/kueditmetadlg.xhtml?id=new:"+id, 900, 600, function(callback){ apiGridster.openAddContentComplete(callback, "widgets", id); });
};
},
openAddContentComplete: function(callback, propertyType, pageId){
if(callback.action == "complete" && callback.iid != ""){
jQuery.ajax({
url: "/in/rest/KUModelSVC/UpdateValue?_=" + (new Date()).getTime(),
data: { iid:pageId, name:propertyType, value:callback.iid, relatedId:callback.iid, position:999},
type: 'POST',
success: function(status) {
if(status && status.StatusInformation && status.StatusInformation.code == "OK"){
alertify.success("Création réussi!");
setTimeout(function(){
window.location.href = document.location.pathname + "?id=" + pageId + "&adminDisplay=edit";
}, 2000);
}else{
alertify.error("Création de contenu, erreur.01");
};
},
error: function() { alertify.error("Création de contenu, erreur.02"); }
}); //end ajax
}; //end if length
},
duplicateContent: function(idContenu, propertyType, idDuplicateContent){
jQuery.ajax({
url: "/in/rest/KUModelSVC/duplicate?_=" + (new Date()).getTime(),
data: {"parentid":idContenu, "id":contentWysiwyg, "cleanupRelations":true},
type: 'GET',
success: function(status) {
var fromXML = $(status);
var GuidResponse = fromXML.find('GuidResponse');
var guid = GuidResponse.find('guid').html();
if(typeof GuidResponse !== "undefined" && typeof guid !== "undefined"){
alertify.success("Création en cours..");
var callback = {action:"complete", iid:guid};
apiGridster.openAddContentComplete(callback, propertyType, idContenu);
}else{
alertify.error("Création de contenu, erreur.01");
};
},
error: function(a, b, c) {
alertify.error("Création de contenu, erreur.02");
console.log("duplicateContent() error", a, b, c);
}
}); //end ajax
},
getDuplicateOriginalElements: function(){
apiGridster.lstDuplicateContents = [];
jQuery.ajax({
url: apiGridster.tree_Clone + "&fn=?&_=" + (new Date()).getTime(),
data: null,
type: 'GET',
success: function(status) {
$(status.children).each(function(i, j){
apiGridster.lstDuplicateContents.push({id:j.id, type:j.type});
});
console.log("getRdyDuplicateElements() success", status, apiGridster.lstDuplicateContents);
},
error: function(a, b, c) {
console.log("getRdyDuplicateElements() error", a, b, c);
}
}); //end ajax
},
showHideContent: function(id, element){
var dispLarge = $(element).parent().parent().attr("data-display"),
dispTablette = $(element).parent().parent().attr("data-display-sm"),
dispMobile = $(element).parent().parent().attr("data-display-xs");
$("#showHide_large, #showHide_tablette, #showHide_mobile").attr("data-id", id);
if(dispLarge == "visible"){ $("#showHide_large").css("opacity", "1.0"); }else{ $("#showHide_large").css("opacity", "0.35"); };
if(dispTablette == "visible"){ $("#showHide_tablette").css("opacity", "1.0"); }else{ $("#showHide_tablette").css("opacity", "0.35"); };
if(dispMobile == "visible"){ $("#showHide_mobile").css("opacity", "1.0"); }else{ $("#showHide_mobile").css("opacity", "0.35"); };
$("#showhideModal").modal();
},
removeDragMeIcon: function(element){
if( $(element).attr("data-new") == "true" ){ // element = li
$(element).attr("data-new", "false").find("div.dragMe").remove();
}else if( $(element).hasClass("gs-resize-handle") ){ // element = span resize corner
if( $(element).parent().attr("data-new") == "true" ){
$(element).parent().attr("data-new", "false").find("div.dragMe").remove();
};
};
}
};
// from : apiGridster.showHideContent()
$("img#showHide_large, img#showHide_tablette, img#showHide_mobile").live("click", function(){
var setValue = "visible";
if( $(this).css("opacity") == "1.0" || $(this).css("opacity") == "1" ){ $(this).css("opacity", "0.35"); setValue = "hidden"; }else{ $(this).css("opacity", "1.0"); };
$("div.gridster li[data-id='"+ $(this).attr("data-id") +"']").attr( $(this).attr("data-type"), setValue);
apiGridster.updateSerializeGrids(apiGridster.idContenu, JSON.stringify( apiGridster.gridster[0].serialize()) );
});
// generator HTML bootstrap from serialize
var bsgridster = function(gridsterBoxes, unitHeight) {
'use strict';
console.log("DEBUG bsgridster", gridsterBoxes, unitHeight);
var _colSize = "md";
if(typeof _ === 'undefined') {throw ""};
if (!unitHeight){unitHeight = 25;};
gridsterBoxes = _.sortBy(gridsterBoxes, function(box) { return box.col; });
function makeBox(width, height, offset, id, display, box) {
var realHeight = ((height - 1) * (apiGridster.gridSize[1] + (apiGridster.gridMargin[0] + apiGridster.gridMargin[1])) ) + apiGridster.gridSize[1];
var boxElem = document.createElement('div');
boxElem.className = "";
// md + lg
if(display == "visible"){ boxElem.className += " col-md-" + width.toString();}
else { boxElem.className += " hidden-md hidden-lg"; };
if(offset>0) { boxElem.className += " col-md-offset-" + offset.toString() + " col-lg-offset-" + offset.toString(); };
// sm
if(box.display_sm == "visible"){ boxElem.className += " col-sm-12";}
else { boxElem.className += " hidden-sm"; };
// xs
if(box.display_xs == "visible"){ boxElem.className += " col-xs-12";}
else { boxElem.className += " hidden-xs"; };
// others
boxElem.setAttribute("data-id", id);
boxElem.setAttribute("data-display", display);
boxElem.setAttribute("data-type", box.type);
boxElem.style.minHeight = (realHeight).toString() + 'px';
return boxElem;
}
function makeRow() {
var rowElem = document.createElement('div');
rowElem.className = "row col-"+_colSize+"-12";
return rowElem;
}
function html() {
var containerElem = document.createElement('div'),
rows = [],
groupedBoxes = _.groupBy(gridsterBoxes, function(box) {return box.row;}),
maxRow = (_.max(gridsterBoxes, function(box) { return box.row; })).row;
console.log("DEBUG 01", rows, groupedBoxes, maxRow);
_.times(maxRow, function(n) { rows.push({row: n, elem: makeRow()}); });
_.each(groupedBoxes, function (boxes, row) {
var rowElem = rows[row-1].elem;
_.each(boxes, function (box, index, boxesInRow) {
var immediateLeftBox = boxesInRow[index-1],
offset = 0;
if(immediateLeftBox) {
offset = box.col - (immediateLeftBox.col+immediateLeftBox.size_x);
} else {
offset = box.col-1;
};
var boxElem = makeBox(box.size_x, box.size_y, offset, box.id, box.display, box);
rowElem.appendChild(boxElem);
});
});
_.each(rows, function(row) { containerElem.appendChild(row.elem); });
return containerElem;
}
return {
getHtml: html
};
};
//from : adminDisplay=wysiwyg
function action_setEditorWYSIWYG(pageId, lang){
var selector = "#adminFormat div[data-type='contents'] > div.contents_tinyMCE[data-type='contents']";
tinymce.init({
selector: selector,
menubar: true,
statusbar: true,
inline: true,
theme: "modern",
image_advtab: true,
plugins: [
"advlist autolink lists link image charmap print preview hr anchor pagebreak",
"searchreplace wordcount visualblocks visualchars code fullscreen",
"insertdatetime media nonbreaking save table contextmenu directionality",
"emoticons template paste textcolor colorpicker textpattern"
],
toolbar1: "undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image",
toolbar2: "insertfile media | preview | forecolor backcolor | customSave",
removed_menuitems: 'newdocument',
init_instance_callback : function(editor) {
$( editor.targetElm ).parent().find("div.g_edit > .saveContentWYSIWYG").attr("data-tinymce", editor.id);
},
setup : function(ed) {
ed.on('click', function(e){}),
ed.on("change", function(e) {
$( ed.targetElm ).parent().find("div.g_edit > .saveContentWYSIWYG").removeClass("glyphicon-floppy-saved").addClass("glyphicon-floppy-remove").css("color", "#F00").css("opacity", "1.0");
}),
ed.addButton('customSave', {
title: (lang == 'fr') ? "Enregistrer" : 'Save',
text: (lang == 'fr') ? "Enregistrer" : 'Save',
onclick: function(e) {
action_saveContentWYSIWYG( $("#" + ed.id).parent().find("div.g_edit > .saveContentWYSIWYG") );
}
});
}
});
};
$("div.g_edit > .saveContentWYSIWYG").live("click", function(){ action_saveContentWYSIWYG( $(this) ); });
function action_saveContentWYSIWYG(element){
var contentID = $(element).parent().parent().attr("data-id"),
tinyMCEID = $(element).parent().prev().attr("id"),
tinyMCEHTML = tinyMCE.get(tinyMCEID).getContent(),
lang = $(element).attr("data-lang"),
paramName = "description";
if(lang != "fr"){ paramName = "description_" + lang; };
saveContentWYSIWYGValueInDB(contentID, paramName, tinyMCEHTML);
$(element).removeClass("glyphicon-floppy-remove").addClass("glyphicon-floppy-saved").css("color", "#0F0").css("opacity", "0.65");
};
function saveContentWYSIWYGValueInDB(id, name, value, lang) {
var tmpValue = value;
if(id.length > 0 && name.length > 0 && value.length > 0){
jQuery.ajax({
url: "/in/rest/KUModelSVC/UpdateValue?_=" + (new Date()).getTime(),
data: { iid: id, name: name, value: value },
type: 'POST',
success: function(status) {
if(status && status.StatusInformation && status.StatusInformation.code == "OK"){
apiGridster.currentSerializeData = tmpValue;
alertify.success("Mise à jour, réussi!");
}else{
alertify.error("Mise à jour, erreur.01");
};
},
error: function() { alertify.error("Mise à jour, erreur.02"); }
}); //end ajax
}; //end if length
};
function changeColorNewContent(){
if($("div.gridster ul li[data-new='true']").length > 0 ){
setTimeout(function(){
if($("div.gridster ul li[data-new='true']").hasClass("newRed")){
$("div.gridster ul li[data-new='true']").addClass("newGreen").removeClass("newRed");
}else{
$("div.gridster ul li[data-new='true']").removeClass("newGreen").addClass("newRed");
};
changeColorNewContent();
}, 450);
}else{
if($("div.gridster ul li.newRed, div.gridster ul li.newGreen").length > 0 ){
$("div.gridster ul li.newRed, div.gridster ul li.newGreen").removeClass("newRed").removeClass("newGreen");
};
};
};