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
|
// Used widgets are sortable
|
||||||
$(this).find('.usedWidgets').sortable({
|
$(this).find('.usedWidgets').sortable({
|
||||||
opacity: 0.6,
|
opacity: 0.6,
|
||||||
handle: '.handle',
|
handle: '.handle',
|
||||||
//update: this.updateWidgets,
|
update: function(e, ui) {parentRef.updateWidgets(e, ui)}
|
||||||
connectWith: $(this).find('.availableWidgets')
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Figure out maxid, this is used when creating new widgets
|
// Figure out maxid, this is used when creating new widgets
|
||||||
$(this).data('maxid', 0);
|
$(this).data('maxid', 0);
|
||||||
|
|
||||||
var parentRef=$(this);
|
|
||||||
var usedWidgets = $(this).find('.usedWidgets .Widget');
|
var usedWidgets = $(this).find('.usedWidgets .Widget');
|
||||||
usedWidgets.each(function() {
|
usedWidgets.each(function() {
|
||||||
var widget = $(this)[0];
|
var widget = $(this)[0];
|
||||||
@ -114,38 +108,19 @@
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
/*updateWidgets: function() {
|
updateWidgets: function(e, ui) {
|
||||||
var self = this;
|
|
||||||
|
|
||||||
// Gotta get the name of the current dohickey based off the ID
|
// 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);
|
var i=0;
|
||||||
|
var usedWidgets = $('#usedWidgets-'+name).children().each(function() {
|
||||||
// Gotta get the name of the current dohickey based off the ID
|
var widget = $(this)[0];
|
||||||
this.name = this.element.id.split('-').pop();
|
if(widget.id) {
|
||||||
|
$(this).find('input[name='+widget.id.replace(/\]/g,'\\]').replace(/\[/g,'\\[')+'\\[Sort\\]]').val(i);
|
||||||
|
i++;
|
||||||
// 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();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
},
|
||||||
}
|
|
||||||
},*/
|
|
||||||
|
|
||||||
insertWidgetEditor: function(response) {
|
insertWidgetEditor: function(response) {
|
||||||
// Remove placeholder text
|
// Remove placeholder text
|
||||||
@ -183,7 +158,7 @@
|
|||||||
|
|
||||||
deleteWidget: function(widgetToRemove) {
|
deleteWidget: function(widgetToRemove) {
|
||||||
// Remove a widget from the used widgets column
|
// Remove a widget from the used widgets column
|
||||||
$('#usedWidgets-'+$(this).attr('name')).remove(widgetToRemove);
|
widgetToRemove.remove();
|
||||||
// TODO ... re-create NoWidgets div?
|
// TODO ... re-create NoWidgets div?
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -201,36 +176,15 @@
|
|||||||
getName: function() {
|
getName: function() {
|
||||||
return 'Widget_TDF_Endpoint';
|
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);
|
})(jQuery);
|
Loading…
x
Reference in New Issue
Block a user