{I" class:ETI"ProcessedAsset;FI"logical_path;TI"(type_station/editables/edit_page.js;FI" pathname;TI"n/Users/richardadams/github/type_station/app/assets/javascripts/type_station/editables/edit_page.js.coffee;FI"content_type;TI"application/javascript;TI" mtime;Tl+€÷TI" length;TiçI" digest;TI"%458ae4c5ef2680c3da63bebe920ef5ef;FI" source;TI"ç(function() { var buildFields, deletePage, move; move = function(element, direction) { return $.ajax({ type: "PATCH", url: element.data('ts-url'), dataType: 'json', contentType: 'application/json', data: JSON.stringify({ direction: direction }), success: function(data, status) { return window.location.reload(); } }); }; deletePage = function(element) { return $.ajax({ type: "DELETE", url: element.data('ts-url'), dataType: 'json', contentType: 'application/json', data: {}, success: function(data, status) { return window.location.reload(); } }); }; buildFields = function(element) { var field, input, inputs, label, model, modelValues, o, select, tsFieldTypes, tsFields, _i, _len; tsFields = element.data('tsFields'); tsFieldTypes = {}; inputs = ''; model = window.TS.getModel(element.data('ts-url')); modelValues = element.data('ts-data')['ts_values']; for (_i = 0, _len = tsFields.length; _i < _len; _i++) { field = tsFields[_i]; tsFieldTypes[field.name] = field.type; label = ""; input = (function() { var _j, _k, _len1, _len2, _ref, _ref1; switch (field.type) { case "text": return ""; case "textarea": return ""; case "select": select = ""; return select; case "multiple_select": select = ""; return select; } })(); inputs += "
" + label + "
" + input + "
"; } element.data('tsFieldTypes', tsFieldTypes); return inputs; }; window.TS.EditPage = (function() { function EditPage(_at_elements) { var element, _i, _len, _ref; this.elements = _at_elements; _ref = this.elements; for (_i = 0, _len = _ref.length; _i < _len; _i++) { element = _ref[_i]; $(element).append($('').addClass('ts-editable-button').addClass('ts-edit-page-button').addClass('ts-button').html("")); $(element).append($('').addClass('ts-editable-button').addClass('ts-delete-page-button').addClass('ts-button').html("")); if ($(element).data('tsData')['moveable']) { switch ($(element).data('tsData')['moveable']) { case 'left_to_right': $(element).append($('').addClass('ts-editable-button').addClass('ts-move-up-button').addClass('ts-button').html("")); $(element).append($('').addClass('ts-editable-button').addClass('ts-move-down-button').addClass('ts-button').html("")); break; case 'invert_left_to_right': $(element).append($('').addClass('ts-editable-button').addClass('ts-move-down-button-invert').addClass('ts-button').html("")); $(element).append($('').addClass('ts-editable-button').addClass('ts-move-up-button-invert').addClass('ts-button').html("")); break; case 'invert': $(element).append($('').addClass('ts-editable-button').addClass('ts-move-down-button-invert').addClass('ts-button').html("")); $(element).append($('').addClass('ts-editable-button').addClass('ts-move-up-button-invert').addClass('ts-button').html("")); break; default: $(element).append($('').addClass('ts-editable-button').addClass('ts-move-up-button').addClass('ts-button').html("")); $(element).append($('').addClass('ts-editable-button').addClass('ts-move-down-button').addClass('ts-button').html("")); } } } } EditPage.prototype.enable = function() { this.disable(); $('.ts-edit-page-button', this.elements).on('click', function() { var $element, tsData; $element = $(this).parent(); tsData = $element.data('tsData'); vex.dialog.buttons.YES.text = 'Save'; return vex.dialog.open({ message: "Edit " + (tsData.name || 'Page'), input: buildFields($element), $element: $element, afterOpen: function($vexContent) { return $("select.multiple_select", $vexContent).chosen(); }, callback: function(data) { var $el, model, tsFieldTypes; if (data) { $el = this.$element; tsFieldTypes = $el.data('tsFieldTypes'); model = window.TS.getModel($el.data('ts-url')); return vex.dialog.confirm({ message: 'Are you sure you want to save changes?', callback: function(value) { var k, type, v; if (value) { for (k in data) { v = data[k]; type = tsFieldTypes[k]; model.set(k, { field: k, value: v, type: type === 'multiple_select' ? 'multiple_select' : 'text' }); } return model.save(function() { return window.location.reload(); }); } } }); } } }); }); $('.ts-move-up-button, .ts-move-up-button-invert', this.elements).on('click', function() { return move($(this).parent(), 'move_up'); }); $('.ts-move-down-button, .ts-move-down-button-invert', this.elements).on('click', function() { return move($(this).parent(), 'move_down'); }); return $('.ts-delete-page-button', this.elements).on('click', function() { var $element; $element = $(this).parent(); return vex.dialog.confirm({ message: 'Are you sure you want to delete this?', callback: function(value) { if (value) { return deletePage($element); } } }); }); }; EditPage.prototype.disable = function() { $('.ts-edit-page-button', this.elements).off('click'); $('.ts-move-up-button', this.elements).off('click'); return $('.ts-move-down-button', this.elements).off('click'); }; return EditPage; })(); }).call(this); ;TI"dependency_digest;TI"%bfddb68bd7f9d8f2e392f68d688515f6;FI"required_paths;T[I"n/Users/richardadams/github/type_station/app/assets/javascripts/type_station/editables/edit_page.js.coffee;FI"dependency_paths;T[{I" path;TI"n/Users/richardadams/github/type_station/app/assets/javascripts/type_station/editables/edit_page.js.coffee;FI" mtime;TI"2015-03-04T21:58:25+00:00;TI" digest;TI"%effc3e7171cc24a7a4a33dfcac85698b;FI" _version;TI"%64e62ddc273c2f5847f30d698ca14b67;F