Index: branches/RC/core/admin_templates/js/template_manager.js =================================================================== diff -u -N -r11705 -r11963 --- branches/RC/core/admin_templates/js/template_manager.js (.../template_manager.js) (revision 11705) +++ branches/RC/core/admin_templates/js/template_manager.js (.../template_manager.js) (revision 11963) @@ -1,6 +1,7 @@ -function TemplateManager ($edit_url, $browse_url, $edting_mode) { +function TemplateManager ($edit_url, $browse_url, $save_layout_url, $edting_mode) { this._editUrl = $edit_url; this.browseUrl = $browse_url; + this._saveLayoutUrl = $save_layout_url; this.editingMode = $edting_mode; // from 1 to 4 this._blocks = {}; @@ -39,6 +40,9 @@ if ($template_manager.editingMode == 2) { // Layout Mode + + $template_manager.renumberMovableElements(); + $('div.movable-area').sortable( { placeholder: 'move-helper', @@ -51,10 +55,71 @@ } ); } + + $('div.cms-edit-btn') + .mouseover( + function(e) { + $(this).css('opacity', 1); + } + ) + .mouseout( + function(e) { + $(this).css('opacity', 0.5); + } + ); } ); } +TemplateManager.prototype.renumberMovableElements = function () { + var $area_index = 0; + // 1. dynamically assign IDs to all movable elements + $('div.movable-area').each( + function() { + var $element_index = 0; + $('div.movable-element', this).each( + function() { + $(this).attr('id', 'target_order_a' + $area_index + 'e' + $element_index); + $element_index++; + } + ); + + $area_index++; + } + ); +} + +TemplateManager.prototype.saveLayout = function () { + // prepare order string + var $sort_order = []; + $('div.movable-area').each( + function($area_index) { + var $order = $(this).sortable('serialize').replace(/target_order\[\]/g, 'target_order[' + $area_index + '][]'); + if ($order) { + $sort_order.push($order); + } + } + ); + $sort_order = $sort_order.join('&'); + + // save order string + var $me = this; + var $url = this._saveLayoutUrl + '&' + $sort_order; + $.get( + $url, + function(data) { + // only, when data was saved renumber movable elements + if (data == 'OK') { + alert('New Layout Saved'); + $me.renumberMovableElements(); + } + else { + alert('Failed to Save New Layout'); + } + } + ); +} + TemplateManager.prototype.onBtnClick = function ($e, $element) { var $id = $element.id.replace(/_btn$/, ''); var $block_info = this._blocks[$id];