diff --git a/install/ui/doc/categories.json b/install/ui/doc/categories.json index ec0776687..e8ae56b79 100644 --- a/install/ui/doc/categories.json +++ b/install/ui/doc/categories.json @@ -123,7 +123,8 @@ "details.command_info", "details.field_info", "details.update_info_builder", - "details.command_builder" + "details.command_builder", + "FormMixin" ] }, { diff --git a/install/ui/doc/config.json b/install/ui/doc/config.json index c744fd6aa..6a200f9ae 100644 --- a/install/ui/doc/config.json +++ b/install/ui/doc/config.json @@ -5,7 +5,7 @@ "--css": ["doc.css"], "--external": ["jQuery", "Store", "QueryResult", "Stateful", "Evented", "XMLHttpRequest", "Promise"], - "--warnings": ["-link", "-no_doc"], + "--warnings": ["-link", "-nodoc"], "--": [ "../src/freeipa/" ], diff --git a/install/ui/src/freeipa/FormMixin.js b/install/ui/src/freeipa/FormMixin.js new file mode 100644 index 000000000..ef594733a --- /dev/null +++ b/install/ui/src/freeipa/FormMixin.js @@ -0,0 +1,204 @@ +/* Authors: + * Petr Vobornik + * + * Copyright (C) 2013 Red Hat + * see file 'COPYING' for use and warranty information + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . +*/ + +define(['dojo/_base/declare', + 'dojo/_base/lang', + 'dojo/on', + './builder', + './field', + './ordered-map' + ], + function(declare, lang, on, builder, field_mod, ordered_map) { + + /** + * Form mixin + * + * Manages fields and related logic. + * + * Expects that this mixin will be mixed in a class which will implement + * `Stateful`. + * + * @class FormMixin + */ + var FormMixin = declare([], { + + /** + * Some field is dirty + * @property {boolean} + */ + dirty: null, + + /** + * Fields + * @property {ordered_map} + */ + fields: null, + + /** + * Builds fields on add if not already built + * + * @property {field.field_builder} + */ + field_builder: null, + + /** + * Raised when `dirty` state changes + * @event dirty-change + */ + + /** + * Raised after fields reset + * @event reset + */ + + /** + * Get field by name + * @param {string} name + */ + get_field: function(name) { + return this.fields.get(name); + }, + + /** + * Get all fields + * @return {Array.} + */ + get_fields: function() { + return this.fields.values; + }, + + /** + * Add field + * @param {IPA.field|Object|String} field + * Field or field spec + */ + add_field: function(field) { + field.container = this; + var built = this.field_builder.build_field(field); + this.register_field_listeners(built); + this.fields.put(field.name, built); + return built; + }, + + /** + * Add multiple fields + * @param {Array} fields + */ + add_fields: function(fields) { + + if (!fields) return []; + + var built = []; + for (var i=0; i