From dec7f98aa995b369f022813093ac88d0062e5089 Mon Sep 17 00:00:00 2001 From: Petr Vobornik Date: Wed, 12 Feb 2014 18:55:01 +0100 Subject: webui: ContainerMixin A mixin which implements widget storing logic. Similar logic is already implemented in details facet and dialog. Long term goal is to replace that with this one. Separating the logic into mixin makes it usable in other components. https://fedorahosted.org/freeipa/ticket/3903 Reviewed-By: Adam Misnyovszki --- install/ui/src/freeipa/widgets/ContainerMixin.js | 154 +++++++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 install/ui/src/freeipa/widgets/ContainerMixin.js (limited to 'install/ui') diff --git a/install/ui/src/freeipa/widgets/ContainerMixin.js b/install/ui/src/freeipa/widgets/ContainerMixin.js new file mode 100644 index 000000000..906d26266 --- /dev/null +++ b/install/ui/src/freeipa/widgets/ContainerMixin.js @@ -0,0 +1,154 @@ +/* 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', + '../ordered-map', + '../widget' + ], + function(declare, lang, on, builder, ordered_map, widget_mod) { + + /** + * Container Mixin + * + * Manages child widgets. + * + * @class widgets.ContainerMixin + */ + var ContainerMixin = declare([], { + + /** + * Childs + * @property {ordered_map} + */ + widgets: null, + + /** + * Builds widgets on add if not already built + * + * @property {widget.widget_builder} + */ + widget_builder: null, + + /** + * Raised after `create` + * @event create + */ + + /** + * Raised after 'clear_widgets` + * @event clear + */ + + /** + * Raised before `clear_widgets` + * + * - `clear_widgets` can be aborted by setting `event.abort=true` + * + * @event pre-clear + */ + + /** + * Get widget by name + * @param {string} name + */ + get_widget: function(name) { + return this.widgets.get(name); + }, + + /** + * Get all widgets + * @return {Array.} + */ + get_widgets: function() { + return this.widgets.values; + }, + + /** + * Add widget + * @param {IPA.widget|Object|String} widget + * Field or widget spec + */ + add_widget: function(widget) { + widget.container = this; + var built = this.widget_builder.build_widget(widget); + + this.register_widget_listeners(widget); + this.widgets.put(widget.name, built); + return built; + }, + + /** + * Add multiple widgets + * @param {Array} widgets + */ + add_widgets: function(widgets) { + + if (!widgets) return []; + + var built = []; + for (var i=0; i