[Templates] Use templateLinker for forms

...for compatibility with both template and templateUrl
This commit is contained in:
Victor Woeltjen
2016-02-26 15:01:40 -08:00
parent 8581547a9c
commit 5c3d8508a2
3 changed files with 8 additions and 22 deletions

View File

@@ -77,6 +77,7 @@ define([
"key": "mctControl", "key": "mctControl",
"implementation": MCTControl, "implementation": MCTControl,
"depends": [ "depends": [
"templateLinker",
"controls[]" "controls[]"
] ]
} }

View File

@@ -36,23 +36,18 @@ define(
* @constructor * @constructor
* @memberof platform/forms * @memberof platform/forms
*/ */
function MCTControl(controls) { function MCTControl(templateLinker, controls) {
var controlMap = {}; var controlMap = {};
// Prepopulate controlMap for easy look up by key // Prepopulate controlMap for easy look up by key
controls.forEach(function (control) { controls.forEach(function (control) {
var path = [ controlMap[control.key] = control;
control.bundle.path,
control.bundle.resources,
control.templateUrl
].join("/");
controlMap[control.key] = path;
}); });
function link(scope, element, attrs, ngModelController) { function link(scope, element, attrs, ngModelController) {
var changeTemplate = templateLinker.link(scope, element);
scope.$watch("key", function (key) { scope.$watch("key", function (key) {
// Pass the template URL to ng-include via scope. changeTemplate(controlMap[key]);
scope.inclusion = controlMap[key];
}); });
scope.ngModelController = ngModelController; scope.ngModelController = ngModelController;
} }
@@ -61,10 +56,6 @@ define(
// Only show at the element level // Only show at the element level
restrict: "E", restrict: "E",
// Use ng-include as a template; "inclusion" will be the real
// template path
template: '<ng-include src="inclusion"></ng-include>',
// ngOptions is terminal, so we need to be higher priority // ngOptions is terminal, so we need to be higher priority
priority: 1000, priority: 1000,

View File

@@ -27,8 +27,8 @@
* @namespace platform/forms * @namespace platform/forms
*/ */
define( define(
["./controllers/FormController"], ["./controllers/FormController", "text!../res/templates/form.html"],
function (FormController) { function (FormController, formTemplate) {
"use strict"; "use strict";
/** /**
@@ -52,18 +52,12 @@ define(
* @constructor * @constructor
*/ */
function MCTForm() { function MCTForm() {
var templatePath = [
"platform/forms", //MCTForm.bundle.path,
"res", //MCTForm.bundle.resources,
"templates/form.html"
].join("/");
return { return {
// Only show at the element level // Only show at the element level
restrict: "E", restrict: "E",
// Load the forms template // Load the forms template
templateUrl: templatePath, template: formTemplate,
// Use FormController to populate/respond to changes in scope // Use FormController to populate/respond to changes in scope
controller: [ '$scope', FormController ], controller: [ '$scope', FormController ],