Daniel@0: "use strict"; Daniel@0: Daniel@0: App.module("RepresentationModule", function(RepresentationModule, App, Backbone, Marionette, $, _, Logger) { Daniel@0: Daniel@0: RepresentationModule.addInitializer(function(options){ Daniel@0: Daniel@0: RepresentationModule.registerMaster({ Daniel@0: id: "entity._", Daniel@0: inherit: "_", Daniel@0: Daniel@0: Daniel@0: // ================================================================= Daniel@0: // config grid header Daniel@0: Daniel@0: _generateCollectionConfigTitle: function(config) { Daniel@0: var rawConfigParameters = config.attributes.parameters.attributes; Daniel@0: var labelParts = []; Daniel@0: if (rawConfigParameters.library) { Daniel@0: if (rawConfigParameters.genre) { Daniel@0: labelParts.push(rawConfigParameters.genre); Daniel@0: } Daniel@0: if (rawConfigParameters.collection) { Daniel@0: if (!rawConfigParameters.place) { Daniel@0: labelParts.push("recordings"); Daniel@0: } Daniel@0: labelParts.push(" in ‘", rawConfigParameters.collection, "’ collection"); Daniel@0: } Daniel@0: if (rawConfigParameters.genre && (rawConfigParameters.title || rawConfigParameters.composer)) { Daniel@0: labelParts.push(" / "); Daniel@0: } Daniel@0: if (rawConfigParameters.composer) { Daniel@0: labelParts.push(rawConfigParameters.composer); Daniel@0: } Daniel@0: if (rawConfigParameters.title && rawConfigParameters.composer) { Daniel@0: labelParts.push(" – "); Daniel@0: } Daniel@0: if (rawConfigParameters.title) { Daniel@0: labelParts.push(rawConfigParameters.title); Daniel@0: } Daniel@0: if (rawConfigParameters.year) { Daniel@0: labelParts.push(" (", rawConfigParameters.year, ")"); Daniel@0: } Daniel@0: if (rawConfigParameters.place) { Daniel@0: labelParts.push(" from ", rawConfigParameters.place); Daniel@0: } Daniel@0: Daniel@0: if (labelParts.length) { Daniel@0: labelParts.unshift(": "); Daniel@0: } Daniel@0: if (!RepresentationModule.getMasterById("entity._")._cachedLibraryLabelsByLibraryId) { Daniel@0: var cachedLibraryLabelsByLibraryId = {}; Daniel@0: var $panelContents = $(Marionette.TemplateCache.get("#cgpma_collection_entity_default")()); Daniel@0: var $tickboxes = $panelContents.find(".cgpma__tickbox"); Daniel@0: $tickboxes.each(function() { Daniel@0: var $tickbox = $(this); Daniel@0: var id = $tickbox.getMod("cgpma_", "id"); Daniel@0: cachedLibraryLabelsByLibraryId[id] = $tickbox.text(); Daniel@0: }); Daniel@0: RepresentationModule.getMasterById("entity._")._cachedLibraryLabelsByLibraryId = cachedLibraryLabelsByLibraryId; Daniel@0: } Daniel@0: var libraries = rawConfigParameters.library.toLowerCase().split(";"); Daniel@0: var libraryLabels = []; Daniel@0: for (var i = 0; i < libraries.length; i++) { Daniel@0: libraryLabels.push(RepresentationModule.getMasterById("entity._")._cachedLibraryLabelsByLibraryId[_.str.trim(libraries[i])]); Daniel@0: } Daniel@0: labelParts.unshift(libraryLabels.join(", ")); Daniel@0: Daniel@0: } else { Daniel@0: labelParts.push("an empty collection"); Daniel@0: } Daniel@0: return labelParts.join(""); Daniel@0: }, Daniel@0: Daniel@0: Daniel@0: _doRenderHeaderContentRelatedToOwnData: function(entityHeaderView, instant) { Daniel@0: if (!entityHeaderView._$label1) { Daniel@0: entityHeaderView._$label1 = $.bem.generateElement("config-grid-cells", "entity-header-label").appendTo(entityHeaderView.$el); Daniel@0: entityHeaderView._$label2 = $.bem.generateElement("config-grid-cells", "entity-header-label", ["row2"]).appendTo(entityHeaderView.$el); Daniel@0: entityHeaderView._$labelFader = $.bem.generateElement("config-grid-cells", "entity-header-label-fader").appendTo(entityHeaderView.$el); Daniel@0: } Daniel@0: if (entityHeaderView.options.config.hasPlannedParameterUpdates()) { Daniel@0: entityHeaderView._$label1.html("" + this._generateHeaderLabel1(entityHeaderView) + ""); Daniel@0: entityHeaderView._$label2.html("being modified"); Daniel@0: } else { Daniel@0: entityHeaderView._$label1.html(this._generateHeaderLabel1(entityHeaderView)); Daniel@0: entityHeaderView._$label2.html(this._generateHeaderLabel2(entityHeaderView)); Daniel@0: } Daniel@0: }, Daniel@0: Daniel@0: _generateHeaderLabel1: function(entityHeaderView) {return "";}, Daniel@0: _generateHeaderLabel2: function(entityHeaderView) {return "";}, Daniel@0: Daniel@0: Daniel@0: // ================================================================= Daniel@0: // dynamic derived vis instance data Daniel@0: Daniel@0: __coverTapActionThatUpdatesDynamicDerivedData: function() { Daniel@0: var $cover = $(this); Daniel@0: var visInstanceView = $cover.data("visInstanceView"); Daniel@0: var derivedDataToUpdate = $cover.data("attachedError").options.derivedDataToUpdate; Daniel@0: switch (derivedDataToUpdate) { Daniel@0: case "entity": Daniel@0: visInstanceView.dynamicDerivedConfigDataForEntity.update(); Daniel@0: break; Daniel@0: case "view": Daniel@0: visInstanceView.dynamicDerivedConfigDataForView.update(); Daniel@0: break; Daniel@0: case "base": Daniel@0: visInstanceView.dynamicDerivedVisInstanceDataForBase.update(); Daniel@0: break; Daniel@0: case "overlay": Daniel@0: visInstanceView.dynamicDerivedVisInstanceDataForOverlay.update(); Daniel@0: break; Daniel@0: case "temp": Daniel@0: visInstanceView.dynamicDerivedVisInstanceDataForTemp.update(); Daniel@0: break; Daniel@0: default: Daniel@0: throw _.str.sprintf("__coverTapActionThatUpdatesDynamicDerivedData cannot be called for derivedDataToUpdate = %s", derivedDataToUpdate); Daniel@0: } Daniel@0: }, Daniel@0: Daniel@0: Daniel@0: // ----------------------------------------------------------------- Daniel@0: // dynamic derived vis instance data - base Daniel@0: Daniel@0: _verifyThatViewIsNotEmptyOrUnknown: function(visInstanceView) { Daniel@0: if (!visInstanceView._cachedViewMaster.options.canHaveBase) { Daniel@0: if (visInstanceView._cachedViewMaster.id == "view._unknown") { Daniel@0: throw new RepresentationModule.Error({type: "view_unknown"}); Daniel@0: } Daniel@0: if (visInstanceView._cachedViewMaster.inherit == "view._default") { Daniel@0: throw new RepresentationModule.Error({type: "view_default"}); Daniel@0: } Daniel@0: else throw "Unknown view master without base " + visInstanceView._cachedViewMaster.id ; Daniel@0: } Daniel@0: }, Daniel@0: Daniel@0: Daniel@0: verifyAllDataForVisInstanceBase: function(visInstanceView) {}, Daniel@0: generateDynamicDerivedVisInstanceDataForBase: function(visInstanceView) { Daniel@0: return new RepresentationModule.DynamicDerivedVisInstanceData(); Daniel@0: }, Daniel@0: Daniel@0: Daniel@0: // ----------------------------------------------------------------- Daniel@0: // dynamic derived vis instance data - overlay Daniel@0: Daniel@0: verifyAllDataForVisInstanceOverlay: function(visInstanceView) {}, Daniel@0: generateDynamicDerivedVisInstanceDataForOverlay: function(visInstanceView) { Daniel@0: if (visInstanceView._cachedViewMaster.generateDynamicDerivedVisInstanceDataForOverlay) { Daniel@0: return visInstanceView._cachedViewMaster.generateDynamicDerivedVisInstanceDataForOverlay(visInstanceView); Daniel@0: } else { Daniel@0: return new RepresentationModule.DynamicDerivedVisInstanceData(); Daniel@0: } Daniel@0: }, Daniel@0: Daniel@0: Daniel@0: // ----------------------------------------------------------------- Daniel@0: // dynamic derived vis instance data - temp Daniel@0: Daniel@0: verifyAllDataForVisInstanceTemp: function(visInstanceView) {}, Daniel@0: generateDynamicDerivedVisInstanceDataForTemp: function(visInstanceView) { Daniel@0: return new RepresentationModule.DynamicDerivedVisInstanceData(); Daniel@0: }, Daniel@0: }); Daniel@0: }); Daniel@0: }, Logger);