annotate src/DML/MainVisBundle/Resources/assets/marionette/modules/RepresentationModule/RepresentationModule.20-Master.entity._.js @ 1:f38015048f48 tip

Added GPL
author Daniel Wolff
date Sat, 13 Feb 2016 20:43:38 +0100
parents 493bcb69166c
children
rev   line source
Daniel@0 1 "use strict";
Daniel@0 2
Daniel@0 3 App.module("RepresentationModule", function(RepresentationModule, App, Backbone, Marionette, $, _, Logger) {
Daniel@0 4
Daniel@0 5 RepresentationModule.addInitializer(function(options){
Daniel@0 6
Daniel@0 7 RepresentationModule.registerMaster({
Daniel@0 8 id: "entity._",
Daniel@0 9 inherit: "_",
Daniel@0 10
Daniel@0 11
Daniel@0 12 // =================================================================
Daniel@0 13 // config grid header
Daniel@0 14
Daniel@0 15 _generateCollectionConfigTitle: function(config) {
Daniel@0 16 var rawConfigParameters = config.attributes.parameters.attributes;
Daniel@0 17 var labelParts = [];
Daniel@0 18 if (rawConfigParameters.library) {
Daniel@0 19 if (rawConfigParameters.genre) {
Daniel@0 20 labelParts.push(rawConfigParameters.genre);
Daniel@0 21 }
Daniel@0 22 if (rawConfigParameters.collection) {
Daniel@0 23 if (!rawConfigParameters.place) {
Daniel@0 24 labelParts.push("recordings");
Daniel@0 25 }
Daniel@0 26 labelParts.push(" in ‘", rawConfigParameters.collection, "’ collection");
Daniel@0 27 }
Daniel@0 28 if (rawConfigParameters.genre && (rawConfigParameters.title || rawConfigParameters.composer)) {
Daniel@0 29 labelParts.push(" / ");
Daniel@0 30 }
Daniel@0 31 if (rawConfigParameters.composer) {
Daniel@0 32 labelParts.push(rawConfigParameters.composer);
Daniel@0 33 }
Daniel@0 34 if (rawConfigParameters.title && rawConfigParameters.composer) {
Daniel@0 35 labelParts.push(" – ");
Daniel@0 36 }
Daniel@0 37 if (rawConfigParameters.title) {
Daniel@0 38 labelParts.push(rawConfigParameters.title);
Daniel@0 39 }
Daniel@0 40 if (rawConfigParameters.year) {
Daniel@0 41 labelParts.push(" (", rawConfigParameters.year, ")");
Daniel@0 42 }
Daniel@0 43 if (rawConfigParameters.place) {
Daniel@0 44 labelParts.push(" from ", rawConfigParameters.place);
Daniel@0 45 }
Daniel@0 46
Daniel@0 47 if (labelParts.length) {
Daniel@0 48 labelParts.unshift(": ");
Daniel@0 49 }
Daniel@0 50 if (!RepresentationModule.getMasterById("entity._")._cachedLibraryLabelsByLibraryId) {
Daniel@0 51 var cachedLibraryLabelsByLibraryId = {};
Daniel@0 52 var $panelContents = $(Marionette.TemplateCache.get("#cgpma_collection_entity_default")());
Daniel@0 53 var $tickboxes = $panelContents.find(".cgpma__tickbox");
Daniel@0 54 $tickboxes.each(function() {
Daniel@0 55 var $tickbox = $(this);
Daniel@0 56 var id = $tickbox.getMod("cgpma_", "id");
Daniel@0 57 cachedLibraryLabelsByLibraryId[id] = $tickbox.text();
Daniel@0 58 });
Daniel@0 59 RepresentationModule.getMasterById("entity._")._cachedLibraryLabelsByLibraryId = cachedLibraryLabelsByLibraryId;
Daniel@0 60 }
Daniel@0 61 var libraries = rawConfigParameters.library.toLowerCase().split(";");
Daniel@0 62 var libraryLabels = [];
Daniel@0 63 for (var i = 0; i < libraries.length; i++) {
Daniel@0 64 libraryLabels.push(RepresentationModule.getMasterById("entity._")._cachedLibraryLabelsByLibraryId[_.str.trim(libraries[i])]);
Daniel@0 65 }
Daniel@0 66 labelParts.unshift(libraryLabels.join(", "));
Daniel@0 67
Daniel@0 68 } else {
Daniel@0 69 labelParts.push("an empty collection");
Daniel@0 70 }
Daniel@0 71 return labelParts.join("");
Daniel@0 72 },
Daniel@0 73
Daniel@0 74
Daniel@0 75 _doRenderHeaderContentRelatedToOwnData: function(entityHeaderView, instant) {
Daniel@0 76 if (!entityHeaderView._$label1) {
Daniel@0 77 entityHeaderView._$label1 = $.bem.generateElement("config-grid-cells", "entity-header-label").appendTo(entityHeaderView.$el);
Daniel@0 78 entityHeaderView._$label2 = $.bem.generateElement("config-grid-cells", "entity-header-label", ["row2"]).appendTo(entityHeaderView.$el);
Daniel@0 79 entityHeaderView._$labelFader = $.bem.generateElement("config-grid-cells", "entity-header-label-fader").appendTo(entityHeaderView.$el);
Daniel@0 80 }
Daniel@0 81 if (entityHeaderView.options.config.hasPlannedParameterUpdates()) {
Daniel@0 82 entityHeaderView._$label1.html("<span class=\"config-grid-cells__view-header-label-part_modified\">" + this._generateHeaderLabel1(entityHeaderView) + "</span>");
Daniel@0 83 entityHeaderView._$label2.html("being modified");
Daniel@0 84 } else {
Daniel@0 85 entityHeaderView._$label1.html(this._generateHeaderLabel1(entityHeaderView));
Daniel@0 86 entityHeaderView._$label2.html(this._generateHeaderLabel2(entityHeaderView));
Daniel@0 87 }
Daniel@0 88 },
Daniel@0 89
Daniel@0 90 _generateHeaderLabel1: function(entityHeaderView) {return "";},
Daniel@0 91 _generateHeaderLabel2: function(entityHeaderView) {return "";},
Daniel@0 92
Daniel@0 93
Daniel@0 94 // =================================================================
Daniel@0 95 // dynamic derived vis instance data
Daniel@0 96
Daniel@0 97 __coverTapActionThatUpdatesDynamicDerivedData: function() {
Daniel@0 98 var $cover = $(this);
Daniel@0 99 var visInstanceView = $cover.data("visInstanceView");
Daniel@0 100 var derivedDataToUpdate = $cover.data("attachedError").options.derivedDataToUpdate;
Daniel@0 101 switch (derivedDataToUpdate) {
Daniel@0 102 case "entity":
Daniel@0 103 visInstanceView.dynamicDerivedConfigDataForEntity.update();
Daniel@0 104 break;
Daniel@0 105 case "view":
Daniel@0 106 visInstanceView.dynamicDerivedConfigDataForView.update();
Daniel@0 107 break;
Daniel@0 108 case "base":
Daniel@0 109 visInstanceView.dynamicDerivedVisInstanceDataForBase.update();
Daniel@0 110 break;
Daniel@0 111 case "overlay":
Daniel@0 112 visInstanceView.dynamicDerivedVisInstanceDataForOverlay.update();
Daniel@0 113 break;
Daniel@0 114 case "temp":
Daniel@0 115 visInstanceView.dynamicDerivedVisInstanceDataForTemp.update();
Daniel@0 116 break;
Daniel@0 117 default:
Daniel@0 118 throw _.str.sprintf("__coverTapActionThatUpdatesDynamicDerivedData cannot be called for derivedDataToUpdate = %s", derivedDataToUpdate);
Daniel@0 119 }
Daniel@0 120 },
Daniel@0 121
Daniel@0 122
Daniel@0 123 // -----------------------------------------------------------------
Daniel@0 124 // dynamic derived vis instance data - base
Daniel@0 125
Daniel@0 126 _verifyThatViewIsNotEmptyOrUnknown: function(visInstanceView) {
Daniel@0 127 if (!visInstanceView._cachedViewMaster.options.canHaveBase) {
Daniel@0 128 if (visInstanceView._cachedViewMaster.id == "view._unknown") {
Daniel@0 129 throw new RepresentationModule.Error({type: "view_unknown"});
Daniel@0 130 }
Daniel@0 131 if (visInstanceView._cachedViewMaster.inherit == "view._default") {
Daniel@0 132 throw new RepresentationModule.Error({type: "view_default"});
Daniel@0 133 }
Daniel@0 134 else throw "Unknown view master without base " + visInstanceView._cachedViewMaster.id ;
Daniel@0 135 }
Daniel@0 136 },
Daniel@0 137
Daniel@0 138
Daniel@0 139 verifyAllDataForVisInstanceBase: function(visInstanceView) {},
Daniel@0 140 generateDynamicDerivedVisInstanceDataForBase: function(visInstanceView) {
Daniel@0 141 return new RepresentationModule.DynamicDerivedVisInstanceData();
Daniel@0 142 },
Daniel@0 143
Daniel@0 144
Daniel@0 145 // -----------------------------------------------------------------
Daniel@0 146 // dynamic derived vis instance data - overlay
Daniel@0 147
Daniel@0 148 verifyAllDataForVisInstanceOverlay: function(visInstanceView) {},
Daniel@0 149 generateDynamicDerivedVisInstanceDataForOverlay: function(visInstanceView) {
Daniel@0 150 if (visInstanceView._cachedViewMaster.generateDynamicDerivedVisInstanceDataForOverlay) {
Daniel@0 151 return visInstanceView._cachedViewMaster.generateDynamicDerivedVisInstanceDataForOverlay(visInstanceView);
Daniel@0 152 } else {
Daniel@0 153 return new RepresentationModule.DynamicDerivedVisInstanceData();
Daniel@0 154 }
Daniel@0 155 },
Daniel@0 156
Daniel@0 157
Daniel@0 158 // -----------------------------------------------------------------
Daniel@0 159 // dynamic derived vis instance data - temp
Daniel@0 160
Daniel@0 161 verifyAllDataForVisInstanceTemp: function(visInstanceView) {},
Daniel@0 162 generateDynamicDerivedVisInstanceDataForTemp: function(visInstanceView) {
Daniel@0 163 return new RepresentationModule.DynamicDerivedVisInstanceData();
Daniel@0 164 },
Daniel@0 165 });
Daniel@0 166 });
Daniel@0 167 }, Logger);