2012-06-19 02:27:35 +02:00
|
|
|
(function($) {
|
|
|
|
$.entwine('ss', function($) {
|
|
|
|
$('.WidgetAreaEditor').entwine({
|
|
|
|
onmatch: function() {
|
|
|
|
var parentName=$(this).attr('name');
|
|
|
|
this.rewriteWidgetAreaAttributes();
|
|
|
|
|
2017-07-09 10:17:44 +02:00
|
|
|
var availableWidgets=$('#availableWidgets-'+parentName).children().each(function() {
|
2012-06-19 02:27:35 +02:00
|
|
|
// Don't run on comments, whitespace, etc
|
|
|
|
if($(this)[0].nodeType==1) {
|
|
|
|
// Gotta change their ID's because otherwise we get clashes between two tabs
|
|
|
|
$(this)[0].id=$(this)[0].id+'-'+parentName;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var parentRef=$(this);
|
|
|
|
|
|
|
|
|
|
|
|
// Used widgets are sortable
|
|
|
|
$(this).find('.usedWidgets').sortable({
|
|
|
|
opacity: 0.6,
|
|
|
|
handle: '.handle',
|
2016-06-14 00:21:58 +02:00
|
|
|
update: function (e, ui) {
|
|
|
|
parentRef.updateWidgets(e, ui)
|
|
|
|
},
|
2012-06-19 02:27:35 +02:00
|
|
|
placeholder: 'ui-state-highlight',
|
2016-06-14 00:21:58 +02:00
|
|
|
forcePlaceholderSize: true,
|
|
|
|
start: function (e, ui) {
|
2016-06-21 03:17:30 +02:00
|
|
|
htmleditors = $(ui.item).closest('.Widget').find('textarea.htmleditor');
|
2016-06-14 00:21:58 +02:00
|
|
|
$.each(htmleditors, function (k, i) {
|
|
|
|
tinyMCE.execCommand('mceRemoveControl', false, $(i).attr('id'));
|
|
|
|
})
|
|
|
|
},
|
|
|
|
stop: function (e, ui) {
|
2016-06-21 03:17:30 +02:00
|
|
|
htmleditors = $(ui.item).closest('.Widget').find('textarea.htmleditor');
|
2016-06-14 00:21:58 +02:00
|
|
|
$.each(htmleditors, function (k, i) {
|
|
|
|
tinyMCE.execCommand('mceAddControl', true, $(i).attr('id'));
|
|
|
|
})
|
|
|
|
}
|
2012-06-19 02:27:35 +02:00
|
|
|
});
|
2016-06-21 01:22:38 +02:00
|
|
|
|
2012-06-19 02:27:35 +02:00
|
|
|
// Ensure correct sort values are written when page is saved
|
|
|
|
// TODO Adjust to new event listeners
|
2014-10-06 17:29:21 +02:00
|
|
|
$('.cms-container').bind('submitform', function(e) {parentRef.beforeSave(e)});
|
2012-06-19 02:27:35 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
rewriteWidgetAreaAttributes: function() {
|
|
|
|
var name = $(this).attr('name');
|
|
|
|
|
|
|
|
var monkeyWith = function(widgets, name) {
|
|
|
|
if (!widgets) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
widgets.each(function() {
|
|
|
|
widget=$(this)[0];
|
|
|
|
if (!widget.rewritten && (widget.id || widget.name)) {
|
|
|
|
if (widget.id && widget.id.indexOf('Widget[') === 0) {
|
|
|
|
var newValue = widget.id.replace(/Widget\[/, 'Widget['+name+'][');
|
|
|
|
widget.id = newValue;
|
|
|
|
}
|
|
|
|
if (widget.name && widget.name.indexOf('Widget[') === 0) {
|
|
|
|
var newValue = widget.name.replace(/Widget\[/, 'Widget['+name+'][');
|
|
|
|
widget.name=newValue;
|
|
|
|
}
|
|
|
|
widget.rewritten='yes';
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
monkeyWith($('#WidgetAreaEditor-'+name+' .Widget'), name);
|
|
|
|
monkeyWith($('#WidgetAreaEditor-'+name+' .Widget *'), name);
|
|
|
|
},
|
|
|
|
|
|
|
|
beforeSave: function() {
|
|
|
|
// Ensure correct sort values are written when page is saved
|
|
|
|
var usedWidgets = $('#usedWidgets-'+$(this).attr('name'));
|
|
|
|
if(usedWidgets) {
|
|
|
|
this.sortWidgets();
|
|
|
|
|
|
|
|
var children=usedWidgets.children();
|
|
|
|
|
|
|
|
children.each(function() {
|
|
|
|
if($(this).beforeSave) {
|
|
|
|
$(this).beforeSave();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
addWidget: function(className, holder) {
|
|
|
|
if($('#WidgetAreaEditor-'+holder).attr('maxwidgets')) {
|
|
|
|
var maxCount = $('#WidgetAreaEditor-'+holder).attr('maxwidgets');
|
|
|
|
var count = $('#usedWidgets-'+holder+' .Widget').length;
|
|
|
|
if (count+1 > maxCount) {
|
|
|
|
alert(ss.i18n._t('WidgetAreaEditor.TOOMANY'));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-06 17:27:04 +02:00
|
|
|
var parentRef=$(this),
|
|
|
|
locale = $(this).closest('form').find('input[name=Locale]').val();
|
|
|
|
|
2012-06-19 02:27:35 +02:00
|
|
|
$.ajax({
|
2013-05-07 10:56:38 +02:00
|
|
|
'url': 'WidgetController/EditableSegment/' + className,
|
2013-08-06 17:27:04 +02:00
|
|
|
'success' : function(response) {parentRef.insertWidgetEditor(response)},
|
|
|
|
'data' : {
|
|
|
|
'locale' : locale ,
|
|
|
|
},
|
2012-06-19 02:27:35 +02:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
updateWidgets: function(e, ui) {
|
|
|
|
// Gotta get the name of the current dohickey based off the ID
|
|
|
|
var name = $(this).attr('id').split('-').pop();
|
|
|
|
|
|
|
|
var i=0;
|
|
|
|
var usedWidgets = $('#usedWidgets-'+name).children().each(function() {
|
|
|
|
var widget = $(this)[0];
|
|
|
|
if(widget.id) {
|
|
|
|
$(this).find('input[name='+widget.id.replace(/\]/g,'\\]').replace(/\[/g,'\\[')+'\\[Sort\\]]').val(i);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
insertWidgetEditor: function(response) {
|
2016-06-21 01:22:38 +02:00
|
|
|
var newID = $(response).find('.formid').val();
|
|
|
|
var widgetContent = response.replace(/Widget\[0\]/gi, "Widget[" + (newID) + "]");
|
2013-04-02 09:07:00 +02:00
|
|
|
$('#usedWidgets-'+$(this).attr('name')).append(widgetContent);
|
2012-06-19 02:27:35 +02:00
|
|
|
|
|
|
|
this.rewriteWidgetAreaAttributes();
|
|
|
|
},
|
|
|
|
|
|
|
|
sortWidgets: function() {
|
|
|
|
// Order the sort by the order the widgets are in the list
|
2014-10-06 17:29:21 +02:00
|
|
|
$('#usedWidgets-'+$(this).attr('name')).children().each(function(i) {
|
2012-06-19 02:27:35 +02:00
|
|
|
var div = $(this)[0];
|
|
|
|
|
|
|
|
if(div.nodeName != '#comment') {
|
|
|
|
var fields = div.getElementsByTagName('input');
|
|
|
|
for(j = 0; field = fields.item(j); j++) {
|
|
|
|
if(field.name == div.id + '[Sort]') {
|
|
|
|
field.value = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
deleteWidget: function(widgetToRemove) {
|
|
|
|
// Remove a widget from the used widgets column
|
|
|
|
widgetToRemove.remove();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$('div.availableWidgets .Widget h3').entwine({
|
|
|
|
onclick: function(event) {
|
|
|
|
parts = $(this).parent().attr('id').split('-');
|
|
|
|
var widgetArea = parts.pop();
|
|
|
|
var className = parts.pop();
|
|
|
|
$('#WidgetAreaEditor-'+widgetArea).addWidget(className, widgetArea);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$('div.usedWidgets div.Widget').entwine({
|
|
|
|
onmatch: function() {
|
|
|
|
// Call deleteWidget when delete button is pushed
|
|
|
|
$(this).find('span.widgetDelete').click(function() {
|
2012-08-21 04:47:26 +02:00
|
|
|
$(this).closest('.WidgetAreaEditor').deleteWidget($(this).parent().parent());
|
|
|
|
});
|
2012-06-19 02:27:35 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
})
|
2013-08-06 17:27:04 +02:00
|
|
|
})(jQuery);
|