[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 * @constructor
*/ */
function ScrollingListController($scope, formatter) { function ScrollingListController($scope, formatter) {
var populator = new ScrollingListPopulator([]);
// Get a set of populated, ready-to-display rows for the // Get a set of populated, ready-to-display rows for the
// latest data values. // 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 () { ColorController.prototype.groups = function () {
return GROUPS; return GROUPS;
}; };

View File

@ -39,17 +39,13 @@ define(
* @constructor * @constructor
*/ */
function CompositeController() { function CompositeController() {
}
// Check if an element is defined; the map step of isNonEmpty // Check if an element is defined; the map step of isNonEmpty
function isDefined(element) { function isDefined(element) {
return typeof element !== 'undefined'; 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 * Check if an array contains anything other than
* undefined elements. * undefined elements.
@ -58,12 +54,9 @@ define(
* element is in the array * element is in the array
* @memberof platform/forms.CompositeController# * @memberof platform/forms.CompositeController#
*/ */
isNonEmpty: function (value) { CompositeController.prototype.isNonEmpty = function (value) {
return Array.isArray(value) && return Array.isArray(value) && value.some(isDefined);
value.map(isDefined).reduce(or, false);
}
}; };
}
return CompositeController; return CompositeController;

View File

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