{I" class:ETI"BundledAsset;FI"logical_path;TI"#rubber_ring/template_editor.js;FI" pathname;TI"e/Users/zigomir/development/rubber_ring/app/assets/javascripts/rubber_ring/template_editor.coffee;FI"content_type;TI"application/javascript;TI" mtime;Tl+þzŸQI" length;Ti¸ I" digest;TI"%b0d586567c56df2221ea425a32a98c11;FI" source;TI"¸ (function() { this.TemplateEditor = (function() { function TemplateEditor(pm, util) { this.pm = pm; this.util = util; } TemplateEditor.prototype.init = function() { var not_saved_yet, _this = this; not_saved_yet = $('[data-cms-template]').filter(function(index, element) { return $(element).data('from-db') === false; }); if (not_saved_yet.length > 0) { this.save_all_templates(); } return $('.rr-control .add-remove').click(function(e) { var $select, action, add_index, content, key, remove_index, template; $select = $(e.currentTarget).parents('.rr-control').find('select'); action = $(e.target).data('action'); template = $select.val(); key = $select.data('cms-template'); add_index = $("[data-cms=" + key + "]").find("[data-template=" + template + "]:first").data('template-index'); remove_index = $("[data-cms=" + key + "]").find("[data-template=" + template + "]:last").data('template-index'); content = { key: key, template: template, index: add_index }; if (action === 'add') { return _this.pm.add_template(content).then(function() { return window.location.reload(true); }); } else { if (add_index !== remove_index) { content.index = remove_index; return _this.pm.remove_template(content).then(function() { return window.location.reload(true); }); } } }); }; TemplateEditor.prototype.save_all_templates = function() { var $templates, templates_to_save; $templates = $('[data-template]'); templates_to_save = this.get_templates_array($templates); return this.pm.save_template(templates_to_save); }; TemplateEditor.prototype.get_templates_array = function($templates) { var list; list = []; $templates.each(function(index, element) { return list.push({ key: $(element).parents('[data-cms]').first().data('cms'), index: $(element).data('template-index'), template: $(element).data('template'), tclass: $(element).attr('class'), element: $(element).prop('tagName').toLowerCase(), sort: index }); }); return list; }; TemplateEditor.prototype.init_sortable = function() { var _this = this; $('.templates').sortable(); $('.templates').sortable('disable'); $('.rr-control [data-action=sort]').click(function(e) { var $btn; $btn = $(e.currentTarget); if ($('.templates').hasClass('ui-sortable-disabled')) { $('.templates').sortable('enable'); $btn.text('Disable sort'); return $('.templates').children().css('cursor', 'move'); } else { $('.templates').sortable('disable'); $btn.text('Enable sort'); return $('.templates').children().css('cursor', 'auto'); } }); return $('.templates').on('sortupdate', function(event, ui) { return _this.save_all_templates(); }); }; return TemplateEditor; })(); }).call(this); ;TI"required_assets_digest;TI"%2921a2fa3f5227ec36bd6c8e995d5eaa;FI" _version;TI"%1e2632a10b8c877576b37720d5bf8883;F