2 * This file is part of the TYPO3 CMS project.
4 * It is free software; you can redistribute it and/or modify it under
5 * the terms of the GNU General Public License, either version 2
6 * of the License, or any later version.
8 * For the full copyright and license information, please read the
9 * LICENSE.txt file that was distributed with this source code.
11 * The TYPO3 project - inspiring people to share!
13 var __values
=this&&this.__values
||function(a
){var b
="function"==typeof Symbol
&&a
[Symbol
.iterator
],c
=0;return b
?b
.call(a
):{next:function(){return a
&&c
>=a
.length
&&(a
=void 0),{value
:a
&&a
[c
++],done
:!a
}}}};define(["require","exports","jquery","TYPO3/CMS/Backend/Modal","TYPO3/CMS/Backend/Severity","bootstrap"],function(a
,b
,c
,d
,e
){"use strict";Object
.defineProperty(b
,"__esModule",{value
:!0});var f=function(){function a(a
){void 0===a
&&(a
=null);var b
=this;this.colCount
=1,this.rowCount
=1,this.nameLabel
="name",this.columnLabel
="columen label",this.defaultCell
={spanned
:0,rowspan
:1,colspan
:1,name
:"",colpos
:"",column
:void 0},this.selectorEditor
=".t3js-grideditor",this.selectorAddColumn
=".t3js-grideditor-addcolumn",this.selectorRemoveColumn
=".t3js-grideditor-removecolumn",this.selectorAddRowTop
=".t3js-grideditor-addrow-top",this.selectorRemoveRowTop
=".t3js-grideditor-removerow-top",this.selectorAddRowBottom
=".t3js-grideditor-addrow-bottom",this.selectorRemoveRowBottom
=".t3js-grideditor-removerow-bottom",this.selectorLinkEditor
=".t3js-grideditor-link-editor",this.selectorLinkExpandRight
=".t3js-grideditor-link-expand-right",this.selectorLinkShrinkLeft
=".t3js-grideditor-link-shrink-left",this.selectorLinkExpandDown
=".t3js-grideditor-link-expand-down",this.selectorLinkShrinkUp
=".t3js-grideditor-link-shrink-up",this.selectorDocHeaderSave
=".t3js-grideditor-savedok",this.selectorDocHeaderSaveClose
=".t3js-grideditor-savedokclose",this.selectorConfigPreview
=".t3js-grideditor-preview-config",this.selectorConfigPreviewButton
=".t3js-grideditor-preview-button",this.modalButtonClickHandler=function(a
){var c
=a
.target
;"cancel"===c
.name
?d
.currentModal
.trigger("modal-dismiss"):"ok"===c
.name
&&(b
.setName(d
.currentModal
.find(".t3js-grideditor-field-name").val(),d
.currentModal
.data("col"),d
.currentModal
.data("row")),b
.setColumn(d
.currentModal
.find(".t3js-grideditor-field-colpos").val(),d
.currentModal
.data("col"),d
.currentModal
.data("row")),b
.drawTable(),b
.writeConfig(b
.export2LayoutRecord()),d
.currentModal
.trigger("modal-dismiss"))},this.addColumnHandler=function(a
){a
.preventDefault(),b
.addColumn(),b
.drawTable(),b
.writeConfig(b
.export2LayoutRecord())},this.removeColumnHandler=function(a
){a
.preventDefault(),b
.removeColumn(),b
.drawTable(),b
.writeConfig(b
.export2LayoutRecord())},this.addRowTopHandler=function(a
){a
.preventDefault(),b
.addRowTop(),b
.drawTable(),b
.writeConfig(b
.export2LayoutRecord())},this.addRowBottomHandler=function(a
){a
.preventDefault(),b
.addRowBottom(),b
.drawTable(),b
.writeConfig(b
.export2LayoutRecord())},this.removeRowTopHandler=function(a
){a
.preventDefault(),b
.removeRowTop(),b
.drawTable(),b
.writeConfig(b
.export2LayoutRecord())},this.removeRowBottomHandler=function(a
){a
.preventDefault(),b
.removeRowBottom(),b
.drawTable(),b
.writeConfig(b
.export2LayoutRecord())},this.linkEditorHandler=function(a
){a
.preventDefault();var d
=c(a
.target
);b
.showOptions(d
.data("col"),d
.data("row"))},this.linkExpandRightHandler=function(a
){a
.preventDefault();var d
=c(a
.target
);b
.addColspan(d
.data("col"),d
.data("row")),b
.drawTable(),b
.writeConfig(b
.export2LayoutRecord())},this.linkShrinkLeftHandler=function(a
){a
.preventDefault();var d
=c(a
.target
);b
.removeColspan(d
.data("col"),d
.data("row")),b
.drawTable(),b
.writeConfig(b
.export2LayoutRecord())},this.linkExpandDownHandler=function(a
){a
.preventDefault();var d
=c(a
.target
);b
.addRowspan(d
.data("col"),d
.data("row")),b
.drawTable(),b
.writeConfig(b
.export2LayoutRecord())},this.linkShrinkUpHandler=function(a
){a
.preventDefault();var d
=c(a
.target
);b
.removeRowspan(d
.data("col"),d
.data("row")),b
.drawTable(),b
.writeConfig(b
.export2LayoutRecord())},this.configPreviewButtonHandler=function(a
){a
.preventDefault();var d
=c(b
.selectorConfigPreview
),e
=c(b
.selectorConfigPreviewButton
);d
.is(":visible")?(e
.empty().append(TYPO3
.lang
["button.showPageTsConfig"]),c(b
.selectorConfigPreview
).slideUp()):(e
.empty().append(TYPO3
.lang
["button.hidePageTsConfig"]),c(b
.selectorConfigPreview
).slideDown())};var e
=c(this.selectorEditor
);this.colCount
=e
.data("colcount"),this.rowCount
=e
.data("rowcount"),this.field
=c('input[name="'+e
.data("field")+'"]'),this.data
=e
.data("data"),this.nameLabel
=null!==a
?a
.nameLabel
:"Name",this.columnLabel
=null!==a
?a
.columnLabel
:"Column",this.targetElement
=c(this.selectorEditor
),c(this.selectorConfigPreview
).hide(),c(this.selectorConfigPreviewButton
).empty().append(TYPO3
.lang
["button.showPageTsConfig"]),this.initializeEvents(),this.drawTable(),this.writeConfig(this.export2LayoutRecord())}return a
.stripMarkup=function(a
){return a
=a
.replace(/<(.*)>/gi,""),c("<p>"+a
+"</p>").text()},a
.prototype.initializeEvents=function(){c(document
).on("click",this.selectorAddColumn
,this.addColumnHandler
),c(document
).on("click",this.selectorRemoveColumn
,this.removeColumnHandler
),c(document
).on("click",this.selectorAddRowTop
,this.addRowTopHandler
),c(document
).on("click",this.selectorAddRowBottom
,this.addRowBottomHandler
),c(document
).on("click",this.selectorRemoveRowTop
,this.removeRowTopHandler
),c(document
).on("click",this.selectorRemoveRowBottom
,this.removeRowBottomHandler
),c(document
).on("click",this.selectorLinkEditor
,this.linkEditorHandler
),c(document
).on("click",this.selectorLinkExpandRight
,this.linkExpandRightHandler
),c(document
).on("click",this.selectorLinkShrinkLeft
,this.linkShrinkLeftHandler
),c(document
).on("click",this.selectorLinkExpandDown
,this.linkExpandDownHandler
),c(document
).on("click",this.selectorLinkShrinkUp
,this.linkShrinkUpHandler
),c(document
).on("click",this.selectorConfigPreviewButton
,this.configPreviewButtonHandler
)},a
.prototype.getNewCell=function(){return c
.extend({},this.defaultCell
)},a
.prototype.writeConfig=function(a
){this.field
.val(a
);var b
=a
.split("\n"),d
="";try{for(var e
=__values(b
),f
=e
.next();!f
.done
;f
=e
.next()){var g
=f
.value
;g
&&(d
+="\t\t\t"+g
+"\n")}}catch(a
){h
={error
:a
}}finally{try{f
&&!f
.done
&&(i
=e
.return)&&i
.call(e
)}finally{if(h
)throw h
.error
}}c(this.selectorConfigPreview
).find("code").empty().append("mod.web_layout.BackendLayouts {\n exampleKey {\n title = Example\n icon = EXT:example_extension/Resources/Public/Images/BackendLayouts/default.gif\n config {\n"+d
.replace(new RegExp("\t","g")," ")+" }\n }\n}\n");var h
,i
},a
.prototype.addRowTop=function(){for(var a
=[],b
=0;b
<this.colCount
;b
++){var c
=this.getNewCell();c
.name
=b
+"x"+this.data
.length
,a
[b
]=c
}this.data
.unshift(a
),this.rowCount
++},a
.prototype.addRowBottom=function(){for(var a
=[],b
=0;b
<this.colCount
;b
++){var c
=this.getNewCell();c
.name
=b
+"x"+this.data
.length
,a
[b
]=c
}this.data
.push(a
),this.rowCount
++},a
.prototype.removeRowTop=function(){if(this.rowCount
<=1)return!1;for(var a
=[],b
=1;b
<this.rowCount
;b
++)a
.push(this.data
[b
]);for(var c
=0;c
<this.colCount
;c
++)1===this.data
[0][c
].spanned
&&this.findUpperCellWidthRowspanAndDecreaseByOne(c
,0);return this.data
=a
,this.rowCount
--,!0},a
.prototype.removeRowBottom=function(){if(this.rowCount
<=1)return!1;for(var a
=[],b
=0;b
<this.rowCount
-1;b
++)a
.push(this.data
[b
]);for(var c
=0;c
<this.colCount
;c
++)1===this.data
[this.rowCount
-1][c
].spanned
&&this.findUpperCellWidthRowspanAndDecreaseByOne(c
,this.rowCount
-1);return this.data
=a
,this.rowCount
--,!0},a
.prototype.findUpperCellWidthRowspanAndDecreaseByOne=function(a
,b
){var c
=this.getCell(a
,b
-1);return!!c
&&(1===c
.spanned
?this.findUpperCellWidthRowspanAndDecreaseByOne(a
,b
-1):c
.rowspan
>1&&this.removeRowspan(a
,b
-1),!0)},a
.prototype.removeColumn=function(){if(this.colCount
<=1)return!1;for(var a
=[],b
=0;b
<this.rowCount
;b
++){for(var c
=[],d
=0;d
<this.colCount
-1;d
++)c
.push(this.data
[b
][d
]);1===this.data
[b
][this.colCount
-1].spanned
&&this.findLeftCellWidthColspanAndDecreaseByOne(this.colCount
-1,b
),a
.push(c
)}return this.data
=a
,this.colCount
--,!0},a
.prototype.findLeftCellWidthColspanAndDecreaseByOne=function(a
,b
){var c
=this.getCell(a
-1,b
);return!!c
&&(1===c
.spanned
?this.findLeftCellWidthColspanAndDecreaseByOne(a
-1,b
):c
.colspan
>1&&this.removeColspan(a
-1,b
),!0)},a
.prototype.addColumn=function(){for(var a
=0;a
<this.rowCount
;a
++){var b
=this.getNewCell();b
.name
=this.colCount
+"x"+a
,this.data
[a
].push(b
)}this.colCount
++},a
.prototype.drawTable=function(){for(var b
=c("<colgroup>"),d
=0;d
<this.colCount
;d
++){var e
=100/this.colCount;b.append(c("<col>").css({width:parseInt(e.toString(),10)+"%"}))}var f=c('<table id="base" class="table editor">');f.append(b);for(var g=0;g<this.rowCount;g++){var h=this.data[g];if(0!==h.length){for(var i=c("<tr>"),d=0;d<this.colCount;d++){var j=this.data[g][d];if(1!==j.spanned){var k=100/this.rowCount
,l
=100/this.colCount,m=c("<td>").css({height:parseInt(k.toString(),10)*j.rowspan+"%",width:parseInt(l.toString(),10)*j.colspan+"%"}),n=c('<div class="cell_container">');m.append(n);var o=c('<a href="#" data-col="'+d+'" data-row="'+g+'">');n.append(o.clone().attr("class","t3js-grideditor-link-editor link link_editor").attr("title",TYPO3.lang.grid_editCell)),this.cellCanSpanRight(d,g)&&n.append(o.clone().attr("class","t3js-grideditor-link-expand-right link link_expand_right").attr("title",TYPO3.lang.grid_mergeCell)),this.cellCanShrinkLeft(d,g)&&n.append(o.clone().attr("class","t3js-grideditor-link-shrink-left link link_shrink_left").attr("title",TYPO3.lang.grid_splitCell)),this.cellCanSpanDown(d,g)&&n.append(o.clone().attr("class","t3js-grideditor-link-expand-down link link_expand_down").attr("title",TYPO3.lang.grid_mergeCell)),this.cellCanShrinkUp(d,g)&&n.append(o.clone().attr("class","t3js-grideditor-link-shrink-up link link_shrink_up").attr("title",TYPO3.lang.grid_splitCell)),m.append(c('<div class="cell_data">').html(TYPO3.lang.grid_name+": "+(j.name?a.stripMarkup(j.name):TYPO3.lang.grid_notSet)+"<br />"+TYPO3.lang.grid_column+": "+("undefined"==typeof j.column||isNaN(j.column)?TYPO3.lang.grid_notSet:parseInt(j.column,10)))),j.colspan>1&&m.attr("colspan
",j.colspan),j.rowspan>1&&m.attr("rowspan
",j.rowspan),i.append(m)}}f.append(i)}}c(this.targetElement).empty().append(f)},a.prototype.setName=function(b,c,d){var e=this.getCell(c,d);return!!e&&(e.name=a.stripMarkup(b),!0)},a.prototype.setColumn=function(a,b,c){var d=this.getCell(b,c);return!!d&&(d.column=parseInt(a.toString(),10),!0)},a.prototype.showOptions=function(b,f){var g=this.getCell(b,f);if(!g)return!1;var h;h=0===g.column?0:g.column?parseInt(g.column.toString(),10):"";var i=c("<div
>"),j=c('<div class="form
-group
">'),k=c("<label
>"),l=c("<input
>");i.append([j.clone().append([k.clone().text(TYPO3.lang.grid_nameHelp),l.clone().attr("type
","text
").attr("class","t3js
-grideditor
-field
-name form
-control
").attr("name
","name
").val(a.stripMarkup(g.name)||"")]),j.clone().append([k.clone().text(TYPO3.lang.grid_columnHelp),l.clone().attr("type
","text
").attr("class","t3js
-grideditor
-field
-colpos form
-control
").attr("name
","column
").val(h)])]);var m=d.show(TYPO3.lang.grid_windowTitle,i,e.notice,[{active:!0,btnClass:"btn
-default",name:"cancel
",text:c(this).data("button
-close
-text
")||TYPO3.lang["button
.cancel
"]||"Cancel
"},{btnClass:"btn
-primary
",name:"ok
",text:c(this).data("button
-ok
-text
")||TYPO3.lang["button
.ok
"]||"OK
"}]);return m.data("col
",b),m.data("row
",f),m.on("button
.clicked
",this.modalButtonClickHandler),!0},a.prototype.getCell=function(a,b){return!(a>this.colCount-1)&&(!(b>this.rowCount-1)&&(this.data.length>b-1&&this.data[b].length>a-1?this.data[b][a]:null))},a.prototype.cellCanSpanRight=function(a,b){if(a===this.colCount-1)return!1;var c,d=this.getCell(a,b);if(d.rowspan>1){for(var e=b;e<b+d.rowspan;e++)if(c=this.getCell(a+d.colspan,e),!c||1===c.spanned||c.colspan>1||c.rowspan>1)return!1}else if(c=this.getCell(a+d.colspan,b),!c||1===d.spanned||1===c.spanned||c.colspan>1||c.rowspan>1)return!1;return!0},a.prototype.cellCanSpanDown=function(a,b){if(b===this.rowCount-1)return!1;var c,d=this.getCell(a,b);if(d.colspan>1){for(var e=a;e<a+d.colspan;e++)if(c=this.getCell(e,b+d.rowspan),!c||1===c.spanned||c.colspan>1||c.rowspan>1)return!1}else if(c=this.getCell(a,b+d.rowspan),!c||1===d.spanned||1===c.spanned||c.colspan>1||c.rowspan>1)return!1;return!0},a.prototype.cellCanShrinkLeft=function(a,b){return this.data[b][a].colspan>1},a.prototype.cellCanShrinkUp=function(a,b){return this.data[b][a].rowspan>1},a.prototype.addColspan=function(a,b){var c=this.getCell(a,b);if(!c||!this.cellCanSpanRight(a,b))return!1;for(var d=b;d<b+c.rowspan;d++)this.data[d][a+c.colspan].spanned=1;return c.colspan+=1,!0},a.prototype.addRowspan=function(a,b){var c=this.getCell(a,b);if(!c||!this.cellCanSpanDown(a,b))return!1;for(var d=a;d<a+c.colspan;d++)this.data[b+c.rowspan][d].spanned=1;return c.rowspan+=1,!0},a.prototype.removeColspan=function(a,b){var c=this.getCell(a,b);if(!c||!this.cellCanShrinkLeft(a,b))return!1;c.colspan-=1;for(var d=b;d<b+c.rowspan;d++)this.data[d][a+c.colspan].spanned=0;return!0},a.prototype.removeRowspan=function(a,b){var c=this.getCell(a,b);if(!c||!this.cellCanShrinkUp(a,b))return!1;c.rowspan-=1;for(var d=a;d<a+c.colspan;d++)this.data[b+c.rowspan][d].spanned=0;return!0},a.prototype.export2LayoutRecord=function(){for(var a="backend_layout
{\n\tcolCount = "+this.colCount+"\n\trowCount = "+this.rowCount+"\n\trows {\n",b=0;b<this.rowCount;b++){a+="\t\t"+(b+1)+" {\n",a+="\t\t\tcolumns {\n";for(var c=0,d=0;d<this.colCount;d++){var e=this.getCell(d,b);e&&(e.spanned||(c++,a+="\t\t\t\t"+c+" {\n",a+="\t\t\t\t\tname = "+(e.name?e.name:d+"x
"+b)+"\n",e.colspan>1&&(a+="\t\t\t\t\tcolspan = "+e.colspan+"\n"),e.rowspan>1&&(a+="\t\t\t\t\trowspan = "+e.rowspan+"\n"),"number
"==typeof e.column&&(a+="\t\t\t\t\tcolPos = "+e.column+"\n"),a+="\t\t\t\t}\n"))}a+="\t\t\t}\n",a+="\t\t}\n"}return a+="\t}\n}\n"},a}();b.GridEditor=f});