From 85bb82f683dc8bad55c204520aec10aeda277f09 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Mon, 27 May 2013 12:29:43 +0000 Subject: [PATCH] initial documents view --- pandora/config.indiancinema.jsonc | 1 + static/js/pandora/documentsView.js | 180 +++++++++++++++++++++++++++++ static/js/pandora/item.js | 9 ++ 3 files changed, 190 insertions(+) create mode 100644 static/js/pandora/documentsView.js diff --git a/pandora/config.indiancinema.jsonc b/pandora/config.indiancinema.jsonc index b62f7a1bc..a7f949473 100644 --- a/pandora/config.indiancinema.jsonc +++ b/pandora/config.indiancinema.jsonc @@ -641,6 +641,7 @@ "itemRequiresVideo": false, "itemViews": [ {"id": "info", "title": "Info"}, + {"id": "documents", "title": "Documents"}, {"id": "player", "title": "Player"}, {"id": "editor", "title": "Editor"}, {"id": "timeline", "title": "Timeline"}, diff --git a/static/js/pandora/documentsView.js b/static/js/pandora/documentsView.js new file mode 100644 index 000000000..6e55f65da --- /dev/null +++ b/static/js/pandora/documentsView.js @@ -0,0 +1,180 @@ +// vim: et:ts=4:sw=4:sts=4:ft=javascript + +'use strict'; + +pandora.ui.documentsView = function(options, self) { + + var self = self || {}, + that = Ox.Element({}, self) + .defaults({ + id: '' + }) + .options(options || {}); + + self.selected = null; + + self.$toolbar = Ox.Bar({ + size: 24 + }); + + self.$preview = Ox.Element(); + + + self.$documentsList = Ox.TableList({ + columns: [ + { + align: 'left', + id: 'index', + operator: '+', + title: Ox._('Index'), + visible: false, + width: 60 + }, + { + align: 'left', + id: 'id', + operator: '+', + title: Ox._('ID'), + visible: false, + width: 60 + }, + { + align: 'left', + id: 'user', + operator: '+', + title: Ox._('User'), + visible: false, + width: 60 + }, + { + align: 'left', + id: 'name', + operator: '+', + title: Ox._('Name'), + visible: true, + width: 360 + }, + { + id: 'extension', + operator: '+', + title: Ox._('Extension'), + visible: false, + width: 60 + }, + { + editable: true, + id: 'description', + operator: '+', + title: Ox._('Description'), + visible: true, + width: 240 + } + ], + columnsMovable: true, + columnsRemovable: true, + columnsResizable: true, + columnsVisible: true, + items: options.documents, + scrollbarVisible: true, + sort: [{key: 'index', operator: '+'}], + sortable: true, + unique: 'id' + }) + .bindEvent({ + add: function(data) { + pandora.$ui.documentsDialog = pandora.ui.documentsDialog().open(); + }, + 'delete': function(data) { + if (data.ids.length > 0 && options.editable) { + pandora.api.removeDocument({ + ids: data.ids, + item: pandora.user.ui.item + }, function(result) { + Ox.Request.clearCache(); + //fixme just upload list here + //self.$documentsList.reloadList(); + pandora.$ui.contentPanel.replaceElement(1, + pandora.$ui.item = pandora.ui.item()); + }); + } + }, + move: function(data) { + Ox.Request.clearCache(); + pandora.api.sortDocuments({ + item: pandora.user.ui.item, + ids: data.ids + }) + }, + select: selectDocument, + submit: function(data) { + var value = self.$documentsList.value(data.id, data.key); + if (data.value != value && !(data.value === '' && value === null)) { + self.$documentsList.value(data.id, data.key, data.value || null); + data.key == 'description' && pandora.api.editDocument({ + description: data.value, + id: data.id, + item: pandora.user.ui.item + }, function(result) { + //if description is empty, fall back to global description + self.$documentsList.value(data.id, data.key, result.data.description); + renderPreview(); + }); + } + } + }); + + function renderPreview() { + var isImage = Ox.contains(['jpg', 'png'], self.selected.split('.').pop()), + size = {width: 256, height: 256}, + src = '/documents/' + self.selected + (isImage ? '' : '.jpg'); + self.$preview.empty(); + self.selected && self.$preview + .append(Ox.ImageElement({ + height: size.height, + src: src, + width: size.width + })) + .append(Ox.Element() + .html(self.$documentsList.value(self.selected, 'description') + )); + } + function selectDocument(data) { + if (data.ids[0] != self.selected) { + self.selected = data.ids[0]; + renderPreview(); + } + } + + that.setElement(Ox.SplitPanel({ + elements: [ + { + element: Ox.SplitPanel({ + elements: [ + { + element: self.$toolbar, + size: 24 + }, + { + element: self.$documentsList + }, + ], + orientation: 'vertical' + }) + }, + { + collapsible: true, + element: self.$preview, + size: 256 + } + ], + orientation: 'horizontal' + }) + ); + + + that.reload = function() { + self.$documentsList.reloadList(); + } + return that; + +}; diff --git a/static/js/pandora/item.js b/static/js/pandora/item.js index 47554884b..55f3fbea1 100644 --- a/static/js/pandora/item.js +++ b/static/js/pandora/item.js @@ -16,6 +16,9 @@ pandora.ui.item = function() { 'cuts', 'director', 'duration', 'editable', 'layers', 'parts', 'posterFrame', 'rendered', 'rightslevel', 'size', 'title', 'videoRatio', 'year' + ] : pandora.user.ui.itemView == 'documents' ? [ + 'director', 'documents', 'duration', 'editable', + 'rightslevel', 'size', 'title', 'videoRatio', 'year' ] : [] }, pandora.user.ui.itemView == 'info' && pandora.site.capabilities.canEditMetadata[pandora.user.level] ? 0 : -1, function(result) { @@ -69,6 +72,12 @@ pandora.ui.item = function() { } }) ); + + } else if (pandora.user.ui.itemView == 'documents') { + + pandora.$ui.contentPanel.replaceElement(1, + pandora.$ui.documentsView = pandora.ui.documentsView(result.data) + ); } else if (pandora.user.ui.itemView == 'player') {