Merge branch 'master' into open638_rebase

This commit is contained in:
Pete Richards
2016-03-01 10:48:53 -08:00
86 changed files with 2207 additions and 557 deletions

View File

@@ -29,6 +29,15 @@ define([
"./src/controllers/CompositeController",
"./src/controllers/ColorController",
"./src/controllers/DialogButtonController",
"text!./res/templates/controls/checkbox.html",
"text!./res/templates/controls/datetime.html",
"text!./res/templates/controls/select.html",
"text!./res/templates/controls/textfield.html",
"text!./res/templates/controls/button.html",
"text!./res/templates/controls/color.html",
"text!./res/templates/controls/composite.html",
"text!./res/templates/controls/menu-button.html",
"text!./res/templates/controls/dialog.html",
'legacyRegistry'
], function (
MCTForm,
@@ -38,6 +47,15 @@ define([
CompositeController,
ColorController,
DialogButtonController,
checkboxTemplate,
datetimeTemplate,
selectTemplate,
textfieldTemplate,
buttonTemplate,
colorTemplate,
compositeTemplate,
menuButtonTemplate,
dialogTemplate,
legacyRegistry
) {
"use strict";
@@ -59,6 +77,7 @@ define([
"key": "mctControl",
"implementation": MCTControl,
"depends": [
"templateLinker",
"controls[]"
]
}
@@ -66,7 +85,7 @@ define([
"controls": [
{
"key": "checkbox",
"templateUrl": "templates/controls/checkbox.html"
"template": checkboxTemplate
},
{
"key": "radio",
@@ -74,35 +93,35 @@ define([
},
{
"key": "datetime",
"templateUrl": "templates/controls/datetime.html"
"template": datetimeTemplate
},
{
"key": "select",
"templateUrl": "templates/controls/select.html"
"template": selectTemplate
},
{
"key": "textfield",
"templateUrl": "templates/controls/textfield.html"
"template": textfieldTemplate
},
{
"key": "button",
"templateUrl": "templates/controls/button.html"
"template": buttonTemplate
},
{
"key": "color",
"templateUrl": "templates/controls/color.html"
"template": colorTemplate
},
{
"key": "composite",
"templateUrl": "templates/controls/composite.html"
"template": compositeTemplate
},
{
"key": "menu-button",
"templateUrl": "templates/controls/menu-button.html"
"template": menuButtonTemplate
},
{
"key": "dialog-button",
"templateUrl": "templates/controls/dialog.html"
"template": dialogTemplate
}
],
"controllers": [

View File

@@ -36,23 +36,18 @@ define(
* @constructor
* @memberof platform/forms
*/
function MCTControl(controls) {
function MCTControl(templateLinker, controls) {
var controlMap = {};
// Prepopulate controlMap for easy look up by key
controls.forEach(function (control) {
var path = [
control.bundle.path,
control.bundle.resources,
control.templateUrl
].join("/");
controlMap[control.key] = path;
controlMap[control.key] = control;
});
function link(scope, element, attrs, ngModelController) {
var changeTemplate = templateLinker.link(scope, element);
scope.$watch("key", function (key) {
// Pass the template URL to ng-include via scope.
scope.inclusion = controlMap[key];
changeTemplate(controlMap[key]);
});
scope.ngModelController = ngModelController;
}
@@ -61,10 +56,6 @@ define(
// Only show at the element level
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
priority: 1000,

View File

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

View File

@@ -25,8 +25,8 @@
* Module defining MCTForm. Created by vwoeltje on 11/10/14.
*/
define(
["./controllers/FormController"],
function (FormController) {
["./MCTForm", "text!../res/templates/toolbar.html"],
function (MCTForm, toolbarTemplate) {
"use strict";
/**
@@ -49,38 +49,14 @@ define(
* @memberof platform/forms
* @constructor
*/
function MCTForm() {
var templatePath = [
"platform/forms", //MCTForm.bundle.path,
"res", //MCTForm.bundle.resources,
"templates/toolbar.html"
].join("/");
return {
// Only show at the element level
restrict: "E",
// Load the forms template
templateUrl: templatePath,
// Use FormController to populate/respond to changes in scope
controller: [ '$scope', FormController ],
// Initial an isolate scope
scope: {
// The model: Where form input will actually go
ngModel: "=",
// Form structure; what sections/rows to show
structure: "=",
// Name under which to publish the form
name: "@"
}
};
function MCTToolbar() {
// Use Directive Definition Object from mct-form,
// but use the toolbar's template instead.
var ddo = new MCTForm();
ddo.template = toolbarTemplate;
return ddo;
}
return MCTForm;
return MCTToolbar;
}
);

View File

@@ -29,6 +29,8 @@ define(
describe("The mct-control directive", function () {
var testControls,
mockScope,
mockLinker,
mockChangeTemplate,
mctControl;
beforeEach(function () {
@@ -46,8 +48,11 @@ define(
];
mockScope = jasmine.createSpyObj("$scope", [ "$watch" ]);
mockLinker = jasmine.createSpyObj("templateLinker", ["link"]);
mockChangeTemplate = jasmine.createSpy('changeTemplate');
mockLinker.link.andReturn(mockChangeTemplate);
mctControl = new MCTControl(testControls);
mctControl = new MCTControl(mockLinker, testControls);
});
it("is restricted to the element level", function () {
@@ -66,14 +71,16 @@ define(
it("changes its template dynamically", function () {
mctControl.link(mockScope);
expect(mockChangeTemplate)
.not.toHaveBeenCalledWith(testControls[1]);
mockScope.key = "xyz";
mockScope.$watch.mostRecentCall.args[1]("xyz");
// Should have communicated the template path to
// ng-include via the "inclusion" field in scope
expect(mockScope.inclusion).toEqual(
"x/y/z/template.html"
);
expect(mockChangeTemplate)
.toHaveBeenCalledWith(testControls[1]);
});
});