diff --git a/main.js b/main.js index a6f19a024c..a51e29965a 100644 --- a/main.js +++ b/main.js @@ -30,7 +30,7 @@ requirejs.config({ "moment": "bower_components/moment/moment", "moment-duration-format": "bower_components/moment-duration-format/lib/moment-duration-format", "screenfull": "bower_components/screenfull/dist/screenfull.min", - "text": "bower_components/text/text.js", + "text": "bower_components/text/text", "uuid": "bower_components/node-uuid/uuid" }, "shim": { diff --git a/platform/commonUI/about/bundle.js b/platform/commonUI/about/bundle.js index ce99c380d1..90235af297 100644 --- a/platform/commonUI/about/bundle.js +++ b/platform/commonUI/about/bundle.js @@ -22,11 +22,13 @@ /*global define*/ define([ + "text!./res/templates/about-dialog.html", "./src/LogoController", "./src/AboutController", "./src/LicenseController", 'legacyRegistry' ], function ( + aboutDialogTemplate, LogoController, AboutController, LicenseController, @@ -50,7 +52,7 @@ define([ }, { "key": "about-dialog", - "templateUrl": "templates/about-dialog.html" + "template": aboutDialogTemplate }, { "key": "overlay-about", diff --git a/platform/representation/src/MCTInclude.js b/platform/representation/src/MCTInclude.js index 761a798dfa..748a57f479 100644 --- a/platform/representation/src/MCTInclude.js +++ b/platform/representation/src/MCTInclude.js @@ -74,7 +74,7 @@ define( var key = template.key; // First found should win (priority ordering) templateMap[key] = - templateMap[key] || templateLinker.getPath(template); + templateMap[key] || template; }); return { diff --git a/platform/representation/src/MCTRepresentation.js b/platform/representation/src/MCTRepresentation.js index 33c203322b..588676cf9a 100644 --- a/platform/representation/src/MCTRepresentation.js +++ b/platform/representation/src/MCTRepresentation.js @@ -69,11 +69,6 @@ define( representationMap[representation.key].push(representation); }); - // Get a path to a representation - function getPath(representation) { - return templateLinker.getPath(representation); - } - // Look up a matching representation for this domain object function lookup(key, domainObject) { var candidates = representationMap[key] || [], @@ -175,9 +170,8 @@ define( function refresh() { var domainObject = $scope.domainObject, representation = lookup($scope.key, domainObject), - path = representation && getPath(representation), uses = ((representation || {}).uses || []), - canRepresent = !!(path && domainObject), + canRepresent = !!(representation && domainObject), canEdit = !!(domainObject && domainObject.hasCapability('editor')), idPath = getIdPath(domainObject), key = $scope.key; @@ -192,7 +186,7 @@ define( // Change templates (passing in undefined to clear // if we don't have enough info to show a template.) - changeTemplate(canRepresent ? path : undefined); + changeTemplate(canRepresent ? representation : undefined); // Any existing representers are no longer valid; release them. destroyRepresenters(); diff --git a/platform/representation/src/TemplateLinker.js b/platform/representation/src/TemplateLinker.js index 8dcef860e6..696edf704f 100644 --- a/platform/representation/src/TemplateLinker.js +++ b/platform/representation/src/TemplateLinker.js @@ -87,7 +87,7 @@ define( * @returns {Function} a function which can be called with a template * URL to switch templates, or `undefined` to remove. */ - TemplateLinker.prototype.link = function (scope, element, templateUrl) { + TemplateLinker.prototype.link = function (scope, element, ext) { var activeElement = element, activeTemplateUrl, comment = this.$compile('')(scope), @@ -124,12 +124,18 @@ define( self.$compile(element.contents())(activeScope); } - function badTemplate(templateUrl) { + function showTemplate(template) { + addElement(); + populateElement(template); + activeTemplateUrl = undefined; + } + + function badTemplateUrl(templateUrl) { self.$log.warn("Couldn't load template at " + templateUrl); removeElement(); } - function changeTemplate(templateUrl) { + function changeTemplateUrl(templateUrl) { if (templateUrl) { destroyScope(); addElement(); @@ -139,7 +145,7 @@ define( populateElement(template); } }, function () { - badTemplate(templateUrl); + badTemplateUrl(templateUrl); }); } else { removeElement(); @@ -147,12 +153,19 @@ define( activeTemplateUrl = templateUrl; } - if (templateUrl) { - changeTemplate(templateUrl); - } else { - removeElement(); + function changeTemplate(ext) { + ext = ext || {}; + if (ext.templateUrl) { + changeTemplateUrl(self.getPath(ext)); + } else if (ext.template) { + showTemplate(ext.template); + } else { + removeElement(); + } } + changeTemplate(ext); + return changeTemplate; }; diff --git a/platform/representation/src/TemplatePrefetcher.js b/platform/representation/src/TemplatePrefetcher.js index e15633694b..7d20bc1031 100644 --- a/platform/representation/src/TemplatePrefetcher.js +++ b/platform/representation/src/TemplatePrefetcher.js @@ -38,11 +38,10 @@ define( .reduce(function (a, b) { return a.concat(b); }, []) - .map(function (ext) { - return templateLinker.getPath(ext); - }) - .forEach(function (path) { - templateLinker.load(path); + .forEach(function (ext) { + if (ext.templateUrl) { + templateLinker.load(templateLinker.getPath(ext)); + } }); }