[Code Style] Use prototypes in forms bundle

WTD-1482.
This commit is contained in:
Victor Woeltjen 2015-08-14 13:40:33 -07:00
parent 1c187c3914
commit 7fe866060b
4 changed files with 42 additions and 45 deletions

View File

@ -39,6 +39,7 @@ define(
* @constructor
*/
function ScrollingListController($scope, formatter) {
var populator = new ScrollingListPopulator([]);
// Get a set of populated, ready-to-display rows for the
// latest data values.

View File

@ -89,6 +89,13 @@ define(
}
}
/**
* Get groups of colors to display in a color picker. These are
* given as #-prefixed color strings, in a two-dimensional array.
* Each element of the array is a group of related colors (e.g.
* grayscale colors, web colors, gradients...)
* @returns {string[][]} groups of colors
*/
ColorController.prototype.groups = function () {
return GROUPS;
};

View File

@ -39,32 +39,25 @@ define(
* @constructor
*/
function CompositeController() {
// Check if an element is defined; the map step of isNonEmpty
function isDefined(element) {
return typeof element !== 'undefined';
}
// Boolean or; the reduce step of isNonEmpty
function or(a, b) {
return a || b;
}
return {
/**
* Check if an array contains anything other than
* undefined elements.
* @param {Array} value the array to check
* @returns {boolean} true if any non-undefined
* element is in the array
* @memberof platform/forms.CompositeController#
*/
isNonEmpty: function (value) {
return Array.isArray(value) &&
value.map(isDefined).reduce(or, false);
}
};
}
// Check if an element is defined; the map step of isNonEmpty
function isDefined(element) {
return typeof element !== 'undefined';
}
/**
* Check if an array contains anything other than
* undefined elements.
* @param {Array} value the array to check
* @returns {boolean} true if any non-undefined
* element is in the array
* @memberof platform/forms.CompositeController#
*/
CompositeController.prototype.isNonEmpty = function (value) {
return Array.isArray(value) && value.some(isDefined);
};
return CompositeController;
}

View File

@ -36,9 +36,8 @@ define(
* for user input
*/
function DialogButtonController($scope, dialogService) {
var buttonStructure,
buttonForm,
field;
var self = this,
buttonForm;
// Store the result of user input to the model
function storeResult(result) {
@ -65,11 +64,11 @@ define(
row.key = $scope.field;
// Prepare the structure for the button itself
buttonStructure = {};
buttonStructure.glyph = structure.glyph;
buttonStructure.name = structure.name;
buttonStructure.description = structure.description;
buttonStructure.click = showDialog;
self.buttonStructure = {};
self.buttonStructure.glyph = structure.glyph;
self.buttonStructure.name = structure.name;
self.buttonStructure.description = structure.description;
self.buttonStructure.click = showDialog;
// Prepare the form; a single row
buttonForm = {
@ -79,21 +78,18 @@ define(
}
$scope.$watch('structure', refreshStructure);
return {
/**
* Get the structure for an `mct-control` of type
* `button`; a dialog will be launched when this button
* is clicked.
* @returns dialog structure
* @memberof platform/forms.DialogButtonController#
*/
getButtonStructure: function () {
return buttonStructure;
}
};
}
/**
* Get the structure for an `mct-control` of type
* `button`; a dialog will be launched when this button
* is clicked.
* @returns dialog structure
*/
DialogButtonController.prototype.getButtonStructure = function () {
return this.buttonStructure;
};
return DialogButtonController;
}
);