by_speech_balloon_template: () ->\r
@filer_list()\r
\r
- show_html: () -> \r
+ show_html: () ->\r
+ _this = this\r
+ @item = new Pettanr.Panel({id: @item.get('id')}, {with_elements: true}) # retake panel for 'with_elements' mode\r
+ @item.fetch().done ->\r
+ view = new Pettanr.Views.Panel.Body({\r
+ el: "#pettanr",\r
+ panel: _this.item,\r
+ operators: _this.operators,\r
+ spot: null\r
+ })\r
+ view.render()\r
+ false\r
\r
show: () ->\r
@set_show()\r
switch @params['format']\r
when 'prof'\r
@show_prof()\r
- when 'html'\r
+ else\r
@show_html()\r
\r
count: () ->\r
this.$el.html('')\r
_.each @parts, (part) ->\r
_this.$el.append(part.render().el)\r
- rb = new Pettanr.Tag.Div({class_name: 'row_break'})\r
+ rb = new Pettanr.Tag.Div({class_name: 'row_break', content: ''})\r
this.$el.append(rb.render().el)\r
this\r
\r
sp.fetch().done ->\r
cb(sp.tmb_opt_img_tag())\r
\r
- style: () ->\r
- {\r
- width: Pettanr.to_s(@get('width')) + 'px', \r
- height: Pettanr.to_s(@get('height')) + 'px',\r
- top: Pettanr.to_s(@get('y')) + 'px',\r
- left: Pettanr.to_s(@get('x')) + 'px'\r
- }\r
- \r
initialize: () ->\r
if @id\r
@url = @url + @id\r
@has_picture: () ->\r
false\r
\r
- div_offset: () ->\r
- if @get('xy')\r
- @get('xy')\r
- else\r
- 0\r
- \r
- div_size: () ->\r
- if @get('wh')\r
- @get('wh')\r
- else\r
- 100 - @div_offset()\r
- \r
- div_x: () ->\r
- if @get('orientation') == 0\r
- 0\r
- else\r
- @div_offset()\r
- \r
- div_y: () ->\r
- if @get('orientation') == 0\r
- @div_offset()\r
- else\r
- 0\r
- \r
- div_width: () ->\r
- if @get('orientation') == 0\r
- 100\r
- else\r
- @div_size()\r
- \r
- div_height: () ->\r
- if @get('orientation') == 0\r
- @div_size()\r
- else\r
- 100\r
- \r
- style: (spot = null, opacity = 20) ->\r
- r = {\r
- position: 'absolute', \r
- 'z-index': @get('z'), \r
- top: Pettanr.to_s(@div_y()) + '%', \r
- left: Pettanr.to_s(@div_x()) + '%', \r
- width: Pettanr.to_s(@div_width()) + '%', \r
- height: Pettanr.to_s(@div_height()) + '%', \r
- 'background-color': '#' + ('000000' + Pettanr.to_s(@get('code'))).slice(-6)\r
- }\r
- @merge_opacity(r, opacity) if spot and spot != this\r
- r\r
- \r
initialize: () ->\r
if @id\r
@url = @url + @id\r
\r
class Pettanr.GroundColor.Collection extends Backbone.Collection\r
model: Pettanr.GroundColor\r
- url: '/ground_colors'\r
+ url: '/ground_colors/'\r
+ \r
has_picture: () ->\r
true\r
\r
- style: (spot = null, opacity = 20) ->\r
- r = {\r
- position: 'absolute', \r
- top: '0px', \r
- left: '0px',\r
- 'z-index': @get('z'), \r
- 'background-image': 'url(' + @picture().r_url() + ')', \r
- 'background-repeat': @repeat_text(), \r
- 'background-position': Pettanr.to_s(@get('x')) + 'px ' + Pettanr.to_s(@get('y')) + 'px'\r
- }\r
- @merge_opacity(r, opacity) if spot and spot != this\r
- r\r
- \r
tmb_opt_img_tag: (picture) ->\r
new Pettanr.Image.SymbolPicture({\r
attr: {\r
\r
class Pettanr.GroundPicture.Collection extends Backbone.Collection\r
model: Pettanr.GroundPicture\r
- url: '/ground_pictures'\r
+ url: '/ground_pictures/'\r
+ \r
publish: 0\r
} \r
\r
- initialize: () ->\r
- if @id\r
- @url = @url + @id\r
+ pp: () ->\r
+ new Pettanr.PanelPicture({id: @get('pp_id')})\r
+ \r
+ is_visible: (operators) ->\r
+ switch super(operators)\r
+ when null # super return\r
+ return true\r
+ when false\r
+ return false\r
+ else\r
+ return true if @isNew()\r
+ @is_publish()\r
+ \r
+ is_usable: (operators) ->\r
+ @is_visible(operators)\r
+ \r
+ is_publish: () ->\r
+ @get('publish') > 0\r
+ \r
+ initialize: (attr = {}, options = {}) ->\r
+ @set(attr)\r
+ if @get('id')\r
+ @url = @url + @get('id')\r
+ if options.with_elements\r
+ @url = @url + '?with_elements=true'\r
\r
class Pettanr.Panel.Collection extends Backbone.Collection\r
model: Pettanr.Panel\r
- url: '/panels'\r
+ url: '/panels/'\r
+class Pettanr.RelationPanel extends Pettanr.Panel\r
+ relations: [\r
+ {\r
+ type: Backbone.HasMany,\r
+ key: 'panel_pictures',\r
+ relatedModel: 'Pettanr.PanelPicture',\r
+ collectionType: 'Pettanr.PanelPicture.Collection',\r
+ reverseRelation: {\r
+ key: 'panel_id',\r
+ includeInJSON: 'id'\r
+ }\r
+ },\r
+ ]\r
+ \r
r_url: () ->\r
'/pictures/' + @filename()\r
\r
- opt_div_style: () ->\r
- "top:#{@get('y')}px; left:#{@get('x')}px; z-index:#{@get('z')}; position: absolute;"\r
- \r
- opt_img_tag: (spot = null, opacity = 20) ->\r
- o = if spot and spot != this\r
- "opacity: #{opacity.to_f/100}; filter:alpha(opacity=#{opacity});"\r
- else\r
- ''\r
- @tag_attributes('img', {\r
- class: "panel-picture", \r
- vPicture: @get('id'), \r
- src: @r_url(), \r
- width: Math.abs(@get('width')), \r
- height: Math.abs(@get('height')), \r
- picture_id: @get('picture_id'), \r
- ext: @picture.ext, \r
- alt: @get('caption'), \r
- style: "#{o}"\r
- })\r
- \r
tmb_opt_img_tag: (picture) ->\r
new Pettanr.Image.SymbolPicture({\r
attr: {\r
\r
class Pettanr.PanelPicture.Collection extends Backbone.Collection\r
model: Pettanr.PanelPicture\r
- url: '/panel_pictures'\r
+ url: '/panel_pictures/'\r
+ \r
sp.fetch().done ->\r
cb(sp.tmb_opt_img_tag())\r
\r
- outer_style: () ->\r
- {\r
- top: @get('y'), left: @get('x'), \r
- width: @get('width'), height: @get('height')\r
- }\r
- \r
- inner_style: () ->\r
- {\r
- 'font-size': Pettanr.to_s(@get('font_size')) + 'em',\r
- 'text-align': @text_align_text(), \r
- color: '#' + ('000000' + Pettanr.to_s(@get('fore_color'))).slice(-6)\r
- }\r
- \r
text_align_text: () ->\r
Pettanr.Speech.text_align_texts()[@get('text_align')]\r
\r
+ scenario: () ->\r
+ @boosts('read')\r
+ @render()\r
+ \r
initialize: () ->\r
if @id\r
@url = @url + @id\r
\r
-class Pettanr.Speech.Collection extends Backbone.Collection\r
- model: Pettanr.Speech\r
- url: '/Speeches'\r
\r
class Pettanr.SpeechBalloon.Collection extends Backbone.Collection\r
model: Pettanr.SpeechBalloon\r
- url: '/speech_balloons'\r
+ url: '/speech_balloons/'\r
+ \r
\r
# super return if my item\r
is_visible: (operators) ->\r
- super()\r
+ super(operators)\r
return null if @owner_model().is_own(operators)\r
true\r
\r
class Peta.Element extends Peta.ElementNestableContent\r
+ merge_opacity: (style_hash, opacity) ->\r
+ _.extend(style_hash, {\r
+ opacity: opacity.to_f/100, \r
+ filter: 'alpha(opacity=' + Pettanr.to_s(opacity) + ')'\r
+ })\r
class Peta.ElementNestableContent extends Peta.Content\r
+ element_items: (element_model) ->\r
+ n = @my_class().my_manifest().associations.child_element_name(element_model)\r
+ @my_class()[n]()\r
+ \r
+ elements_items: () ->\r
+ _this = this\r
+ r = _.map @my_class().child_models, (element_model) ->\r
+ _this.element_items(element_model)\r
+ _.flatten(r)\r
+ \r
+ boosts: (level) ->\r
+ super(level)\r
+ _.each @elements_items(), (item) ->\r
+ item.boosts(level)\r
+ \r
is_extend_column: (column_name) ->\r
@is_extend_column column_name\r
\r
- is_user_visible: (operators) ->\r
- if Manifest.manifest.magic_numbers['run_mode'] == 0\r
- return false if not operators.is_guest\r
- else\r
- return false if not operators.is_resource_reader\r
- true\r
- \r
is_visible: (operators) ->\r
- return false if not @is_user_visible(operators)\r
+ if Manifest.manifest().magic_numbers['run_mode'] == 0\r
+ return false if not operators.is_guest()\r
+ else\r
+ return false if not operators.is_resource_reader()\r
true\r
\r
is_editize: () ->\r
class Peta.Root extends Peta.ElementNestableContent\r
+ \r
+ parts_element: () ->\r
+ r = []\r
+ _.each @my_class.child_models, () ->\r
+ r += (@element_items(k) || [])\r
+ end\r
+ r\r
+ \r
+ zorderd_elements: () ->\r
+ res = []\r
+ _.each @parts_element, (e) ->\r
+ res[e.get('z')-1] = e\r
+ end\r
+ res\r
+ \r
+ scenario_elements: () ->\r
+ res = []\r
+ _.each @parts_element, (e) ->\r
+ res[e.get('t')] = e\r
+ end\r
+ res\r
+ \r
else\r
''\r
\r
+ @to_style: (hash) ->\r
+ a = _.map hash, (n, k) ->\r
+ Pettanr.to_s(k) + ': ' + Pettanr.to_s(n)\r
+ a.join('; ')\r
+ \r
@url: (controller_name, action_name, params) ->\r
controller = Manifest.manifest().controllers[controller_name]\r
action = controller.actions[action_name]\r
tagName: 'div'\r
\r
initialize: (options) ->\r
+ @attr = options.attr || {}\r
@content = options.content\r
@class_name = options.class_name\r
\r
render: () ->\r
+ this.$el.attr(@attr)\r
@el.className = @class_name\r
this.$el.html(@content)\r
this\r
--- /dev/null
+class Pettanr.Views.Balloon.Element extends Backbone.View\r
+ tagName: 'img'\r
+ className: 'pettanr-balloon'\r
+ \r
+ initialize: (options) ->\r
+ @element = options.element\r
+ @root = options.root\r
+ @spot = options.spot\r
+ \r
+ render: () ->\r
+ attr = {\r
+ src: @element.system_picture.url(), \r
+ alt: @element.get('caption')\r
+ }\r
+ this.$el.attr(attr)\r
+ this\r
+ \r
--- /dev/null
+class Pettanr.Views.GroundColor.Element extends Backbone.View\r
+ tagName: 'div'\r
+ className: 'pettanr-comic-ground-color'\r
+ \r
+ initialize: (options) ->\r
+ @element = options.element\r
+ @root = options.root\r
+ @spot = options.spot\r
+ \r
+ render: () ->\r
+ attr = {\r
+ style: Pettanr.to_style(@style(@spot))\r
+ }\r
+ this.$el.attr(attr)\r
+ this\r
+ \r
+ div_offset: () ->\r
+ if @element.get('xy')\r
+ @element.get('xy')\r
+ else\r
+ 0\r
+ \r
+ div_size: () ->\r
+ if @element.get('wh')\r
+ @element.get('wh')\r
+ else\r
+ 100 - @div_offset()\r
+ \r
+ div_x: () ->\r
+ if @element.get('orientation') == 0\r
+ 0\r
+ else\r
+ @div_offset()\r
+ \r
+ div_y: () ->\r
+ if @element.get('orientation') == 0\r
+ @div_offset()\r
+ else\r
+ 0\r
+ \r
+ div_width: () ->\r
+ if @element.get('orientation') == 0\r
+ 100\r
+ else\r
+ @div_size()\r
+ \r
+ div_height: () ->\r
+ if @element.get('orientation') == 0\r
+ @div_size()\r
+ else\r
+ 100\r
+ \r
+ style: (spot = null, opacity = 20) ->\r
+ r = {\r
+ position: 'absolute', \r
+ 'z-index': @element.get('z'), \r
+ top: Pettanr.to_s(@div_y()) + '%', \r
+ left: Pettanr.to_s(@div_x()) + '%', \r
+ width: Pettanr.to_s(@div_width()) + '%', \r
+ height: Pettanr.to_s(@div_height()) + '%', \r
+ 'background-color': '#' + ('000000' + Pettanr.to_s(@element.get('code'))).slice(-6)\r
+ }\r
+ @merge_opacity(r, opacity) if spot and spot != @element\r
+ r\r
+ \r
--- /dev/null
+class Pettanr.Views.GroundPicture.Element extends Backbone.View\r
+ tagName: 'div'\r
+ className: 'pettanr-comic-ground-picture'\r
+ \r
+ initialize: (options) ->\r
+ @element = options.element\r
+ @root = options.root\r
+ @spot = options.spot\r
+ \r
+ render: () ->\r
+ s = @style(@spot)\r
+ _.extend(s, @style_wh())\r
+ attr = {\r
+ style: Pettanr.to_style(s)\r
+ }\r
+ this.$el.attr(attr)\r
+ this\r
+ \r
+ style: (spot = null, opacity = 20) ->\r
+ r = {\r
+ position: 'absolute', \r
+ top: '0px', \r
+ left: '0px',\r
+ 'z-index': @element.get('z'), \r
+ 'background-image': 'url(' + @picture().r_url() + ')', \r
+ 'background-repeat': @repeat_text(), \r
+ 'background-position': Pettanr.to_s(@element.get('x')) + 'px ' + Pettanr.to_s(@element.get('y')) + 'px'\r
+ }\r
+ @merge_opacity(r, opacity) if spot and spot != @element\r
+ r\r
+ \r
+ style_wh: () ->\r
+ {\r
+ width: Pettanr.to_s(@root.get('width')) + 'px', \r
+ height: Pettanr.to_s(@root.get('height')) + 'px'\r
+ }\r
+ \r
--- /dev/null
+class Pettanr.Views.PanelPicture.Element extends Backbone.View\r
+ tagName: 'div'\r
+ className: 'pettanr-panel-picture-wrapper'\r
+ \r
+ initialize: (options) ->\r
+ @element = options.element\r
+ @root = options.root\r
+ @spot = options.spot\r
+ \r
+ render: () ->\r
+ @attr = {style: Pettanr.to_style(@opt_div_style())}\r
+ this.$el.attr(@attr)\r
+ @img = new Pettanr.Tag.Img({\r
+ attr: @opt_img_tag(@spot)\r
+ })\r
+ this.$el.html(@img.render().el)\r
+ this\r
+ \r
+ opt_div_style: () ->\r
+ {\r
+ 'top': Pettanr.to_s(@element.get('y')) + 'px',\r
+ 'left': Pettanr.to_s(@element.get('x')) + 'px',\r
+ 'z-index': @element.get('z'),\r
+ 'position': 'absolute'\r
+ }\r
+ \r
+ opt_img_tag: (spot = null, opacity = 20) ->\r
+ style = {}\r
+ if spot and spot != @element\r
+ @merge_opacity(style, opacity)\r
+ {\r
+ vPicture: @element.get('id'), \r
+ src: @element.r_url(), \r
+ width: Pettanr.to_s(Math.abs(@element.get('width'))) + 'px', \r
+ height: Pettanr.to_s(Math.abs(@element.get('height'))) + 'px', \r
+ alt: @element.get('caption'), \r
+ style: Pettanr.to_style(style)\r
+ }\r
+ \r
--- /dev/null
+# panel: panel item\r
+# operators: operators\r
+# spot: no opacity element\r
+class Pettanr.Views.Panel.Body extends Backbone.View\r
+ tagName: 'div'\r
+ className: 'pettanr-comic-panel'\r
+ \r
+ initialize: (options) ->\r
+ @panel = options.panel\r
+ @operators = options.operators\r
+ @spot = options.spot\r
+ \r
+ render: () ->\r
+ attr = {style: Pettanr.to_style(@style())}\r
+ this.$el.attr(attr)\r
+ if @panel.is_visible(@operators)\r
+ this.$el.html('')\r
+ _this = this\r
+ _.each @panel.scenario_elements(), (element) ->\r
+ c = Pettanr[element.singular()].Element\r
+ tag = new c({element: element, root: _this.panel, spot: _this.spot})\r
+ _this.$el.append(tag.render().el)\r
+ else\r
+ tag = new Pettanr.Tag.Div({\r
+ content: I18n.t('panels.hidden'), \r
+ class_name: 'hidden'\r
+ })\r
+ this.$el.html(tag.render().el)\r
+ this\r
+ \r
+ style: () ->\r
+ {\r
+ 'width': Pettanr.to_s(@panel.get('width')) + 'px', \r
+ 'height': Pettanr.to_s(@panel.get('height')) + 'px', \r
+ 'border-style': 'solid', \r
+ 'border-width': Pettanr.to_s(@panel.get('border')) + 'px', \r
+ 'border-color': 'black', \r
+ 'background-color': 'white'\r
+ }\r
--- /dev/null
+class Pettanr.Views.SpeechBalloon.Element extends Backbone.View\r
+ tagName: 'div'\r
+ className: 'pettanr-comic-balloon'\r
+ \r
+ initialize: (options) ->\r
+ @element = options.element\r
+ @root = options.root\r
+ @spot = options.spot\r
+ \r
+ render: () ->\r
+ attr = {style: @style()}\r
+ @balloon = new Pettanr.Views.Balloon.Element({\r
+ element: @element, \r
+ root: @root,\r
+ spot: @spot\r
+ })\r
+ @speech = new Pettanr.Views.Speech.Element({\r
+ element: @element, \r
+ root: @root,\r
+ spot: @spot\r
+ })\r
+ this.$el.attr(@attr)\r
+ this.$el.html(@img.render().el)\r
+ this\r
+ \r
+ style: () ->\r
+ {\r
+ width: Pettanr.to_s(@balloon.get('width')) + 'px', \r
+ height: Pettanr.to_s(@balloon.get('height')) + 'px',\r
+ top: Pettanr.to_s(@balloon.get('y')) + 'px',\r
+ left: Pettanr.to_s(@balloon.get('x')) + 'px',\r
+ 'z-index': @element.get('z')\r
+ }\r
+ \r
--- /dev/null
+class Pettanr.Views.Speech.Element extends Backbone.View\r
+ tagName: 'div'\r
+ className: 'pettanr-comic-speech'\r
+ \r
+ initialize: (options) ->\r
+ @element = options.element\r
+ @root = options.root\r
+ @spot = options.spot\r
+ \r
+ render: () ->\r
+ attr = {style: Pettanr.to_style(@outer_style())}\r
+ @div = new Pettanr.Tag.Div({\r
+ attr: {\r
+ style: Pettanr.to_style(@inner_style())\r
+ }, \r
+ content: @element.scenario(),\r
+ class_name: 'pettanr-comic-speech-inner'\r
+ })\r
+ this.$el.attr(@attr)\r
+ this.$el.html(@div.render().el)\r
+ this\r
+ \r
+ outer_style: () ->\r
+ {\r
+ top: @element.get('y'), \r
+ left: @element.get('x'), \r
+ width: @element.get('width'), \r
+ height: @element.get('height')\r
+ }\r
+ \r
+ inner_style: () ->\r
+ {\r
+ 'font-size': Pettanr.to_s(@element.get('font_size')) + 'em',\r
+ 'text-align': @element.text_align_text(), \r
+ color: '#' + ('000000' + Pettanr.to_s(@element.get('fore_color'))).slice(-6)\r
+ }\r
+ \r
end
def show_json_format_for_root format
- format.json { render json: @item.attributes.to_json(@my_model_class.show_json_opt_for_root) }
+ format.json { render json: @item.to_json(@my_model_class.show_json_opt_for_root) }
end
def set_new
respond_to do |format|
show_html_format format
show_prof_format format
- show_json_format_for_root format
+ if params[:with_elements]
+ show_json_format_for_root format
+ else
+ show_json_format format
+ end
end
end
self.attributes[self.pickup_column_name]
end
- def attr_y
+ def y
self.attributes['y']
end
--- /dev/null
+class RmPanelXy < ActiveRecord::Migration
+ def up
+ remove_column :panels, :x
+ remove_column :panels, :y
+ remove_column :panels, :z
+ end
+
+ def down
+ end
+end
def self.show_json_opt_for_root
r = (self.build_json_opt(self))
- r[:include].merge!(:author => {})
+ #r[:include].merge!(:author => {})
r
end