@show_html()\r
\r
show_html: () -> \r
- @item = @item.with_elements() # retake panel for 'with_elements' mode\r
+ @item = @item.play() # retake panel for 'with_elements' mode\r
@item.fetch({cache: false}).done =>\r
- @item.attributes = @item.replaced_attributes()\r
+ @item.attributes = @item.decoded_attributes()\r
@trigger('title', @params, @item.get('caption'))\r
show = new Pettanr.Views.Panel.Show(@item, {\r
spot: null\r
new: () ->\r
@trigger('title', @params)\r
@set_new()\r
- @item = @item.with_elements()\r
- @render_form()\r
+ @item = @item.edit({\r
+ context: this, \r
+ success: (@item) ->\r
+ @item.boosts 'post'\r
+ @render_form()\r
+ })\r
@trigger('done', @params)\r
\r
edit: () ->\r
@trigger('title', @params)\r
- @set_edit({with_elements: true})\r
+ @set_edit()\r
@trigger('done', @params)\r
\r
+ render_edit: (item) ->\r
+ item.edit({\r
+ context: this, \r
+ success: (@item) ->\r
+ @item.boosts 'post'\r
+ @render_form()\r
+ })\r
+ \r
render_form: () ->\r
@form = new Editor.PanelEditor({root_item: @item})\r
@form.render()\r
tab = @find_tab(element)\r
tab.label.remove()\r
tab.body.remove()\r
- console.log @tabs.indexOf(tab)\r
@tabs.splice(@tabs.indexOf(tab), 1)\r
#@tabs = _.compact(@tabs)\r
@unshift_z()\r
@on('change:field', @change)\r
\r
change: (field) ->\r
- console.log(field.field_name)\r
\r
fold_extend_settings: (params) ->\r
@item.my_class().fold_extend_settings params[@item.item_name()]\r
this\r
\r
refresh: () ->\r
- @tag.render()\r
+ @tag.refresh()\r
@helpers.refresh()\r
\r
change: () ->\r
this.$el.attr(@attr())\r
this\r
\r
+ refresh: () ->\r
+ @render()\r
+ \r
change: (event) ->\r
\r
type: () ->\r
this.$el.attr(@attr())\r
this\r
\r
+ refresh: () ->\r
+ @render()\r
+ \r
val: () ->\r
parseInt(super) # humm... \r
\r
this.$el.attr(@attr())\r
this\r
\r
+ refresh: () ->\r
+ @render()\r
+ \r
change: () ->\r
@field.helpers.refresh()\r
@field.trigger('change')\r
'change': 'change'\r
}\r
\r
+ initialize: (options) ->\r
+ super(options)\r
+ @option_tags = []\r
+ \r
render: () ->\r
+ this.$el.html('')\r
+ this.$el.attr(@attr())\r
+ @option_tags = []\r
@select_values((members) =>\r
values = if @model_attribute_manifest().source.translate()\r
Pettanr.AppHelper.t_select_items(members)\r
else\r
members\r
- this.$el.html('')\r
- this.$el.attr(@attr())\r
_.each values, (member) =>\r
selected = if @is_selected(member)\r
' selected'\r
else\r
''\r
- this.$el.append('<option value="' + member[1] + '"' + selected + '>' + member[0] + '</option>')\r
+ tag = '<option value="' + member[1] + '"' + selected + '>' + member[0] + '</option>'\r
+ @option_tags.push(tag)\r
+ this.$el.append(tag)\r
@trigger('ready:select')\r
)\r
this\r
\r
+ refresh: () ->\r
+ this.$el.html('')\r
+ this.$el.attr(@attr())\r
+ _.each @option_tags, (tag) =>\r
+ this.$el.append(tag)\r
+ \r
val: () ->\r
switch @model_attribute_manifest().type\r
when 'number'\r
this.$el.val(@value())\r
this\r
\r
+ refresh: () ->\r
+ @render()\r
+ \r
change: () ->\r
@field.trigger('change')\r
\r
this.$el.val(@value())\r
this\r
\r
+ refresh: () ->\r
+ @render()\r
+ \r
change: () ->\r
@field.trigger('change')\r
\r
loaded_manifest.init()\r
loaded_local_manifest.init()\r
\r
- #window.onbeforeunload = (e)->\r
- # return('leave?')\r
+ window.onbeforeunload = (e)->\r
+ return('leave?')\r
Backbone.history.start({silent: true, pushState: true, root: '/'})\r
\r
Pettanr.cache = new Pettanr.Cache({operators: new Pettanr.Operator({})})\r
label: (shorten_length) ->\r
@_label('caption', shorten_length)\r
\r
+ play: () ->\r
+ new Pettanr.Panel.Play({id: @get('id')})\r
+ \r
+ edit: (options) ->\r
+ i = new Pettanr.Panel.Edit({id: @get('id')})\r
+ i.load(options)\r
+ \r
initialize: (attr = {}, options = {}) ->\r
super(attr, options)\r
@set(attr)\r
\r
-class Pettanr.Panel.WithElements extends Pettanr.Panel\r
+class Pettanr.Panel.Play extends Pettanr.Panel\r
\r
fetch: (options) ->\r
@url = @default_url() + '?with_elements=true'\r
super(options)\r
\r
+class Pettanr.Panel.Edit extends Pettanr.Panel.Play\r
+ \r
+ load: (options) ->\r
+ @fetch().done =>\r
+ @attributes = @decoded_attributes()\r
+ @load_elements(options)\r
+ \r
save: (attrs) ->\r
@url = @default_url()\r
method = if @isNew()\r
_.each @elements_items(), (item) =>\r
item.boosts(level) if item\r
\r
- replaced_attributes: (options = {}) ->\r
+ dig_elements: () ->\r
+ items = []\r
+ @_dig_elements(items, @attributes)\r
+ items\r
+ \r
+ _dig_elements: (items, attributes) ->\r
+ _.each attributes, (attribute, name) =>\r
+ a = @my_class().my_manifest().associations\r
+ if a.has_many[name]\r
+ _.each attribute, (attr) =>\r
+ items.push(attr)\r
+ Array.prototype.push.apply(items, attr.dig_elements())\r
+ if a.has_one[name]\r
+ items.push(attribute)\r
+ Array.prototype.push.apply(items, attribute.dig_elements())\r
+ \r
+ load_elements: (options) ->\r
+ @_load_elements(@dig_elements(), options)\r
+ \r
+ _load_elements: (items, options) ->\r
+ if _.isEmpty(items)\r
+ options.success.call(options.context, this)\r
+ return\r
+ item = items.shift()\r
+ item.fetch().done =>\r
+ @_load_elements(items, options)\r
+ \r
+ decoded_attributes: () ->\r
attributes = {}\r
_.each @attributes, (attribute, name) =>\r
- replaced = if _.isArray(attribute)\r
+ a = @my_class().my_manifest().associations\r
+ decoded = if a.has_many[name]\r
# has many association\r
- model = @my_class().my_manifest().associations.has_many[name].model()\r
+ model = a.has_many[name].model()\r
_.map attribute, (attr) =>\r
+ child = @cache_child(model, attr)\r
+ child.attributes = child.decoded_attributes()\r
+ child\r
+ else if a.has_one[name]\r
+ # has one association\r
+ model = a.has_one[name].model()\r
+ child = @cache_child(model, attribute)\r
+ child.attributes = child.decoded_attributes()\r
+ child\r
+ else\r
+ attribute\r
+ attributes[name] = decoded\r
+ attributes\r
+ \r
+ replaced_attributes: (options = {}) ->\r
+ attributes = {}\r
+ _.each @attributes, (attribute, name) =>\r
+ console.log name\r
+ console.log attribute\r
+ a = @my_class().my_manifest().associations\r
+ replaced = if a.has_many[name]\r
+ # has many association\r
+ _.map attribute, (decoded) =>\r
child = if options.hold\r
- @replace_and_hold_element(model, attr)\r
+ @replace_and_hold_element(decoded)\r
else\r
- @replace_element(model, attr)\r
+ @replace_element(decoded)\r
+ console.log child\r
child.attributes = child.replaced_attributes(options)\r
child\r
- else if _.isObject(attribute)\r
+ else if a.has_one[name]\r
# has one association\r
- model = @my_class().my_manifest().associations.has_one[name].model()\r
child = if options.hold\r
- @replace_and_hold_element(model, attribute)\r
+ @replace_and_hold_element(attribute)\r
else\r
- @replace_element(model, attribute)\r
+ @replace_element(attribute)\r
child.attributes = child.replaced_attributes(options)\r
child\r
else\r
attribute\r
+ console.log replaced\r
attributes[name] = replaced\r
attributes\r
\r
- replace_element: (model, attr) ->\r
- empty_child = new model(attr)\r
- cached_child = Pettanr.cache.restore(empty_child)\r
+ replace_element: (decoded_child) ->\r
+ cached_child = Pettanr.cache.restore(decoded_child)\r
item = if cached_child\r
cached_child\r
else\r
- Pettanr.cache.store(empty_child)\r
- item.attributes = attr\r
+ model = decoded_child.my_class()\r
+ caching_item = new model()\r
+ Pettanr.cache.store(caching_item)\r
item\r
\r
- replace_and_hold_element: (model, attr) ->\r
- empty_child = new model(attr)\r
- cached_child = Pettanr.cache.restore(empty_child)\r
- item = if cached_child\r
- cached_child\r
+ cache_child: (model, attr) ->\r
+ attr_without_element = {}\r
+ _.each attr, (a, n) ->\r
+ if !_.isObject(a) and !_.isArray(a)\r
+ attr_without_element[n] = a\r
+ decoded_child = new model(attr_without_element)\r
+ cached_child = Pettanr.cache.restore(decoded_child)\r
+ holden_item = if cached_child\r
+ cached_child.hold()\r
else\r
- Pettanr.cache.store(empty_child) \r
- holden = item.hold()\r
- holden.attributes = attr\r
- holden\r
+ Pettanr.cache.store(decoded_child).hold()\r
+ holden_item.attributes = attr\r
+ holden_item\r
\r
hold: () ->\r
super()\r
\r
release_elements: () ->\r
_.each @attributes, (elements, name) =>\r
- if _.isArray(elements)\r
+ a = @my_class().my_manifest().associations\r
+ if a.has_many[name]\r
# has many association\r
- model = @my_class().my_manifest().associations.has_many[name].model()\r
+ model = @my_class().my_manifest().associations.model()\r
_.each elements, (element) =>\r
element.release()\r
- else if _.isObject(elements)\r
+ else if a.has_one[name]\r
# has one association\r
elements.release()\r
\r
fix_elements: () ->\r
return \r
_.each @attributes, (elements, name) =>\r
- if _.isArray(elements)\r
+ a = @my_class().my_manifest().associations\r
+ if a.has_many[name]\r
# has many association\r
- model = @my_class().my_manifest().associations.has_many[name].model()\r
_.each elements, (element) =>\r
if @has('_destroy')\r
element.release() # destroy element by editor\r
else\r
element.fix()\r
- else if _.isObject(elements)\r
+ else if a.has_one[name]\r
# has one association\r
if @has('_destroy')\r
element.release()\r
_.extend(this, Backbone.Events)\r
\r
go: (context, options) -> \r
- @item = @item.with_elements() # retake panel for 'with_elements' mode\r
- @item.fetch({cache: false}).done =>\r
- @item.attributes = @item.replaced_attributes()\r
- delete @item.attributes['id']\r
- @item.overwrite({})\r
- @set_root()\r
- @set_elements()\r
- @save(context, options)\r
+ @item.edit({\r
+ context: this, \r
+ success: (@item) ->\r
+ @item.boosts 'post'\r
+ delete @item.attributes['id']\r
+ @item.overwrite({})\r
+ @set_root()\r
+ @set_elements()\r
+ @save(context, options)\r
+ })\r
\r
set_root: () ->\r
@root_form = Locmare.Form.factory({\r
success: (items) => \r
pager = Locmare.ListGroupModule.LibModule.Pager.factory(@list.page_status, params)\r
_.each items, (panel) =>\r
- panel = panel.with_elements() # retake panel for 'with_elements' mode\r
+ panel = panel.play() # retake panel for 'with_elements' mode\r
panel.fetch({cache: false}).done =>\r
- panel.attributes = panel.replaced_attributes()\r
+ panel.attributes = panel.decoded_attributes()\r
body = new Pettanr.Views.Panel.Body({\r
panel: panel,\r
spot: null\r
@spot = options.spot\r
@speech_balloon = options.parent\r
\r
- clear: () ->\r
- this\r
- \r
render: () ->\r
this.$el.html('')\r
@element.get_parent('system_picture', this, {\r
success: (@system_picture) =>\r
- @set_style()\r
@init_picture()\r
+ @set_style()\r
})\r
+ this\r
\r
init_picture: () ->\r
\r
'z-index': 1 # play case\r
}\r
\r
- add_element: (element) ->\r
- null\r
- \r
class Pettanr.Views.Balloon.Element.Edit extends Pettanr.Views.Balloon.Element\r
\r
initialize: (options) ->\r
}\r
\r
input_r: () ->\r
- @render()\r
- resize_div = this.$el.parent()\r
- resize_div.css('z-index', 1)\r
+ @element.get_parent('system_picture', this, {\r
+ success: (@system_picture) =>\r
+ @set_style()\r
+ #resize_div = this.$el.parent()\r
+ #resize_div.css('z-index', 1)\r
+ })\r
\r
resize: () ->\r
resize_div = this.$el.parent()\r
\r
initialize: (options) ->\r
super(options)\r
- @listenTo(@item, 'input:r', @input_r)\r
+ if @fields['r'] # passing scenario tab's event\r
+ @listenTo(@item, 'input:r', @input_r)\r
\r
render: () ->\r
s = Form.__super__.render\r
@element = options.element\r
@root = options.root\r
@spot = options.spot\r
- @add_element()\r
- \r
- clear: () ->\r
- this\r
\r
render: () ->\r
@restyle()\r
}\r
this.$el.attr(attr)\r
\r
- add_element: () ->\r
- null\r
- \r
div_offset: () ->\r
if @element.get('xy')\r
@element.get('xy')\r
@element = options.element\r
@root = options.root\r
@spot = options.spot\r
- @add_element()\r
\r
init_picture: () ->\r
\r
- clear: () ->\r
- this\r
- \r
render: () ->\r
@element.get_parent('picture', this, {\r
success: (@picture) =>\r
- @restyle()\r
@init_picture()\r
+ @restyle()\r
})\r
this\r
\r
}\r
this.$el.attr(attr)\r
\r
- add_element: () ->\r
- null\r
- \r
style: (spot = null, opacity = 20) ->\r
r = {\r
position: 'absolute', \r
super(options)\r
\r
init_picture: () ->\r
+ super()\r
@listenTo(@root, 'resize', @restyle)\r
@listenTo(@root, 'input:width', @restyle)\r
@listenTo(@root, 'input:height', @restyle)\r
@listenTo(@element, 'active', @active)\r
@listenTo(@element, 'inactive', @inactive)\r
@listenTo(@element, 'sort', @restyle)\r
- super()\r
\r
active: () ->\r
@root.trigger('active')\r
@root = options.root\r
@spot = options.spot\r
\r
- clear: () ->\r
- this\r
- \r
render: () ->\r
@element.get_parent('picture', this, {\r
success: (@picture) =>\r
attr = {style: Pettanr.to_style(@style())}\r
this.$el.attr(attr)\r
\r
- add_element: () ->\r
- null\r
- \r
style: () ->\r
{\r
'top': Pettanr.to_s(@element.get('y')) + 'px',\r
@picture = options.picture\r
@spot = options.spot\r
\r
- clear: () ->\r
- this\r
- \r
render: () ->\r
this.$el.html('')\r
@restyle()\r
\r
initialize: (options) ->\r
super(options)\r
+ \r
+ init_picture: (img) ->\r
+ super(img)\r
@listenTo(@element, 'input:x', @restyle)\r
@listenTo(@element, 'input:y', @restyle)\r
@listenTo(@element, 'sort', @restyle)\r
@listenTo(@element, 'active', @active)\r
@listenTo(@element, 'inactive', @inactive)\r
- \r
- init_picture: (img) ->\r
- super(img)\r
wrapper = this\r
this.$el.draggable {\r
stop: (event, ui) ->\r
success: (item) =>\r
@panel = item.with_elements()\r
@panel.fetch().done =>\r
- @panel.attributes = @panel.replaced_attributes()\r
+ @panel.attributes = @panel.decoded_attributes()\r
@authored_by = @panel.authored_by()\r
@body = new Pettanr.Views.Panel.Body({\r
panel: @panel,\r
view = new c({element: element, root: @panel, spot: @spot})\r
@views.splice(index, 0, view)\r
if @is_visible()\r
- this.$el.append(view.clear().el)\r
- view.render()\r
+ this.$el.append(view.render().el)\r
view\r
\r
remove_element: (element) ->\r
\r
render: () ->\r
this.$el.html('')\r
- @panel = @panel.with_elements() # retake panel for 'with_elements' mode\r
+ @panel = @panel.play() # retake panel for 'with_elements' mode\r
@panel.fetch({cache: true}).done =>\r
@panel.attributes = @panel.replaced_attributes()\r
body = new Pettanr.Views.Scroll.PlayModule.PanelBody({\r
@element = options.element\r
@root = options.root\r
@spot = options.spot\r
- @add_element()\r
- \r
- add_element: () ->\r
- @add_balloon()\r
- @add_speech()\r
- \r
- add_balloon: () ->\r
@balloon = @element.get('balloon')\r
- @set_style()\r
klass = @balloon_class()\r
@balloon_view = new klass({\r
parent: this, \r
root: @root,\r
spot: @spot\r
})\r
- \r
- add_speech: () ->\r
@speech = @element.get('speech')\r
klass = @speech_class()\r
@speech_view = new klass({\r
spot: @spot\r
})\r
\r
- clear: () ->\r
- this\r
- \r
render: () ->\r
this.$el.html('')\r
- this.$el.append(@balloon_view.clear().el)\r
+ this.$el.append(@balloon_view.render().el)\r
this.$el.append(@speech_view.render().el)\r
@set_style()\r
- @balloon_view.render()\r
this\r
\r
set_style: () ->\r
@listenTo(@element, 'sort', @set_style)\r
@listenTo(@element, 'active', @active)\r
@listenTo(@element, 'inactive', @inactive)\r
- \r
- render: () ->\r
- super()\r
@listenTo(@balloon, 'input:r', @input_r)\r
@listenTo(@balloon, 'input:x', @set_style)\r
@listenTo(@balloon, 'input:y', @set_style)\r
@listenTo(@balloon, 'input:width', @set_style)\r
@listenTo(@balloon, 'input:height', @set_style)\r
+ \r
+ render: () ->\r
+ super()\r
bln = @balloon\r
this.$el.draggable {\r
stop: (event, ui) ->\r
@root = options.root\r
@spot = options.spot\r
@parent = options.parent\r
- @listenTo(@parent, 'ready:balloon', @set_style)\r
c = @inner_class()\r
@inner = new c({\r
element: @element,\r
parent: this\r
})\r
\r
- clear: () ->\r
- @render()\r
- \r
render: () ->\r
@set_style()\r
this.$el.html(@inner.render().el)\r
:list => list.map{|i| i.attributes}
# :list => @finder.to_json
}
- p res
render json: res.to_json
}
end