app/assets/javascripts/pageflow/editor/views/file_item_view.js in pageflow-0.11.4 vs app/assets/javascripts/pageflow/editor/views/file_item_view.js in pageflow-12.0.0.rc1

- old
+ new

@@ -6,42 +6,51 @@ ui: { fileName: '.file_name', selectButton: '.select', + settingsButton: '.settings', removeButton: '.remove', confirmButton: '.confirm', cancelButton: '.cancel', retryButton: '.retry', thumbnail: '.file_thumbnail', stageItems: '.file_stage_items', - rights: 'input.rights', metaData: 'tbody.attributes', downloads: 'tbody.downloads', downloadLink: 'a.original' }, events: { 'click .select': function() { - this.options.selectionHandler.call(this.model); - pageflow.editor.navigate(this.options.selectionHandler.getReferer(), {trigger: true}); + var result = this.options.selectionHandler.call(this.model); + + if (result !== false) { + pageflow.editor.navigate(this.options.selectionHandler.getReferer(), + {trigger: true}); + } + return false; }, + 'click .settings': function() { + pageflow.FileSettingsDialogView.open({ + model: this.model + }); + }, + 'click .cancel': 'cancel', 'click .confirm': 'confirm', 'click .remove': 'destroy', 'click .retry': 'retry', - 'click .file_thumbnail': 'toggleExpanded', - - 'change': 'save' + 'click .file_thumbnail': 'toggleExpanded' }, modelEvents: { 'change': 'update' }, @@ -64,43 +73,45 @@ this.ui.metaData.append(this.subview(view).el); }, this); }, update: function() { + if (this.isClosed) { + return; + } + this.$el.attr('data-id', this.model.id); this.ui.fileName.text(this.model.get('file_name') || '(Unbekannt)'); - this.ui.rights.val(this.model.get('rights')); - this.ui.rights.attr('placeholder', pageflow.entry.get('default_file_rights')); - this.ui.downloadLink.attr('href', this.model.get('original_url')); - this.ui.downloads.toggle(this.model.isUploaded()); + this.ui.downloads.toggle(this.model.isUploaded() && !_.isEmpty(this.model.get('original_url'))); this.ui.selectButton.toggle(!!this.options.selectionHandler); + this.ui.settingsButton.toggle(!this.model.isNew()); this.ui.cancelButton.toggle(this.model.isUploading()); this.ui.confirmButton.toggle(this.model.isConfirmable()); this.ui.removeButton.toggle(!this.model.isUploading()); this.ui.retryButton.toggle(this.model.isRetryable()); this.updateToggleTitle(); }, - save: function() { - this.model.save({ - rights: this.ui.rights.val() - }); - }, - metaDataViews: function() { var model = this.model; - return _.map(this.options.metaDataAttributes, function(attribute) { - return new pageflow.FileMetaDataItemView({ - model: model, - attribute: attribute - }); + return _.map(this.options.metaDataAttributes, function(options) { + if (typeof options === 'string') { + options = { + name: options, + valueView: pageflow.TextFileMetaDataItemValueView + }; + } + + return new pageflow.FileMetaDataItemView(_.extend({ + model: model + }, options)); }); }, toggleExpanded: function() { this.$el.toggleClass('expanded'); @@ -111,10 +122,10 @@ this.ui.thumbnail.attr('title', this.$el.hasClass('expanded') ? 'Details ausblenden' : 'Details einblenden'); }, destroy: function() { if (confirm("Datei wirklich wirklich löschen?")) { - this.model.destroyUsage(); + this.model.destroy(); } }, cancel: function() { this.model.cancelUpload();