initialize: (options) ->\r
@panel = options.root_item\r
@operators = options.operators\r
+ @element_forms = []\r
@body = new Pettanr.Views.Panel.Body.Edit({\r
panel: @root_item(),\r
operators: @operators,\r
@add_element(element)\r
#@dock.add_new_tab()\r
@body.on('panel:resize', @panel_resize)\r
+ @listenTo(@dock, 'put', @put)\r
\r
add_element: (element) ->\r
console.log(element)\r
panel_element_view = @body.add_element(element)\r
element_form = @dock.add_element(element)\r
@dig(element, panel_element_view, element_form)\r
+ @element_forms.push(element_form)\r
if element.constructor.has_picture()\r
@credits.add_picture(element.picture())\r
\r
#$(trace + 'width').val(w)\r
#$(trace + 'height').val(h)\r
\r
+ put: () ->\r
+ attrs = @dock.save_data()\r
+ false\r
+ \r
root_item: () ->\r
@panel\r
\r
parent: @scenario_bay\r
})\r
)\r
+ @listenTo(@root_bay.body, 'put', @put)\r
\r
render: () ->\r
this.$el.html('')\r
dom_labels_class: () ->\r
@dom_class() + '-labels'\r
\r
+ put: () ->\r
+ @trigger('put')\r
+ false\r
+ \r
+ save_data: () ->\r
+ attrs = @root_bay.save_data()\r
+ _.extend(attrs, @element_bay.save_data())\r
+ attrs\r
+ \r
class Editor.EditorModule.DockModule.RootBay extends Editor.EditorModule.DockModule.SimpleBay\r
\r
render: () ->\r
@body.render()\r
\r
+ save_data: () ->\r
+ @body.form.save_data()\r
+ \r
class Editor.EditorModule.DockModule.TabModule.RootBayLabel extends Editor.EditorModule.DockModule.TabModule.BayLabel\r
\r
class Editor.EditorModule.DockModule.TabModule.RootBayBody extends Editor.EditorModule.DockModule.TabModule.BayBody\r
\r
initialize: (options) ->\r
super(options)\r
- @form = new Locmare.Bucket.factory(\r
- @root_item().item_name(), \r
- @root_item(), \r
- @mounted(), \r
- 'default', \r
- @dock().editor().operators\r
- )\r
- @bucket = new Editor.EditorModule.DockModule.FormBucket({\r
- parent: this, form: @form\r
+ @form = Locmare.Form.factory({\r
+ form_name: @root_item().item_name(), \r
+ item: @root_item(), \r
+ mounted: @mounted(), \r
+ submit: 'default', \r
+ operators: @dock().editor().operators,\r
+ action: '/' + @root_item().table_name() + '/' + Pettanr.to_s(@root_item().get('id'))\r
})\r
+ @listenTo(@form, 'put', @put)\r
\r
render: () ->\r
super()\r
@el.className = @bay().body.dom_class()\r
- this.$el.html(@bucket.render().el)\r
+ this.$el.html(@form.render().el)\r
this\r
\r
mounted: () ->\r
root_item: () ->\r
@dock().root_item()\r
\r
+ put: () ->\r
+ @trigger('put')\r
+ false\r
+ \r
class Editor.EditorModule.DockModule.ElementBay extends Editor.EditorModule.DockModule.BoardBay\r
\r
initialize: (options) ->\r
panel_body: () ->\r
@dock().editor().body\r
\r
+ save_data: () ->\r
+ attrs = {}\r
+ _.each @tabs, (tab) ->\r
+ return if not tab.element # without new element tab\r
+ form = tab.body.form\r
+ name = form.item.table_name() + '_attributes'\r
+ attrs[name] ||= []\r
+ attrs[name].push(form.save_data())\r
+ attrs\r
+ \r
class Editor.EditorModule.DockModule.ElementBay.ElementsTabs extends Backbone.View\r
tagName: 'div'\r
className: 'elements_tabs ui-tabs-vertical ui-helper-clearfix'\r
super(options)\r
@submit = options.submit\r
@action = options.action\r
+ @child_forms = {}\r
@item.boosts 'post'\r
@init_fields()\r
\r
action: '/' + element.table_name() + '/' + Pettanr.to_s(element.get('id'))\r
})\r
this.$el.append(form.render().el)\r
+ mm = @item.my_class().my_manifest()\r
+ em = element.my_class().my_manifest()\r
+ if mm.associations.is_has_one(em)\r
+ @child_forms[element.item_name()] = form\r
+ else\r
+ @child_forms[element.table_name()] ||= []\r
+ @child_forms[element.table_name()].push(form)\r
form\r
\r
init_fields: () ->\r
_.each @fields, (field) =>\r
@item.set(field.field_name, field.val())\r
@item.overwrite({operators: @operators})\r
- if @item.save()\r
+ attrs = @make_attrs()\r
+ if @item.save(attrs)\r
window.router.navigate('/' + @item.table_name() + '/' + Pettanr.to_s(@item.get('id')), true)\r
return false\r
else\r
alert('invalid')\r
\r
+ save_data: () ->\r
+ @item.my_class().child_models()\r
+ attrs = {}\r
+ _.each @fields, (field) =>\r
+ attrs[field.field_name] = @item.get(field.field_name)\r
+ _.each @child_forms, (child_form, name) =>\r
+ mm = @item.my_class().my_manifest()\r
+ em = child_form.item.my_class().my_manifest()\r
+ if mm.associations.is_has_one(em)\r
+ attrs[name + '_attributes'] = child_form.save_data()\r
+ else\r
+ attrs[name + '_attributes'] = []\r
+ _.each child_form, (form) =>\r
+ attrs[name + '_attributes'].push(form.save_data())\r
+ attrs\r
+ \r
class Locmare.ExtendForm extends Locmare.FormBase\r
tagName: 'div'\r
className: 'fields'\r
return true if @isNew()\r
@is_publish()\r
\r
+ overwrite: (options) ->\r
+ @set('author_id', options.operators.author.id)\r
+ \r
is_usable: (operators) ->\r
@is_visible(operators)\r
\r
\r
initialize: (options) ->\r
super(options)\r
- 'width'\r
- 'height'\r
- 'border'\r
+ \r
+ post: () ->\r
+ \r
+ put: () ->\r
+ @trigger('put')\r
+ false\r
+ \r