class Pettanr.OriginalPicture extends Peta.Content\r
- @single: () ->\r
+ url: '/original_pictures/'\r
+ \r
+ @singular: () ->\r
'OriginalPicture'\r
\r
@plural: () ->\r
'OriginalPictures'\r
\r
defaults: {\r
- id: 11\r
+ id: null,\r
+ artist_id: null\r
} \r
\r
- initialize: () ->\r
- confirm("Welcome to Panel")\r
+ picture: () ->\r
+ new Pettanr.Cache.Retriever(Pettanr.Picture, @get('picture_id'))\r
+ \r
+ is_visible: (operators) ->\r
+ @is_own(operators)\r
+ \r
+ filename: () ->\r
+ @get('id') + '.' + @get('ext')\r
+ \r
+ mime_type: () ->\r
+ 'image/' + @get('ext')\r
+ \r
+ r_url: () ->\r
+ '/original_pictures/' + @filename()\r
+ \r
+ opt_img_tag: () ->\r
+ {src: @r_url(), width: @get('width'), height: @get('height')}\r
+ \r
+ tmb_opt_img_tag: () ->\r
+ new Pettanr.Image.SymbolPicture({\r
+ attr: {\r
+ src: @r_url()\r
+ },\r
+ picture: this\r
+ })\r
+ \r
+ symbol_option: () ->\r
+ retriever = @retriever()\r
+ @listenTo(retriever, 'retrieve', @retrieve_symbol)\r
+ retriever.retrieve()\r
+ \r
+ retrieve_symbol: (item) -> \r
+ @trigger('ready:symbol', item.tmb_opt_img_tag())\r
+ \r
+ filer_caption: () ->\r
+ history = @history()\r
+ history.fetch({cache: true}).done =>\r
+ caption = if _.isEmpty(history.models)\r
+ 'unpublished'\r
+ else\r
+ head = _.first(history.models)\r
+ Pettanr.to_s(head.get('revision'))\r
+ @trigger('ready:caption', caption)\r
+ \r
+ revision: () ->\r
+ new Pettanr.OriginalPicture.Head({original_picture: this})\r
+ \r
+ history: () ->\r
+ new Pettanr.OriginalPicture.History({original_picture: this})\r
+ \r
+ is_unpublished: () ->\r
+ @get('published_at') == null and @get('stopped_at') == null\r
+ \r
+ is_stopped: () ->\r
+ @get('stopped_at') != null\r
+ \r
+ is_unlicensed: () ->\r
+ dt = @get('published_at') || @get('stopped_at')\r
+ return false if not dt\r
+ @get('uploaded_at') > dt\r
+ \r
+ is_published: () ->\r
+ @get('published_at') != null\r
+ \r
+ state: () ->\r
+ switch true\r
+ when @is_unpublished()\r
+ 'unpublished'\r
+ when @is_unlicensed()\r
+ 'unlicensed'\r
+ when @is_stopped()\r
+ 'stopped'\r
+ when @is_published()\r
+ 'published'\r
+ \r
+ initialize: (attr = {}, options = {}) ->\r
+ super(attr, options)\r
+ if @id\r
+ @url = @url + @id\r
+ \r
+class Pettanr.OriginalPicture.History extends Backbone.Collection\r
+ url: '/original_pictures/'\r
+ \r
+ initialize: (options) ->\r
+ @original_picture = options.original_picture\r
+ @model = Pettanr.Picture\r
+ @url = @url + @original_picture.get('id') + '/history'\r
+ \r
+class Pettanr.OriginalPicture.Head extends Backbone.View\r
+ tagName: 'span'\r
+ initialize: (options) ->\r
+ @original_picture = options.original_picture\r
+ @pictures = new Pettanr.OriginalPicture.History({id: @original_picture.get('id')})\r
+ \r
+ render: () ->\r
+ @pictures.fetch({cache: true}).done =>\r
+ head = @pictures.models[0]\r
+ value = if head\r
+ head.get('revision')\r
+ else\r
+ 'unpublished'\r
+ this.$el.html(value)\r
+ this\r
\r
-\r