mirror of
https://github.com/silverstripe/silverstripe-widgets
synced 2024-10-22 15:05:54 +00:00
Finished work on the editor javascript
This commit is contained in:
parent
3fdd8fe2ec
commit
4972b44cec
@ -13,25 +13,19 @@
|
||||
}
|
||||
});
|
||||
|
||||
var parentRef=$(this);
|
||||
|
||||
// Create dummy sortable to prevent javascript errors
|
||||
$(this).find('.availableWidgets').sortable({
|
||||
opacity: 0.6,
|
||||
handle: '.handle'
|
||||
});
|
||||
|
||||
// Used widgets are sortable
|
||||
$(this).find('.usedWidgets').sortable({
|
||||
opacity: 0.6,
|
||||
handle: '.handle',
|
||||
//update: this.updateWidgets,
|
||||
connectWith: $(this).find('.availableWidgets')
|
||||
update: function(e, ui) {parentRef.updateWidgets(e, ui)}
|
||||
});
|
||||
|
||||
// Figure out maxid, this is used when creating new widgets
|
||||
$(this).data('maxid', 0);
|
||||
|
||||
var parentRef=$(this);
|
||||
var usedWidgets = $(this).find('.usedWidgets .Widget');
|
||||
usedWidgets.each(function() {
|
||||
var widget = $(this)[0];
|
||||
@ -114,38 +108,19 @@
|
||||
});
|
||||
},
|
||||
|
||||
/*updateWidgets: function() {
|
||||
var self = this;
|
||||
|
||||
updateWidgets: function(e, ui) {
|
||||
// Gotta get the name of the current dohickey based off the ID
|
||||
this.name = this.element.id.split('-').pop();
|
||||
var name = $(this).attr('id').split('-').pop();
|
||||
|
||||
// alert(this.name);
|
||||
|
||||
// Gotta get the name of the current dohickey based off the ID
|
||||
this.name = this.element.id.split('-').pop();
|
||||
|
||||
|
||||
// This is called when an available widgets is dragged over to used widgets.
|
||||
// It inserts the editor form into the new used widget
|
||||
|
||||
var usedWidgets = document.getElementById('usedWidgets-'+this.name).childNodes;
|
||||
for(var i = 0; i < usedWidgets.length; i++) {
|
||||
var widget = usedWidgets[i];
|
||||
if(widget.id && (widget.id.indexOf("Widget[") != 0) && (widget.id != 'NoWidgets-'+this.name)) {
|
||||
// Need to remove the -$Name part.
|
||||
var wIdArray = widget.id.split('-');
|
||||
wIdArray.pop();
|
||||
|
||||
jQuery.ajax({
|
||||
'url': 'Widget_Controller/EditableSegment/' + wIdArray.join('-'),
|
||||
'success' : function() {
|
||||
document.getElementById('usedWidgets-'+self.name).parentNode.parentNode.insertWidgetEditor();
|
||||
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) {
|
||||
// Remove placeholder text
|
||||
@ -183,7 +158,7 @@
|
||||
|
||||
deleteWidget: function(widgetToRemove) {
|
||||
// Remove a widget from the used widgets column
|
||||
$('#usedWidgets-'+$(this).attr('name')).remove(widgetToRemove);
|
||||
widgetToRemove.remove();
|
||||
// TODO ... re-create NoWidgets div?
|
||||
}
|
||||
});
|
||||
@ -201,36 +176,15 @@
|
||||
getName: function() {
|
||||
return 'Widget_TDF_Endpoint';
|
||||
}
|
||||
});
|
||||
|
||||
/*$('div.usedWidgets div.Widget').entwine({
|
||||
initialize: function() {
|
||||
// Call deleteWidget when delete button is pushed
|
||||
this.deleteButton = this.findDescendant('span', 'widgetDelete');
|
||||
if(this.deleteButton)
|
||||
this.deleteButton.onclick = this.deleteWidget.bind(this);
|
||||
},
|
||||
|
||||
// Taken from FieldEditor
|
||||
findDescendant: function(tag, clsName, element) {
|
||||
if(!element)
|
||||
element = this;
|
||||
|
||||
var descendants = element.getElementsByTagName(tag);
|
||||
|
||||
for(var i = 0; i < descendants.length; i++) {
|
||||
var el = descendants[i];
|
||||
|
||||
if(tag.toUpperCase() == el.tagName && el.className.indexOf( clsName ) != -1)
|
||||
return el;
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
|
||||
deleteWidget: function() {
|
||||
this.parentNode.parentNode.parentNode.deleteWidget(this);
|
||||
}
|
||||
});*/
|
||||
|
||||
$('div.usedWidgets div.Widget').entwine({
|
||||
onmatch: function() {
|
||||
// Call deleteWidget when delete button is pushed
|
||||
$(this).find('span.widgetDelete').click(function() {
|
||||
$(this).closest('.WidgetAreaEditor').deleteWidget($(this).parent().parent());
|
||||
});
|
||||
}
|
||||
});
|
||||
})
|
||||
})(jQuery);
|
Loading…
x
Reference in New Issue
Block a user