From 3fdd8fe2ecaa44f4723d88dd1cc972db1b4a2d7c Mon Sep 17 00:00:00 2001 From: Ed Date: Tue, 19 Jun 2012 21:02:37 -0300 Subject: [PATCH] Updated the handled-bg.png to better fit the SS3.0 design More work on getting the editor functional --- images/handled-bg.png | Bin 9922 -> 1303 bytes javascript/WidgetAreaEditor.js | 224 +++++++++++++++------------------ 2 files changed, 99 insertions(+), 125 deletions(-) diff --git a/images/handled-bg.png b/images/handled-bg.png index b7c440b533ad2b595138122f436dc8931e8d1344..f8a232b7980a70da79aa1bfbbeae844b45b80eeb 100644 GIT binary patch literal 1303 zcmaJ>T}&KR6h15zE7*kep|pLdlcBz7cYb!eEQ~B=+1a(LELj%}Gtuflzl#QjDCKY2Tm9W*mNQ`0)#>SsjF~KynmUh$hp;{B`orR@7i1RRW z?w#-Z&Uel|xvxiCAKOr|wE_S(gm?2X0LN7vKfK<7-!BGZ8vbmtf}K{I)@`K(1A$-C zx)2dogdP+_f;9N-7pMWCl#tsytWoB*fMy`VLorT~sbz>-mSWvIyqvGR~O zn;~^`F+Q}C3$J`+uVv{RO{Y>RD&?j$qlaee>+5X|m&=I}PIFMTgtSvNYl;dyGDSny zEm>0uTT$rJ1}qxx6M0C`h%6TRkH%LjWZsVcy@K&Mp1IJ|1|o>XmP{PgPVZEhpbh{8s++_{$?Bi4&Pb z&*f+4pW4XWB0nA4U-$l0<=elDH!jZJ`TOd?I;dKZhJ^}fie@)Epz0F!$V~^7P0o(R z;lQ!v(Y;$sz<+(=0}AH8{A=<1i7e1+kx$*dUOgWO9d9E6W*KSkLv@wtMH~%#8?P%kv#nbWU zJE~!Q7uMn@58gdo4)5mBNesv&4`XaJyElI99S0oh63d{e>H_|Mieok-z$aOmKVPMHF+~0hs?g|;S&>Q4?bE0nWwW$cgBuS#=p7` zu6##*-XmA1LeTVaa?g3U>p{ru$?muw|E%D7(|mTy?SSdY*}JLGwO1Ftr4ESMJ7;n; n55R%3LLZF&VOX}l{m)Gan3ez7pLpn;WnWd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0}O zI_0fqB^=yzREh}zJVhAWPH5?;S*}AO0TLRh>X zPdQ2-P8Qohf_0|y;u40&$wPHXoXX-a>;DTd02**)2tKwXh5!Hn07*qoM6N<$f<%hl A9RL6T diff --git a/javascript/WidgetAreaEditor.js b/javascript/WidgetAreaEditor.js index d81ba28..4a86340 100644 --- a/javascript/WidgetAreaEditor.js +++ b/javascript/WidgetAreaEditor.js @@ -2,20 +2,16 @@ $.entwine('ss', function($) { $('.WidgetAreaEditor').entwine({ onmatch: function() { - this.name = $(this).attr('name'); - /*this.rewriteWidgetAreaAttributes(); - UsedWidget.applyToChildren(document.getElementById('usedWidgets-'+this.name), 'div.Widget'); + var parentName=$(this).attr('name'); + this.rewriteWidgetAreaAttributes(); - var availableWidgets = document.getElementById('availableWidgets-'+this.name).childNodes; - - for(var i = 0; i < availableWidgets.length; i++) { - var widget = availableWidgets[i]; + var availableWidgets=$('#availableWidgets-'+$(this).attr('name')).children().each(function() { // Don't run on comments, whitespace, etc - if (widget.nodeType == 1) { + if($(this)[0].nodeType==1) { // Gotta change their ID's because otherwise we get clashes between two tabs - widget.id = widget.id + '-'+this.name; + $(this)[0].id=$(this)[0].id+'-'+parentName; } - }*/ + }); // Create dummy sortable to prevent javascript errors @@ -33,35 +29,37 @@ }); // Figure out maxid, this is used when creating new widgets - this.maxid = 0; + $(this).data('maxid', 0); + var parentRef=$(this); var usedWidgets = $(this).find('.usedWidgets .Widget'); - for(var i = 0; i < usedWidgets.length; i++) { - var widget = usedWidgets.get(i); + usedWidgets.each(function() { + var widget = $(this)[0]; if(widget.id) { - widgetid = widget.id.match(/Widget\[([0-9]+)\]/i); - if(widgetid && parseInt(widgetid[1]) > this.maxid) { - this.maxid = parseInt(widgetid[1]); + widgetid = widget.id.match(/Widget\[(.+?)\]\[([0-9]+)\]/i); + if(widgetid && parseInt(widgetid[2]) > parseInt(parentRef.data('maxid'))) { + parentRef.data('maxid', parseInt(widgetid[2])); } } - } + }); // Ensure correct sort values are written when page is saved // TODO Adjust to new event listeners - //jQuery('.cms-edit-form').bind('ajaxsubmit', this.beforeSave.bind(this));*/ - }/*, + $('.cms-container').bind('submitform', this.beforeSave); + }, rewriteWidgetAreaAttributes: function() { - this.name = this.getAttribute('name'); + var name = $(this).attr('name'); var monkeyWith = function(widgets, name) { if (!widgets) { return; } - for(var i = 0; i < widgets.length; i++) { - widget = widgets[i]; - if (!widget.getAttribute('rewritten') && (widget.id || widget.name)) { + + 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+']['); //console.log('Renaming '+widget.tagName+' ID '+widget.id+' to '+newValue); @@ -70,59 +68,53 @@ if (widget.name && widget.name.indexOf('Widget[') === 0) { var newValue = widget.name.replace(/Widget\[/, 'Widget['+name+']['); //console.log('Renaming '+widget.tagName+' Name '+widget.name+' to '+newValue); - widget.name = newValue; + widget.name=newValue; } - widget.setAttribute('rewritten', 'yes'); - } - else { + widget.rewritten='yes'; + }else { //console.log('Skipping '+(widget.id ? widget.id : (widget.name ? widget.name : 'unknown '+widget.tagName))); } - } + }); } - monkeyWith($$('#WidgetAreaEditor-'+this.name+' .Widget'), this.name); - monkeyWith($$('#WidgetAreaEditor-'+this.name+' .Widget *'), this.name); + monkeyWith($('#WidgetAreaEditor-'+name+' .Widget'), name); + monkeyWith($('#WidgetAreaEditor-'+name+' .Widget *'), name); }, beforeSave: function() { // Ensure correct sort values are written when page is saved - var usedWidgets = document.getElementById('usedWidgets-'+this.name); - + var usedWidgets = $('#usedWidgets-'+$(this).attr('name')); if(usedWidgets) { this.sortWidgets(); - var children = usedWidgets.childNodes; + var children=usedWidgets.children(); - for( var i = 0; i < children.length; ++i ) { - var child = children[i]; - - if(child.beforeSave) { - child.beforeSave(); + children.each(function() { + if($(this).beforeSave) { + $(this).beforeSave(); } - } + }); } }, addWidget: function(className, holder) { - - if (document.getElementById('WidgetAreaEditor-'+holder).getAttribute('maxwidgets')) { - var maxCount = document.getElementById('WidgetAreaEditor-'+holder).getAttribute('maxwidgets'); - var count = $$('#usedWidgets-'+holder+' .Widget').length; + 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; } } - - this.name = holder; - jQuery.ajax({ + var parentRef=$(this); + $.ajax({ 'url': 'Widget_Controller/EditableSegment/' + className, - 'success' : document.getElementById('usedWidgets-'+holder).parentNode.parentNode.insertWidgetEditor.bind(this) + 'success' : function(response) {parentRef.insertWidgetEditor(response)} }); }, - updateWidgets: function() { + /*updateWidgets: function() { var self = this; // Gotta get the name of the current dohickey based off the ID @@ -153,110 +145,92 @@ }); } } - }, + },*/ insertWidgetEditor: function(response) { // Remove placeholder text - if(document.getElementById('NoWidgets-'+this.name)) { - document.getElementById('usedWidgets-'+this.name).removeChild(document.getElementById('NoWidgets-'+this.name)); + if($('#NoWidgets-'+$(this).attr('name')).length>0) { + $('#usedWidgets-'+$(this).attr('name')).remove($('#NoWidgets-'+$(this).attr('name'))); } - var usedWidgets = document.getElementById('usedWidgets-'+this.name).childNodes; + var usedWidgets = $('#usedWidgets-'+$(this).attr('name')).children(); // Give the widget a unique id - widgetContent = response.replace(/Widget\[0\]/gi, "Widget[new-" + (++document.getElementById('usedWidgets-'+this.name).parentNode.parentNode.maxid) + "]"); - new Insertion.Top(document.getElementById('usedWidgets-'+this.name), widgetContent); + var newID=parseInt($(this).data('maxid'))+1; + $(this).data('maxid', newID); - document.getElementById('usedWidgets-'+this.name).parentNode.parentNode.rewriteWidgetAreaAttributes(); - UsedWidget.applyToChildren(document.getElementById('usedWidgets-'+this.name), 'div.Widget'); + var widgetContent = response.replace(/Widget\[0\]/gi, "Widget[new-" + (newID) + "]"); + $('#usedWidgets-'+$(this).attr('name')).prepend(widgetContent); - // Repply some common form controls - WidgetTreeDropdownField.applyTo('div.usedWidgets .TreeDropdownField'); - - Sortable.create('usedWidgets-'+this.name, { - tag: 'div', - handle: 'handle', - containment: ['availableWidgets-'+this.name, 'usedWidgets-'+this.name], - onUpdate: document.getElementById('usedWidgets-'+this.name).parentNode.parentNode.updateWidgets - }); + this.rewriteWidgetAreaAttributes(); }, sortWidgets: function() { // Order the sort by the order the widgets are in the list - var usedWidgets = document.getElementById('usedWidgets-'+this.name); - - if(usedWidgets) { - widgets = usedWidgets.childNodes; - - for(i = 0; i < widgets.length; i++) { - var div = widgets[i]; + $('#usedWidgets-'+$(this).attr('name')).children().each(function() { + 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 - document.getElementById('usedWidgets-'+this.name).removeChild(widgetToRemove); + $('#usedWidgets-'+$(this).attr('name')).remove(widgetToRemove); // TODO ... re-create NoWidgets div? - }*/ - - - - /*$('div.availableWidgets .Widget h3').entwine({ - onclick: function(event) { - parts = this.parentNode.id.split('-'); - var widgetArea = parts.pop(); - var className = parts.pop(); - document.getElementById('WidgetAreaEditor-'+widgetArea).addWidget(className, widgetArea); - } - }); - - $('div.usedWidgets .TreeDropdownField').entwine({ - 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.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 .TreeDropdownField').entwine({ + 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); + } + });*/ }) })(jQuery); \ No newline at end of file