123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- "use strict";
- /**
- * Licensed Materials - Property of IBM
- * IBM Cognos Products: Cognos Analytics
- * Copyright IBM Corp. 2015, 2016
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define(['jquery', 'underscore', 'q', 'bi/commons/ui/core/Class', 'bi/admin/nls/StringResource'], function ($, _, Q, Class, StringResource) {
- 'use strict'; //NOSONAR: meant to be strict
- var _singletonInstance = null;
- var MagicWand = Class.extend({
- _types: {
- 'searchInput': {
- 'query': 'input[type="search"]',
- 'ariaLabel': StringResource.get('editFilter'),
- 'module': 'bi/admin/common/ui/input/SearchInput'
- },
- 'radioBox': {
- 'query': 'input[type="radio"]',
- 'module': 'bi/admin/common/ui/input/RadioBox'
- },
- 'checkBox': {
- 'query': 'input[type="checkbox"]',
- 'module': 'bi/admin/common/ui/input/CheckBox'
- },
- 'button': {
- 'query': 'button',
- 'module': 'bi/admin/common/ui/input/Button'
- },
- 'testFlow': {
- 'query': '[data-bi-testflow]',
- 'module': 'bi/admin/common/ui/testflow/TestFlow'
- }
- },
- init: function init(options) {
- $.extend(this, options);
- },
- searchInput: function searchInput(scope) {
- var spec = this._types['searchInput'];
- return this._doTransform(spec, scope);
- },
- radioBox: function radioBox(scope) {
- var spec = this._types['radioBox'];
- return this._doTransform(spec, scope);
- },
- checkBox: function checkBox(scope) {
- var spec = this._types['checkBox'];
- return this._doTransform(spec, scope);
- },
- button: function button(scope) {
- var spec = this._types['button'];
- return this._doTransform(spec, scope);
- },
- testFlow: function testFlow(scope) {
- var spec = this._types['testFlow'];
- return this._doTransform(spec, scope);
- },
- all: function all(scope) {
- // May optimize the transform process with faster quering
- this.searchInput(scope);
- this.radioBox(scope);
- this.checkBox(scope);
- this.button(scope);
- },
- _doTransform: function _doTransform(spec, scope) {
- var deferred = Q.defer();
- var elements = $(spec.query, scope);
- elements.hide();
- require([spec.module], function (WidgetClass) {
- var widgets = [];
- elements.each(function (index, el) {
- var w;
- var $el = $(el);
- if (spec.ariaLabel) {
- $el.attr('aria-label', spec.ariaLabel);
- }
- var widgetName = $el.data('widgetName');
- if (widgetName) {
- w = $el.data(widgetName);
- if (w && w.refresh) {
- w.refresh();
- }
- } else {
- w = new WidgetClass({
- el: this,
- scope: scope
- });
- }
- widgets.push(w);
- });
- elements.show();
- deferred.resolve(widgets);
- });
- return deferred.promise;
- },
- transform: function transform() {// to do...
- }
- });
- var _static = {
- getInstance: function getInstance() {
- if (!_singletonInstance) {
- _singletonInstance = new MagicWand();
- }
- return _singletonInstance;
- }
- };
- return _static.getInstance();
- });
|