Reusable Accessible Mapping Platform

API Docs for: 5.3.1
Show:

File: src/js/RAMP/Utils/bricks.js

  1. /*global console, define, $, jscolor, RColor, Base */
  2.  
  3. /**
  4. * Bricks is a static collection of form controls rolled into prototypical objects with extra functions available. The main purpose is to use them in the choice tree for adding datasets but they can be reused anywhere where form controls are required.
  5. * @module Utils
  6. * @submodule Bricks
  7. */
  8.  
  9. /**
  10. * Bricks is a static collection of form controls rolled into prototypical objects with extra functions available. The main purpose is to use them in the choice tree for adding datasets but they can be reused anywhere where form controls are required.
  11. *
  12. *
  13. * ####Imports RAMP Modules:
  14. * {{#crossLink "Util"}}{{/crossLink}}
  15. * {{#crossLink "TmplHelper"}}{{/crossLink}}
  16. * {{#crossLink "Array"}}{{/crossLink}}
  17. * {{#crossLink "Dictionary"}}{{/crossLink}}
  18. *
  19. * ####Uses RAMP Templates:
  20. * {{#crossLink "templates/bricks_template.json"}}{{/crossLink}}
  21. *
  22. *
  23. * @class Bricks
  24. * @static
  25. * @uses dojo/_base/lang
  26. *
  27. */
  28. define([
  29. /* Dojo */
  30. "dojo/_base/lang",
  31.  
  32. /* Text */
  33. "dojo/text!./templates/bricks_template.json",
  34.  
  35. /* Util */
  36. "utils/util", "utils/tmplHelper", "utils/array", "utils/dictionary"
  37. ],
  38. function (lang,
  39.  
  40. bricks_template,
  41.  
  42. UtilMisc, TmplHelper, UtilArray, UtilDict) {
  43. "use strict";
  44.  
  45. var Brick,
  46.  
  47. ButtonBrick,
  48. OkCancelButtonBrick,
  49.  
  50. MultiBrick,
  51.  
  52. ChoiceBrick,
  53.  
  54. DropDownBrick,
  55. ColorPickerBrick,
  56. SimpleInputBrick,
  57. FileInputBrick,
  58.  
  59. templates = JSON.parse(TmplHelper.stringifyTemplate(bricks_template));
  60.  
  61. /**
  62. * Generates a template node based on the name of the template and the data to be passed to the template engine. The set of brick templates is suppled to the {{#crossLink "TmplHelper"}}{{/crossLink}} module.
  63. *
  64. * @method template
  65. * @private
  66. * @param {String} key template name
  67. * @param {Object} data any data that should be passed to the template engine
  68. * @return {jObject} a generated template nodes
  69. */
  70. function template(key, data) {
  71. /*jshint validthis: true */
  72. return $(TmplHelper.template.call(this, key, data, templates)); // -> No Strict violation!
  73. }
  74.  
  75. /**
  76. * The basic Brick prototype with no special functions. A base from all other Bricks.
  77. * To instantiate, call {{#crossLink "Brick/new:method"}}{{/crossLink}} on the Brick prototype.
  78. *
  79. * ####Imports RAMP Modules:
  80. * {{#crossLink "Util"}}{{/crossLink}}
  81. * {{#crossLink "TmplHelper"}}{{/crossLink}}
  82. * {{#crossLink "Array"}}{{/crossLink}}
  83. * {{#crossLink "Dictionary"}}{{/crossLink}}
  84. *
  85. * ####Uses RAMP Templates:
  86. * {{#crossLink "templates/bricks_template.json"}}{{/crossLink}}
  87. *
  88. *
  89. * @class Brick
  90. * @constructor
  91. * @for Bricks
  92. * @static
  93. * @uses dojo/_base/lang
  94. *
  95. */
  96. Brick = Base.extend({
  97. /**
  98. * A Brick header.
  99. *
  100. * @property header
  101. * @for Brick
  102. * @private
  103. * @type {String}
  104. * @default ""
  105. */
  106.  
  107. /**
  108. * A CSS class of the Brick container node.
  109. *
  110. * @property containerClass
  111. * @private
  112. * @type {String}
  113. * @default ""
  114. */
  115.  
  116. /**
  117. * A name of the specific Brick template.
  118. *
  119. * @property template
  120. * @private
  121. * @type {String}
  122. * @default ""
  123. */
  124.  
  125. /**
  126. * An instructional text to be displayed.
  127. *
  128. * @property instructions
  129. * @private
  130. * @type {String}
  131. * @default ""
  132. */
  133.  
  134. /**
  135. * A collection of rules specifying what external conditions must be valid for the Brick to be enabled.
  136. * This is not used directly by the Brick itself, but instead by the external object manipulating a collection of Bricks.
  137. * Two types of rules possible: "all" and "any". Any additional properties needed can be specified.
  138. *
  139. * @property required
  140. * @type {Array}
  141. * @default null
  142. * @example
  143. *
  144. * [
  145. * {
  146. * type: "all",
  147. * check: ["serviceType", "serviceURL"]
  148. * }
  149. * ]
  150. */
  151.  
  152. /**
  153. * A set of rules specifying states Brick should be frozen.
  154. *
  155. * @property freezeStates
  156. * @private
  157. * @type {Array}
  158. * @default []
  159. * @example
  160. *
  161. * [
  162. * Bricks.Brick.state.SUCCESS,
  163. * Bricks.Brick.state.ERROR
  164. * ],
  165. */
  166.  
  167. /**
  168. * A default base template name.
  169. *
  170. * @property baseTemplate
  171. * @private
  172. * @type {String}
  173. * @default "default_base_template"
  174. */
  175.  
  176. /**
  177. * A default notice template name.
  178. *
  179. * @property noticeTemplate
  180. * @private
  181. * @type {String}
  182. * @default "default_brick_notice"
  183. */
  184.  
  185. /**
  186. * Indicates if the Brick is frozen and cannot be interacted with.
  187. *
  188. * @property _isFrozen
  189. * @private
  190. * @type {Boolean}
  191. * @default false
  192. */
  193.  
  194. /**
  195. * A collection of listeners to be notified of specified Brick events.
  196. *
  197. * @property _listeners
  198. * @private
  199. * @type {Object}
  200. * @default {}
  201. */
  202.  
  203. /**
  204. * A dictionary of possible Brick events.
  205. *
  206. * @property event
  207. * @type {Object}
  208. * @example
  209. * event: {
  210. * CHANGE: "brick/change"
  211. * }
  212. *
  213. */
  214. event: {
  215. /**
  216. * Published whenever a Brick undergoes some change.
  217. *
  218. * @event Bricks.Brick.event.CHANGE
  219. * @param data {Object} anything, usually result of calling getData() on the Brick
  220. */
  221. CHANGE: "brick/change"
  222. },
  223.  
  224. /**
  225. * A dictionary of Brick events.
  226. *
  227. * @property state
  228. * @type {Object}
  229. * @example
  230. * state: {
  231. * SUCCESS: "brick/success",
  232. * ERROR: "brick/error",
  233. * DEFAULT: "brick/default"
  234. * }
  235. */
  236. state: {
  237. SUCCESS: "brick/success",
  238. ERROR: "brick/error",
  239. DEFAULT: "brick/default"
  240. },
  241.  
  242. /**
  243. * Initializes the Brick by generating a specified template and setting defaults.
  244. *
  245. * @method new
  246. * @param {String} id specified id of the Brick
  247. * @param {Object} config a configuration object for the Brick
  248. * @param {String} [config.header] a Brick header
  249. * @param {String} [config.instructions] a configuration object for the Brick
  250. * @param {Array|Object} [config.required] collection of rules specifying what external conditions must be valid for the Brick to be enabled
  251. * @param {Array} [config.freezeStates] a set of rules specifying states Brick should be frozen
  252. * @param {String} [config.baseTemplate] a base template name to be used
  253. * @param {String} [config.noticeTemplate] a notice template name to be used
  254. * @param {String} [config.containerClass] a CSS class of the specific brick container
  255. * @param {String} [config.template] a name of the specific Brick template
  256. * @retun Brick
  257. * @chainable
  258. *
  259. */
  260. initialize: function (id, config) {
  261.  
  262. lang.mixin(this,
  263. {
  264. required: null,
  265. freezeStates: [],
  266. baseTemplate: "default_base_template",
  267. noticeTemplate: "default_brick_notice"
  268. },
  269. config,
  270. {
  271. id: id,
  272. _isFrozen: false,
  273. _listeners: {}
  274. }
  275. );
  276.  
  277. this.node = template(this.baseTemplate, this);
  278.  
  279. lang.mixin(this,
  280. {
  281. noticeNode: this.node.find(".brick-notice-placeholder")
  282. }
  283. );
  284.  
  285. if (this.required) {
  286. if (Array.isArray(this.required)) {
  287. this.required.forEach(function (req) {
  288. req.type = req.type ? req.type : "all";
  289. });
  290. } else {
  291. this.required.type = this.required.type ? this.required.type : "all";
  292. }
  293. }
  294.  
  295. },
  296.  
  297. /**
  298. * Notifies a listener of a Brick event.
  299. *
  300. * @method notify
  301. * @private
  302. * @param {String} eventName an eventName that should be reported
  303. * @param {Object} data a payload object to be passed along with the @event
  304. * @return {Brick} itself
  305. * @chainable
  306. */
  307. notify: function (eventName, data) {
  308. var that = this;
  309.  
  310. if (!this._listeners[eventName]) {
  311. this._listeners[eventName] = [];
  312. }
  313. this._listeners[eventName].forEach(function (listener) {
  314. listener.call(that, data);
  315. });
  316.  
  317. return this;
  318. },
  319.  
  320. /**
  321. * Sets a listener on the Brick for a specified eventName.
  322. *
  323. * @method on
  324. * @param {String} eventName an eventName to listen for
  325. * @param {Function} listener a callback function to be called
  326. * @return {Brick} itself
  327. * @chainable
  328. */
  329. on: function (eventName, listener) {
  330. if (!this._listeners[eventName]) {
  331. this._listeners[eventName] = [];
  332. }
  333. this._listeners[eventName].push(listener);
  334.  
  335. return this;
  336. },
  337.  
  338. /**
  339. * Sets the state of the Brick. Checks if the state being set is a freezing state and freezes/unfreezes the Brick.
  340. *
  341. * @method setState
  342. * @param {String} state a name of the state to set
  343. * @return {Brick} itself
  344. * @chainable
  345. */
  346. setState: function (state) {
  347. this.freeze(this.freezeStates.indexOf(state) !== -1);
  348. return this;
  349. },
  350.  
  351. /**
  352. * Display a (error) notice on the brick.
  353. *
  354. * @method displayNotice
  355. * @param {Object} notice object with notice data to be passed to the template
  356. * @param {String} [noticeTemplate] notice template name
  357. * @return {Brick} itself
  358. * @chainable
  359. */
  360. displayNotice: function (notice, noticeTemplate) {
  361. noticeTemplate = noticeTemplate || this.noticeTemplate;
  362.  
  363. if (notice) {
  364. this.noticeNode
  365. .empty()
  366. .append(
  367. template(noticeTemplate, notice)
  368. );
  369. } else {
  370. this.noticeNode.empty();
  371. }
  372.  
  373. return this;
  374. },
  375.  
  376. /**
  377. * Clears the Brick. This is an empty function. Bricks inheriting from this should override and provide their specific implementations.
  378. *
  379. * @method clear
  380. * @return {Brick} itself
  381. * @chainable
  382. */
  383. clear: function () {
  384. this.noticeNode.empty();
  385.  
  386. return this;
  387. },
  388.  
  389. /**
  390. * Checks if the brick is valid. This is an empty function. Bricks inheriting from this should override and provide their specific implementations.
  391. *
  392. * @method isValid
  393. * @return {Boolean} true if valid; false if not
  394. */
  395. isValid: function () {
  396. return true;
  397. },
  398.  
  399. /**
  400. * Sets Brick's data. This is an empty function. Bricks inheriting from this should override and provide their specific implementations.
  401. *
  402. * @method setData
  403. * @return {Brick} itself
  404. * @chainable
  405. */
  406. setData: function () {
  407. return this;
  408. },
  409.  
  410. /**
  411. * Returns Brick's data. Bricks inheriting from this should override and provide their one implementation and then call parent's getData method.
  412. *
  413. * @method getData
  414. * @param {Object} [payload] data to be returned
  415. * @param {Boolean} [wrap] indicates of the payload should be wrapped with a Brick's id; useful when collection information from several Bricks at once.
  416. * @return {Object} Brick's data
  417. */
  418. getData: function (payload, wrap) {
  419. var result = {};
  420.  
  421. payload = payload || {};
  422.  
  423. if (wrap) {
  424. result[this.id] = payload;
  425. } else {
  426. result = payload;
  427. }
  428.  
  429. return result;
  430. },
  431.  
  432. freeze: function (freeze) {
  433. this._isFrozen = freeze;
  434. this.disable(freeze, true);
  435. },
  436.  
  437. /**
  438. * Disables or re-enables the Brick.
  439. *
  440. * @method disable
  441. * @param {Boolean} disable true to disable; false to enable
  442. * @param {Boolean} force if true, disables the brick even if it's frozen
  443. * @chainable
  444. * @return {Brick} itself
  445. * @for Brick
  446. */
  447. disable: function (disable, force) {
  448. if (!this._isFrozen || force) {
  449. if (disable) {
  450. this.node
  451. // make the buttons appear and act as if they are disabled but still able to receive focus
  452. // it's needed so keyboard focus wouldn't fly away to the beginning of the page if the button is suddenly disabled
  453. .find("button")
  454. .addClass("disabled")
  455. .attr("aria-disabled", true)
  456. .end()
  457. .find("input, select")
  458. .attr("disabled", true);
  459. } else {
  460. this.node
  461. .find("button")
  462. .removeClass("disabled")
  463. .attr("aria-disabled", false)
  464. .end()
  465. .find("input, select")
  466. .attr("disabled", false);
  467. }
  468. }
  469.  
  470. return this;
  471. }
  472. });
  473.  
  474. /**
  475. * The MultiBrick prototype. Used as a container for multiple independent Bricks if they are required to be displayed side by side.
  476. * To instantiate, call {{#crossLink "MultiBrick/new:method"}}{{/crossLink}} on the MultiBrick prototype.
  477. *
  478. *
  479. * ####Imports RAMP Modules:
  480. * {{#crossLink "Util"}}{{/crossLink}}
  481. * {{#crossLink "TmplHelper"}}{{/crossLink}}
  482. * {{#crossLink "Array"}}{{/crossLink}}
  483. * {{#crossLink "Dictionary"}}{{/crossLink}}
  484. *
  485. * ####Uses RAMP Templates:
  486. * {{#crossLink "templates/bricks_template.json"}}{{/crossLink}}
  487. *
  488. *
  489. * @class MultiBrick
  490. * @for Bricks
  491. * @static
  492. * @uses dojo/_base/lang
  493. * @extends Brick
  494. *
  495. */
  496. MultiBrick = Brick.extend({
  497. /**
  498. * A CSS class of the MultiBrick container node.
  499. *
  500. * @property containerClass
  501. * @for MultiBrick
  502. * @private
  503. * @type {String}
  504. * @default "multi-brick-container"
  505. */
  506. /**
  507. * A name of the default MultiBrick template.
  508. *
  509. * @property template
  510. * @private
  511. * @type {String}
  512. * @default "default_multi_brick_template"
  513. */
  514.  
  515. /**
  516. * A collection of Brick objects to be displayed side by side in the MultiBrick.
  517. *
  518. * @property content
  519. * @private
  520. * @type {Array}
  521. * @default []
  522. */
  523. /**
  524. * A MultiBrick container node.
  525. *
  526. * @property multiContainer
  527. * @private
  528. * @type {Object}
  529. */
  530. /**
  531. * A dictionary of the initialized content Brick objects for easy lookup.
  532. *
  533. * @property contentBricks
  534. * @private
  535. * @type {Object}
  536. */
  537.  
  538. /**
  539. * Initializes the MutliBrick by generating a specified template and setting defaults.
  540. *
  541. * @method new
  542. * @param {String} id specified id of the MultiBrick
  543. * @param {Object} config a configuration object for the MultiBrick
  544. * @param {String} [config.content] a collection of bricks to be displayed in the MultiBrick
  545. * @param {String} [config.header] a Brick header
  546. * @param {String} [config.instructions] a configuration object for the Brick
  547. * @param {Array|Object} [config.required] collection of rules specifying what external conditions must be valid for the Brick to be enabled
  548. * @param {Array} [config.freezeStates] a set of rules specifying states Brick should be frozen
  549. * @param {String} [config.baseTemplate] a base template name to be used
  550. * @param {String} [config.noticeTemplate] a notice template name to be used
  551. * @param {String} [config.containerClass] a CSS class of the specific brick container
  552. * @param {String} [config.template] a name of the specific Brick template
  553. * @retun MultiBrick
  554. * @chainable
  555. */
  556. initialize: function (id, config) {
  557. var that = this;
  558.  
  559. lang.mixin(this,
  560. {
  561. template: "default_multi_brick_template",
  562. containerClass: "multi-brick-container",
  563. content: []
  564. }
  565. );
  566.  
  567. Brick.initialize.call(this, id, config);
  568.  
  569. lang.mixin(this,
  570. {
  571. multiContainer: this.node.find(".multi-container"),
  572. contentBricks: {}
  573. }
  574. );
  575.  
  576. // loop through the content and create Bricks and append them to the MultiBrick container
  577. this.content.forEach(function (contentItem) {
  578. var contentBrick = contentItem.type.new(contentItem.id, contentItem.config);
  579.  
  580. that.contentBricks[contentBrick.id] = contentBrick;
  581.  
  582. if (that.header) {
  583. contentBrick.node = $(
  584. contentBrick.node
  585. .prop('outerHTML').replace("<h3", "<h4").replace("</h3>", "</h4>")
  586. )
  587. ;
  588. }
  589.  
  590. that.multiContainer.append(contentBrick.node);
  591. });
  592. },
  593.  
  594. /**
  595. * Sets the state of the MultiBrick by setting states of the individual bricks inside the MultiBrick using their specific setState methods.
  596. *
  597. * @method setState
  598. * @param {String} state a name of the state to set
  599. * @return {MultiBrick} itself
  600. * @chainable
  601. */
  602. setState: function (state) {
  603. UtilDict.forEachEntry(this.contentBricks, function (key, brick) {
  604. brick.setState(state);
  605. });
  606.  
  607. return this;
  608. },
  609.  
  610. /**
  611. * Clears the MultiBrick by clearing of the individual bricks inside the MultiBrick using their specific clear methods.
  612. *
  613. * @method clear
  614. * @return {MultiBrick} itself
  615. * @chainable
  616. */
  617. clear: function () {
  618. UtilDict.forEachEntry(this.contentBricks, function (key, brick) {
  619. brick.clear();
  620. });
  621.  
  622. return this;
  623. },
  624.  
  625. /**
  626. * Checks if the MultiBrick is valid. It's valid only if all individual bricks inside it are valid.
  627. *
  628. * @method isValid
  629. * @return {Boolean} true if valid; false if not
  630. */
  631. isValid: function () {
  632. UtilDict.forEachEntry(this.contentBricks, function (key, brick) {
  633. if (!brick.isValid()) {
  634. return false;
  635. }
  636. });
  637.  
  638. return true;
  639. },
  640.  
  641. /**
  642. * Sets MultiBrick's data by setting data to the individual bricks inside it. Uses their own specific setData functions.
  643. * *
  644. * @method setData
  645. * @param {Object} data
  646. * @return {MultiBrick} itself
  647. * @chainable
  648. */
  649. setData: function (data) {
  650. UtilDict.forEachEntry(this.contentBricks, function (key, brick) {
  651. brick.setData(data);
  652. });
  653.  
  654. return this;
  655. },
  656.  
  657. /**
  658. * Returns MultiBrick's data by mixing together data of the individual bricks inside using their specific getData methods and then passing it to the Brick's getData method for potential wrapping.
  659. *
  660. * @method getData
  661. * @for MultiBrick
  662. * @param {Boolean} [wrap] indicates of the payload should be wrapped with a Brick's id; useful when collection information from several Bricks at once.
  663. * @return {Object} MultiBrick's data
  664. */
  665. getData: function (wrap) {
  666. var payload = {};
  667.  
  668. UtilDict.forEachEntry(this.contentBricks, function (key, brick) {
  669. lang.mixin(payload, brick.getData(true));
  670. });
  671.  
  672. return Brick.getData.call(this, payload, wrap);
  673. }
  674. });
  675.  
  676. /**
  677. * ButtonBrick is just a Brick with a button inside it. The button can be styled and can be assigned an onClick event.
  678. * To instantiate, call {{#crossLink "ButtonBrick/new:method"}}{{/crossLink}} on the ButtonBrick prototype.
  679. *
  680. *
  681. * ####Imports RAMP Modules:
  682. * {{#crossLink "Util"}}{{/crossLink}}
  683. * {{#crossLink "TmplHelper"}}{{/crossLink}}
  684. * {{#crossLink "Array"}}{{/crossLink}}
  685. * {{#crossLink "Dictionary"}}{{/crossLink}}
  686. *
  687. * ####Uses RAMP Templates:
  688. * {{#crossLink "templates/bricks_template.json"}}{{/crossLink}}
  689. *
  690. *
  691. * @class ButtonBrick
  692. * @for Bricks
  693. * @static
  694. * @uses dojo/_base/lang
  695. * @extends Brick
  696. *
  697. */
  698. ButtonBrick = Brick.extend({
  699. /**
  700. * A dictionary of possible ButtonBrick events. Add a CLICK event to the default Brick events.
  701. *
  702. * @property event
  703. * @for ButtonBrick
  704. * @type {Object}
  705. * @example
  706. * event: {
  707. * CHANGE: "brick/change",
  708. * CLICK: "buttonBrick/click"
  709. * }
  710. *
  711. */
  712. event: lang.mixin({}, Brick.event,
  713. {
  714. /**
  715. * Published whenever a ButtonBrick is clicked.
  716. *
  717. * @event Bricks.ButtonBrick.event.CLICK
  718. * @param data {Object} anything, usually result of calling getData() on the Brick
  719. */
  720. CLICK: "buttonBrick/click"
  721. }
  722. ),
  723.  
  724. /**
  725. * A CSS class of the MultiBrick container node.
  726. *
  727. * @property containerClass
  728. * @private
  729. * @type {String}
  730. * @default "button-brick-container"
  731. */
  732.  
  733. /**
  734. * A name of the default ButtonBrick template.
  735. *
  736. * @property template
  737. * @private
  738. * @type {String}
  739. * @default "default_button_brick_template"
  740. */
  741. /**
  742. * A CSS class of the button.
  743. *
  744. * @property buttonClass
  745. * @private
  746. * @type {String}
  747. * @default "btn-primary"
  748. */
  749. /**
  750. * A button label.
  751. *
  752. * @property label
  753. * @private
  754. * @type {String}
  755. * @default "Ok"
  756. */
  757.  
  758. /**
  759. * Initializes the ButtonBrick by generating a specified template and setting defaults. Also sets a click listener on the template button.
  760. * ButtonBrick is a simple button in the Brick container.
  761. *
  762. * @method new
  763. * @param {String} id specified id of the Brick
  764. * @param {Object} config a configuration object for the Brick
  765. * @param {String} [config.header] a Brick header
  766. * @param {String} [config.instructions] a configuration object for the Brick
  767. * @param {Array|Object} [config.required] collection of rules specifying what external conditions must be valid for the Brick to be enabled
  768. * @param {Array} [config.freezeStates] a set of rules specifying states Brick should be frozen
  769. * @param {String} [config.baseTemplate] a base template name to be used
  770. * @param {String} [config.noticeTemplate] a notice template name to be used
  771. * @param {String} [config.containerClass] a CSS class of the specific brick container
  772. * @param {String} [config.template] a name of the specific Brick template
  773. * @param {String} [config.buttonClass] a CSS class of the button in the ButtonBrick
  774. * @param {String} [config.label] a button label
  775. * @chainable
  776. * @return {ButtonBrick}
  777. */
  778. initialize: function (id, config) {
  779. var that = this;
  780.  
  781. lang.mixin(this,
  782. {
  783. template: "default_button_brick_template",
  784. containerClass: "button-brick-container",
  785. buttonClass: "btn-primary",
  786. label: "Ok"
  787. }
  788. );
  789.  
  790. Brick.initialize.call(this, id, config);
  791.  
  792. this.node.on("click", "button:not(.disabled)", function () {
  793. that.notify(that.event.CLICK, null);
  794. });
  795. },
  796.  
  797. /**
  798. * Returns true. ButtonBrick is always valid
  799. *
  800. * @method isValid
  801. * @return {Boolean} true
  802. */
  803. isValid: function () {
  804. return true;
  805. },
  806.  
  807. /**
  808. * Returns ButtonBrick's data. Pretty useless function when you think of it. Just returns the data of the Brick prototype which is empty.
  809. *
  810. * @method getData
  811. * @for ButtonBrick
  812. * @param {Boolean} [wrap] indicates of the payload should be wrapped with a Brick's id; useful when collection information from several Bricks at once.
  813. * @return {Object} ButtonBrick's data
  814. */
  815. getData: function (wrap) {
  816. var payload = {};
  817.  
  818. return Brick.getData.call(this, payload, wrap);
  819. }
  820. });
  821. /**
  822. * The OkCancelButtonBrick prototype. A MultiBrick with two ButtonBricks displayed side by side and styled as OK and Cancel buttons.
  823. * To instantiate, call {{#crossLink "OkCancelButtonBrick/new:method"}}{{/crossLink}} on the OkCancelButtonBrick prototype.
  824. *
  825. *
  826. * ####Imports RAMP Modules:
  827. * {{#crossLink "Util"}}{{/crossLink}}
  828. * {{#crossLink "TmplHelper"}}{{/crossLink}}
  829. * {{#crossLink "Array"}}{{/crossLink}}
  830. * {{#crossLink "Dictionary"}}{{/crossLink}}
  831. *
  832. * ####Uses RAMP Templates:
  833. * {{#crossLink "templates/bricks_template.json"}}{{/crossLink}}
  834. *
  835. *
  836. * @class OkCancelButtonBrick
  837. * @for Bricks
  838. * @static
  839. * @uses dojo/_base/lang
  840. * @extends MultiBrick
  841. */
  842. OkCancelButtonBrick = MultiBrick.extend({
  843. /**
  844. * A dictionary of possible OkCancelButtonBrick events. Adds a OK_CLICK and CANCEL_CLICK events to the default ButtonBrick events.
  845. *
  846. * @property event
  847. * @for OkCancelButtonBrick
  848. * @type {Object}
  849. * @example
  850. * event: {
  851. * CHANGE: "brick/change",
  852. * CLICK: "buttonBrick/click",
  853. * OK_CLICK: "okCancelButtonBrick/okClick",
  854. * CANCEL_CLICK: "okCancelButtonBrick/cancelClick"
  855. * }
  856. *
  857. */
  858. event: lang.mixin({},
  859. MultiBrick.event,
  860. ButtonBrick.event,
  861. {
  862. /**
  863. * Published whenever an OK button of the OkCancelButtonBrick is clicked.
  864. *
  865. * @event Bricks.OkCancelButtonBrick.event.OK_CLICK
  866. * @param data {Object} anything, usually result of calling getData() on the Brick
  867. */
  868. OK_CLICK: "okCancelButtonBrick/okClick",
  869. /**
  870. * Published whenever an Cancel button of the OkCancelButtonBrick is clicked
  871. *
  872. * @event Bricks.OkCancelButtonBrick.event.CANCEL_CLICK
  873. * @param data {Object} anything, usually result of calling getData() on the Brick
  874. */
  875. CANCEL_CLICK: "okCancelButtonBrick/cancelClick"
  876. }
  877. ),
  878.  
  879. /**
  880. * A CSS class of the OkCancelButtonBrick container node.
  881. *
  882. * @property containerClass
  883. * @private
  884. * @type {String}
  885. * @default "okcancelbutton-brick-container"
  886. */
  887. /**
  888. * Default id of the OK button of the Brick, cannot be changed.
  889. *
  890. * @property okButtonId
  891. * @private
  892. * @type {String}
  893. * @default "okButton"
  894. */
  895.  
  896. /**
  897. * Default id of the cancel button of the Brick, cannot be changed.
  898. *
  899. * @property cancelButtonId
  900. * @private
  901. * @type {String}
  902. * @default "cancelButton"
  903. */
  904.  
  905. /**
  906. * Default id of the cancel button of the Brick, cannot be changed.
  907. *
  908. * @property cancelButtonId
  909. * @private
  910. * @type {String}
  911. * @default "cancelButton"
  912. */
  913. /**
  914. * Reverses the default visual order of OK, Cancel button to Cancel, OK.
  915. *
  916. * @property reverseOrder
  917. * @private
  918. * @type {Boolean}
  919. * @default "false"
  920. */
  921.  
  922. okButtonId: "okButton",
  923. cancelButtonId: "cancelButton",
  924.  
  925. /**
  926. * Initializes the OkCancelButtonBrick by generating a specified template and setting defaults. Also sets a click listener on the template button.
  927. * OkCancelButtonBrick is a brick with two preset buttons: OK and Cancel.
  928. * Button container classes are predefined as "ok-button-brick-container" and "cancel-button-brick-container"
  929. *
  930. * @method new
  931. * @for OkCancelButtonBrick
  932. * @param {String} id specified id of the Brick
  933. * @param {Object} config a configuration object for the Brick
  934. * @param {String} [config.header] a Brick header
  935. * @param {String} [config.instructions] a configuration object for the Brick
  936. * @param {Array|Object} [config.required] collection of rules specifying what external conditions must be valid for the Brick to be enabled
  937. * @param {Array} [config.freezeStates] a set of rules specifying states Brick should be frozen
  938. * @param {String} [config.baseTemplate] a base template name to be used
  939. * @param {String} [config.noticeTemplate] a notice template name to be used
  940. * @param {String} [config.containerClass] a CSS class of the specific brick container
  941. * @param {String} [config.template] a name of the specific Brick template
  942. * @param {String} [config.buttonClass] a CSS class of the button in the OkCancelButtonBrick
  943. * @param {String} [config.okLabel] an OK button label
  944. * @param {String} [config.cancelLabel] a Cancel button label
  945. * @param {String} [config.okButtonClass] an OK button CSS class
  946. * @param {String} [config.cancelButtonClass] a Cancel button CSS class
  947. * @param {String} [config.okFreezeStates] an OK button freeze states
  948. * @param {String} [config.cancelFreezeStates] a Cancel button freeze states
  949. * @param {String} [config.reverseOrder] reverses the default visual order of OK, Cancel button to Cancel, OK.
  950. * @chainable
  951. * @return {OkCancelButtonBrick}
  952. */
  953. initialize: function (id, config) {
  954. var that = this,
  955. newConfig;
  956.  
  957. // generating a MultiBrick config with two buttons
  958. newConfig =
  959. {
  960. //template: "default_okcancelbutton_brick_template",
  961. containerClass: "okcancelbutton-brick-container",
  962. header: config.header,
  963. content: [
  964. {
  965. id: this.okButtonId,
  966. type: ButtonBrick,
  967. config: {
  968. label: config.okLabel,
  969. containerClass: "ok-button-brick-container",
  970. buttonClass: "ok-btn " + (config.okButtonClass || "btn-sm btn-primary"),
  971. freezeStates: config.okFreezeStates || []
  972. }
  973. },
  974. {
  975. id: this.cancelButtonId,
  976. type: ButtonBrick,
  977. config: {
  978. label: config.cancelLabel,
  979. containerClass: "cancel-button-brick-container",
  980. buttonClass: "cancel-btn " + (config.cancelButtonClass || "btn-sm button-none"),
  981. freezeStates: config.cancelFreezeStates || []
  982. }
  983. }
  984. ],
  985. required: config.required
  986. };
  987.  
  988. if (config.reverseOrder) {
  989. newConfig.content.reverse();
  990. }
  991.  
  992. MultiBrick.initialize.call(this, id, newConfig);
  993.  
  994. lang.mixin(this,
  995. {
  996. okButtonBrick: this.contentBricks[this.okButtonId],
  997. cancelButtonBrick: this.contentBricks[this.cancelButtonId]
  998. }
  999. );
  1000.  
  1001. // setting event listeners on individual ButtonBricks, not button nodes directly
  1002. this.okButtonBrick.on(this.event.CLICK, function () {
  1003. that.notify(that.event.OK_CLICK, null);
  1004. that.notify(that.event.CLICK, null);
  1005. });
  1006.  
  1007. this.cancelButtonBrick.on(this.event.CLICK, function () {
  1008. that.notify(that.event.CANCEL_CLICK, null);
  1009. that.notify(that.event.CLICK, null);
  1010. });
  1011. }
  1012. });
  1013.  
  1014. /**
  1015. * The ChoiceBrick prototype. Provides a user the ability to choose a single item among several.
  1016. * To instantiate, call {{#crossLink "ChoiceBrick/new:method"}}{{/crossLink}} on the ChoiceBrick prototype.
  1017. *
  1018. *
  1019. * ####Imports RAMP Modules:
  1020. * {{#crossLink "Util"}}{{/crossLink}}
  1021. * {{#crossLink "TmplHelper"}}{{/crossLink}}
  1022. * {{#crossLink "Array"}}{{/crossLink}}
  1023. * {{#crossLink "Dictionary"}}{{/crossLink}}
  1024. *
  1025. * ####Uses RAMP Templates:
  1026. * {{#crossLink "templates/bricks_template.json"}}{{/crossLink}}
  1027. *
  1028. *
  1029. * @class ChoiceBrick
  1030. * @for Bricks
  1031. * @static
  1032. * @uses dojo/_base/lang
  1033. * @extends Brick
  1034. */
  1035. ChoiceBrick = Brick.extend({
  1036. /**
  1037. * A CSS class of the MultiBrick container node.
  1038. *
  1039. * @property containerClass
  1040. * @private
  1041. * @for ChoiceBrick
  1042. * @type {String}
  1043. * @default "choice-brick-container"
  1044. */
  1045.  
  1046. /**
  1047. * A name of the default ButtonBrick template.
  1048. *
  1049. * @property template
  1050. * @private
  1051. * @type {String}
  1052. * @default "default_choice_brick_template"
  1053. */
  1054. /**
  1055. * Indicates which choice is currently selected
  1056. *
  1057. * @property selectedChoice
  1058. * @private
  1059. * @type {String}
  1060. * @default null
  1061. */
  1062. /**
  1063. * Indicates if the user made the selection or it was made programmatically
  1064. *
  1065. * @property userSelected
  1066. * @private
  1067. * @type {Boolean}
  1068. * @default false
  1069. */
  1070.  
  1071. /**
  1072. * A collection of choices that will be offered to the user. At least two choices are required for this Brick to have any use at all.
  1073. *
  1074. * @property choices
  1075. * @private
  1076. * @type {Array}
  1077. * @example
  1078. * [
  1079. * {
  1080. * key: "ie9",
  1081. * value: "IE9"
  1082. * },
  1083. * {
  1084. * key: "chrome",
  1085. * value: "Chrome"
  1086. * }
  1087. * ]
  1088. */
  1089.  
  1090. /**
  1091. * Initializes the ChoiceBrick by generating a specified template and setting defaults. Also sets a click listener on the template button.
  1092. * The ChoiceBrick prototype. Provides a user the ability to choose a single item among several.
  1093. *
  1094. * @method new
  1095. * @param {String} id specified id of the Brick
  1096. * @param {Object} config a configuration object for the Brick
  1097. * @param {String} [config.header] a Brick header
  1098. * @param {String} [config.instructions] a configuration object for the Brick
  1099. * @param {Array|Object} [config.required] collection of rules specifying what external conditions must be valid for the Brick to be enabled
  1100. * @param {Array} [config.freezeStates] a set of rules specifying states Brick should be frozen
  1101. * @param {String} [config.baseTemplate] a base template name to be used
  1102. * @param {String} [config.noticeTemplate] a notice template name to be used
  1103. * @param {String} [config.containerClass] a CSS class of the specific brick container
  1104. * @param {String} [config.template] a name of the specific Brick template
  1105. * @param {Array} [config.choices] a set of choices that will be presented to the user
  1106. * @chainable
  1107. * @return {ChoiceBrick}
  1108. */
  1109. initialize: function (id, config) {
  1110. var that = this;
  1111.  
  1112. lang.mixin(this,
  1113. {
  1114. template: "default_choice_brick_template",
  1115. containerClass: "choice-brick-container"
  1116. }
  1117. );
  1118.  
  1119. Brick.initialize.call(this, id, config);
  1120.  
  1121. lang.mixin(this,
  1122. {
  1123. selectedChoice: "",
  1124. userSelected: false
  1125. }
  1126. );
  1127.  
  1128. this.choiceButtons = this.node.find(".btn-choice");
  1129.  
  1130. this.node.on("click", ".btn-choice:not(.button-pressed)", function (event) {
  1131. var choiceKey = $(event.currentTarget).data("key");
  1132. that.setChoice(choiceKey, true);
  1133. });
  1134. },
  1135.  
  1136. /**
  1137. * Sets the choice of the ChoiceBrick.
  1138. *
  1139. * @method setChoice
  1140. * @param {String} choiceKey string value of the choice to be selected
  1141. * @param {Boolean} userSelected boolean value indicating if the user is the source of the selection
  1142. * @return {ChoiceBrick} itself
  1143. * @chainable
  1144. */
  1145. setChoice: function (choiceKey, userSelected) {
  1146. // only set choice if it differs from the current one
  1147. if (choiceKey !== this.selectedChoice || (userSelected ? true : false) !== this.userSelected) {
  1148.  
  1149. this.userSelected = userSelected ? true : false;
  1150. this.selectedChoice = choiceKey;
  1151.  
  1152. this.choiceButtons
  1153. .removeClass("button-pressed")
  1154. .filter("[data-key='" + choiceKey + "']")
  1155. .addClass("button-pressed");
  1156.  
  1157. console.log("ChoiceBrick-" + this.id, ":", this.selectedChoice, "; userSelected:", this.userSelected);
  1158.  
  1159. this.notify(this.event.CHANGE, this.getData());
  1160. }
  1161.  
  1162. return this;
  1163. },
  1164.  
  1165. /**
  1166. * Checks if the option was selected by the user or not.
  1167. *
  1168. * @method isUserSelected
  1169. * @return {Boolean} true if the option was selected by the user; false, otherwise
  1170. * @return {ChoiceBrick} itself
  1171. * @chainable
  1172. */
  1173. isUserSelected: function () {
  1174. return this.userSelected;
  1175. },
  1176.  
  1177. /**
  1178. * Clears the ChoiceBrick by reseting selectedChoice to an empty string and userSelected to false.
  1179. *
  1180. * @method clear
  1181. * @return {ChoiceBrick} itself
  1182. * @chainable
  1183. */
  1184. clear: function () {
  1185. this.setChoice("", false);
  1186.  
  1187. Brick.clear.call(this);
  1188.  
  1189. return this;
  1190. },
  1191.  
  1192. /**
  1193. * Checks if the brick is valid. The ChoiceBrick is considered valid if selectedChoice is not an empty String.
  1194. *
  1195. * @method isValid
  1196. * @return {Boolean} true if valid; false if not
  1197. */
  1198. isValid: function () {
  1199. return this.selectedChoice !== "";
  1200. },
  1201.  
  1202. /**
  1203. * Sets ChoiceBrick's data. First calls setChoice and calls set data on the Brick prototype.
  1204. *
  1205. * @method setData
  1206. * @param {Object} data a wrapper object for the data to be set.
  1207. * @return {ChoiceBrick} itself
  1208. * @chainable
  1209. */
  1210. setData: function (data) {
  1211. this.setChoice(data.selectedChoice, data.userSelected);
  1212.  
  1213. Brick.setData.call(data);
  1214.  
  1215. return this;
  1216. },
  1217.  
  1218. /**
  1219. * Returns ChoiceBrick's data.
  1220. *
  1221. * @method getData
  1222. * @for ChoiceBrick
  1223. * @param {Boolean} [wrap] indicates of the payload should be wrapped with a Brick's id; useful when collection information from several Bricks at once.
  1224. * @return {Object} A wrapper object around two properties: selectedChoice and userSelected
  1225. */
  1226. getData: function (wrap) {
  1227. var payload = {
  1228. selectedChoice: this.selectedChoice,
  1229. userSelected: this.userSelected
  1230. };
  1231.  
  1232. return Brick.getData.call(this, payload, wrap);
  1233. }
  1234. });
  1235.  
  1236. /**
  1237. * The SimpleInputBrick prototype. Provides a control for a simple text input. Can be potentially extended to serve more specific purposes.
  1238. * To instantiate, call {{#crossLink "SimpleInputBrick/new:method"}}{{/crossLink}} on the SimpleInputBrick prototype.
  1239. *
  1240. *
  1241. * ####Imports RAMP Modules:
  1242. * {{#crossLink "Util"}}{{/crossLink}}
  1243. * {{#crossLink "TmplHelper"}}{{/crossLink}}
  1244. * {{#crossLink "Array"}}{{/crossLink}}
  1245. * {{#crossLink "Dictionary"}}{{/crossLink}}
  1246. *
  1247. * ####Uses RAMP Templates:
  1248. * {{#crossLink "templates/bricks_template.json"}}{{/crossLink}}
  1249. *
  1250. *
  1251. * @class SimpleInputBrick
  1252. * @for Bricks
  1253. * @static
  1254. * @uses dojo/_base/lang
  1255. * @extends Brick
  1256. */
  1257. SimpleInputBrick = Brick.extend({
  1258. /**
  1259. * A CSS class of the SimpleInputBrick container node.
  1260. *
  1261. * @property containerClass
  1262. * @private
  1263. * @for SimpleInputBrick
  1264. * @type {String}
  1265. * @default "simpleinput-brick-container"
  1266. */
  1267.  
  1268. /**
  1269. * A name of the default SimpleInputBrick template.
  1270. *
  1271. * @property template
  1272. * @private
  1273. * @type {String}
  1274. * @default "default_simpleinput_brick_template"
  1275. */
  1276.  
  1277. /**
  1278. * An input field label. Invisible. Defaults to the Brick's header.
  1279. *
  1280. * @property label
  1281. * @private
  1282. * @type {String}
  1283. * @default ""
  1284. */
  1285. /**
  1286. * A placeholder to be displayed inside the input field.
  1287. *
  1288. * @property placeholder
  1289. * @private
  1290. * @type {String}
  1291. * @default ""
  1292. */
  1293.  
  1294. /**
  1295. * A string that is currently entered in the input field
  1296. *
  1297. * @property inputValue
  1298. * @private
  1299. * @type {String}
  1300. * @default ""
  1301. */
  1302. /**
  1303. * Indicates if the user entered text into the input field or it was entered programmatically
  1304. *
  1305. * @property userEntered
  1306. * @private
  1307. * @type {Boolean}
  1308. * @default false
  1309. */
  1310.  
  1311. /**
  1312. * Initializes the SimpleInputBrick by generating a specified template and setting defaults.
  1313. * This Brick fires a CHANGE event on every change inside the input field.
  1314. *
  1315. * @method new
  1316. * @param {String} id specified id of the Brick
  1317. * @param {Object} config a configuration object for the Brick
  1318. * @param {String} [config.header] a Brick header
  1319. * @param {String} [config.instructions] a configuration object for the Brick
  1320. * @param {Array|Object} [config.required] collection of rules specifying what external conditions must be valid for the Brick to be enabled
  1321. * @param {Array} [config.freezeStates] a set of rules specifying states Brick should be frozen
  1322. * @param {String} [config.baseTemplate] a base template name to be used
  1323. * @param {String} [config.noticeTemplate] a notice template name to be used
  1324. * @param {String} [config.containerClass] a CSS class of the specific brick container
  1325. * @param {String} [config.template] a name of the specific Brick template
  1326. * @param {String} [config.label] an input field label. Invisible. Defaults to the Brick's header
  1327. * @param {String} [config.placeholder] a placeholder to be displayed inside the input field
  1328. * @retun SimpleInputBrick
  1329. * @chainable
  1330. *
  1331. */
  1332. initialize: function (id, config) {
  1333. var that = this;
  1334.  
  1335. lang.mixin(this,
  1336. {
  1337. template: "default_simpleinput_brick_template",
  1338. containerClass: "simpleinput-brick-container",
  1339. guid: UtilMisc.guid(),
  1340. label: config.header
  1341. }
  1342. );
  1343.  
  1344. Brick.initialize.call(this, id, config);
  1345.  
  1346. lang.mixin(this,
  1347. {
  1348. inputValue: "",
  1349. userEntered: false,
  1350. formGroup: this.node.find(".form-group"),
  1351. inputNode: this.node.find("input[type='text']#" + this.guid)
  1352. }
  1353. );
  1354.  
  1355. // setting a listener on the input field
  1356. this.inputNode.on("input", function (event) {
  1357. var value = $(event.target).val();
  1358. that.setInputValue(value, true);
  1359. });
  1360. },
  1361.  
  1362. /**
  1363. * Sets the current value of the input field.
  1364. *
  1365. * @method setInputValue
  1366. * @param {String} value string value to be entered into the input field
  1367. * @param {Boolean} userEntered boolean value indicating if the user is the source of the string value
  1368. * @return {SimpleInputBrick} itself
  1369. * @chainable
  1370. */
  1371. setInputValue: function (value, userEntered) {
  1372. this.userEntered = userEntered ? true : false;
  1373. this.inputValue = value;
  1374.  
  1375. // if user entered it, the text is already in the field;
  1376. // if not, need to populate the field
  1377. if (!userEntered) {
  1378. this.inputNode.val(value);
  1379. }
  1380.  
  1381. // fire change event
  1382. this.notify(this.event.CHANGE, this.getData());
  1383.  
  1384. return this;
  1385. },
  1386.  
  1387. /**
  1388. * Checks if the input value was entered by the user or not.
  1389. *
  1390. * @method isUserEntered
  1391. * @return {Boolean} true if the input value was entered by the user; false, otherwise
  1392. */
  1393. isUserEntered: function () {
  1394. return this.userEntered;
  1395. },
  1396.  
  1397. /**
  1398. * Sets the state of the Brick. Depending on the state, update the visual styles of the input field.
  1399. * Then call the Brick prototype setState function.
  1400. *
  1401. * @method setState
  1402. * @param {String} state a name of the state to set
  1403. * @return {SimpleInputBrick} itself
  1404. * @chainable
  1405. */
  1406. setState: function (state) {
  1407.  
  1408. switch (state) {
  1409. case this.state.SUCCESS:
  1410. this.formGroup.addClass("has-feedback has-success");
  1411. break;
  1412.  
  1413. case this.state.ERROR:
  1414. this.formGroup.addClass("has-feedback has-error");
  1415. break;
  1416.  
  1417. case this.state.DEFAULT:
  1418. this.formGroup.removeClass("has-feedback has-success has-error");
  1419. break;
  1420.  
  1421. default:
  1422. break;
  1423. }
  1424.  
  1425. Brick.setState.call(this, state);
  1426.  
  1427. return this;
  1428. },
  1429.  
  1430. /**
  1431. * Clears the Brick by setting inputValue to "" and userEntered to false.
  1432. *
  1433. * @method clear
  1434. * @return {SimpleInputBrick} itself
  1435. * @chainable
  1436. */
  1437. clear: function () {
  1438. this.setInputValue("", false);
  1439.  
  1440. Brick.clear.call(this);
  1441.  
  1442. return this;
  1443. },
  1444.  
  1445. /**
  1446. * Checks if the SimpleInputBrick is valid. It's considered valid if the input value is not an empty String.
  1447. *
  1448. * @method isValid
  1449. * @return {Boolean} true if valid; false if not
  1450. */
  1451. isValid: function () {
  1452. return this.inputValue !== "";
  1453. },
  1454.  
  1455. /**
  1456. * Sets SimpleInputBrick's data. First calls setInputValue and calls set data on the Brick prototype.
  1457. *
  1458. * @method setData
  1459. * @param {Object} data a wrapper object for the data to be set.
  1460. * @return {SimpleInputBrick} itself
  1461. * @chainable
  1462. */
  1463. setData: function (data) {
  1464. this.setInputValue(data.inputValue, data.userEntered);
  1465.  
  1466. Brick.setData.call(data);
  1467.  
  1468. return this;
  1469. },
  1470.  
  1471. /**
  1472. * Returns SimpleInputBrick's data.
  1473. *
  1474. * @method getData
  1475. * @for SimpleInputBrick
  1476. * @param {Boolean} [wrap] indicates of the payload should be wrapped with a Brick's id; useful when collection information from several Bricks at once.
  1477. * @return {Object} A wrapper object around two properties: inputValue and userEntered
  1478. */
  1479. getData: function (wrap) {
  1480. var payload = {
  1481. inputValue: this.inputValue,
  1482. userEntered: this.userEntered
  1483. };
  1484.  
  1485. return Brick.getData.call(this, payload, wrap);
  1486. }
  1487. });
  1488. /**
  1489. * The DropDownBrick prototype. Provides a dropdown control to choose an item from.
  1490. * To instantiate, call {{#crossLink "DropDownBrick/new:method"}}{{/crossLink}} on the DropDownBrick prototype.
  1491. *
  1492. *
  1493. * ####Imports RAMP Modules:
  1494. * {{#crossLink "Util"}}{{/crossLink}}
  1495. * {{#crossLink "TmplHelper"}}{{/crossLink}}
  1496. * {{#crossLink "Array"}}{{/crossLink}}
  1497. * {{#crossLink "Dictionary"}}{{/crossLink}}
  1498. *
  1499. * ####Uses RAMP Templates:
  1500. * {{#crossLink "templates/bricks_template.json"}}{{/crossLink}}
  1501. *
  1502. *
  1503. * @class DropDownBrick
  1504. * @for Bricks
  1505. * @static
  1506. * @uses dojo/_base/lang
  1507. * @extends Brick
  1508. */
  1509. DropDownBrick = Brick.extend({
  1510. /**
  1511. * A CSS class of the DropDownBrick container node.
  1512. *
  1513. * @property containerClass
  1514. * @private
  1515. * @for DropDownBrick
  1516. * @type {String}
  1517. * @default "dropdown-brick-container"
  1518. */
  1519.  
  1520. /**
  1521. * A name of the default DropDownBrick template.
  1522. *
  1523. * @property template
  1524. * @private
  1525. * @type {String}
  1526. * @default "default_dropdown_brick_template"
  1527. */
  1528. /**
  1529. * An input field label. Invisible. Defaults to the Brick's header.
  1530. *
  1531. * @property label
  1532. * @private
  1533. * @type {String}
  1534. * @default ""
  1535. */
  1536.  
  1537. /**
  1538. * A value of the currently selected item in the dropdown.
  1539. *
  1540. * @property dropDownValue
  1541. * @private
  1542. * @type {String}
  1543. * @default ""
  1544. */
  1545. /**
  1546. * A text string of the currently selected item in the dropdown.
  1547. *
  1548. * @property dropDownText
  1549. * @private
  1550. * @type {String}
  1551. * @default ""
  1552. */
  1553.  
  1554. /**
  1555. * Indicates if the user selected the option in the dropdown or it was selected programmatically.
  1556. *
  1557. * @property userSelected
  1558. * @private
  1559. * @type {Boolean}
  1560. * @default false
  1561. */
  1562.  
  1563. /**
  1564. * Initializes the DropDownBrick by generating a specified template and setting defaults.
  1565. * This Brick fires a CHANGE event on every change inside the dropdown.
  1566. *
  1567. * @method new
  1568. * @param {String} id specified id of the Brick
  1569. * @param {Object} config a configuration object for the Brick
  1570. * @param {String} [config.header] a Brick header
  1571. * @param {String} [config.instructions] a configuration object for the Brick
  1572. * @param {Array|Object} [config.required] collection of rules specifying what external conditions must be valid for the Brick to be enabled
  1573. * @param {Array} [config.freezeStates] a set of rules specifying states Brick should be frozen
  1574. * @param {String} [config.baseTemplate] a base template name to be used
  1575. * @param {String} [config.noticeTemplate] a notice template name to be used
  1576. * @param {String} [config.containerClass] a CSS class of the specific brick container
  1577. * @param {String} [config.template] a name of the specific Brick template
  1578. * @retun DropDownBrick
  1579. * @chainable
  1580. *
  1581. */
  1582. initialize: function (id, config) {
  1583. var that = this;
  1584.  
  1585. lang.mixin(this,
  1586. {
  1587. template: "default_dropdown_brick_template",
  1588. containerClass: "dropdown-brick-container",
  1589. guid: UtilMisc.guid(),
  1590. label: config.header
  1591. }
  1592. );
  1593.  
  1594. Brick.initialize.call(this, id, config);
  1595.  
  1596. lang.mixin(this,
  1597. {
  1598. dropDownValue: "",
  1599. dropDownText: "",
  1600. userSelected: false,
  1601. selectNode: this.node.find("select#" + this.guid)
  1602. }
  1603. );
  1604.  
  1605. // setting event listener on <select> node; "change" is the most appropriate
  1606. // https://developer.mozilla.org/en-US/docs/Web/Events/change
  1607. this.selectNode.on("change", function () {
  1608. var option = that.selectNode.find("option:selected");
  1609.  
  1610. that.setDropDownValue(option, true);
  1611. });
  1612.  
  1613. if (this.options) {
  1614. this.setDropDownOptions(this.options);
  1615. }
  1616. },
  1617.  
  1618. /**
  1619. * Selects the option whose value is provided in selectedOption param;
  1620. *
  1621. * @method selectOption
  1622. * @param {String} selectedOption string value to be selected in the dropdown
  1623. * @param {Boolean} userSelected boolean value indicating if the user is the source of the string value
  1624. * @return {DropDownBrick} itself
  1625. * @chainable
  1626. */
  1627. selectOption: function (selectedOption, userSelected) {
  1628. var option = this.selectNode.find("option[value='" + selectedOption + "']");
  1629.  
  1630. this.selectNode.val(selectedOption);
  1631. this.setDropDownValue(option, userSelected);
  1632.  
  1633. return this;
  1634. },
  1635.  
  1636. /**
  1637. * Stores selected option's text and value and notifies any listeners of the change.
  1638. * Internal should not be called from outside.
  1639. *
  1640. * @method setDropDownValue
  1641. * @private
  1642. * @param {String} option string value to be selected in the dropdown
  1643. * @param {Boolean} userSelected boolean value indicating if the user is the source of the string value
  1644. * @return {DropDownBrick} itself
  1645. * @chainable
  1646. */
  1647. setDropDownValue: function (option, userSelected) {
  1648. var value = option.val(),
  1649. text = option.find("option:selected").text();
  1650.  
  1651. this.userSelected = userSelected ? true : false;
  1652. this.dropDownValue = value;
  1653. this.dropDownText = text;
  1654.  
  1655. this.notify(this.event.CHANGE, this.getData());
  1656.  
  1657. return this;
  1658. },
  1659.  
  1660. /**
  1661. * Populates the drop down with provided set of options optionally replacing or appending them to the existing options.
  1662. *
  1663. * @method setDropDownOptions
  1664. * @param {Array} options an array of options(Object) in the form of { value: [value], text: [text] }
  1665. * @param {Boolean} [append] Indicates whether to append to or replace the existing options
  1666. * @return {DropDownBrick} itself
  1667. */
  1668. setDropDownOptions: function (options, append) {
  1669. UtilMisc.setSelectOptions(this.selectNode, options, append);
  1670.  
  1671. return this;
  1672. },
  1673.  
  1674. /**
  1675. * Checks if the option was selected by the user or not.
  1676. *
  1677. * @method isUserSelected
  1678. * @return {Boolean} true if the option was selected by the user; false, otherwise
  1679. * @return {DropDownBrick} itself
  1680. * @chainable
  1681. */
  1682. isUserSelected: function () {
  1683. return this.userSelected;
  1684. },
  1685.  
  1686. /**
  1687. * Clears the DropDownBrick by setting the selected option to "" and userSelected to false.
  1688. *
  1689. * @method clear
  1690. * @return {DropDownBrick} itself
  1691. * @chainable
  1692. */
  1693. clear: function () {
  1694. this.selectOption("");
  1695.  
  1696. Brick.clear.call(this);
  1697.  
  1698. return this;
  1699. },
  1700.  
  1701. /**
  1702. * Checks if the DropDownBrick is valid. It's considered valid if the selected option's value is not "".
  1703. *
  1704. * @method isValid
  1705. * @return {Boolean} true if valid; false if not
  1706. */
  1707. isValid: function () {
  1708. return this.dropDownValue !== "";
  1709. },
  1710.  
  1711. /**
  1712. * Sets DropDownBrick's data.
  1713. * data object may contain:
  1714. * - {Object} options an array of options to be added to the dropdown
  1715. * - {Boolean} append indicates whether to append or replace the exiting options
  1716. * - {String} selectedOption string value of the option that should be preselected (either old or newly added option)
  1717. * - {Boolean} userSelected boolean value indicating if the user is the source of the string value
  1718. *
  1719. * By default, after appending/replacing options, the first option will be selected unless specified otherwise.
  1720. *
  1721. * @method setData
  1722. * @param {Object} data a wrapper object for the data to be set.
  1723. * @return {DropDownBrick} itself
  1724. * @chainable
  1725. */
  1726. setData: function (data) {
  1727.  
  1728. if (data.options) {
  1729. this.setDropDownOptions(data.options, data.append);
  1730. }
  1731.  
  1732. if (data.selectedOption) {
  1733. this.selectOption(data.selectedOption, data.userSelected);
  1734. } else if (data.options && data.options.length > 0) {
  1735. this.selectOption(data.options[0].value, false);
  1736. }
  1737.  
  1738. Brick.setData.call(data);
  1739.  
  1740. return this;
  1741. },
  1742.  
  1743. /**
  1744. * Returns DropDownBrick's data.
  1745. *
  1746. * @method getData
  1747. * @for DropDownBrick
  1748. * @param {Boolean} [wrap] indicates of the payload should be wrapped with a Brick's id; useful when collection information from several Bricks at once.
  1749. * @return {Object} A wrapper object around two properties: inputValue and userEntered
  1750. */
  1751. getData: function (wrap) {
  1752. var payload = {
  1753. dropDownValue: this.dropDownValue,
  1754. dropDownText: this.dropDownText,
  1755. userSelected: this.userSelected
  1756. };
  1757.  
  1758. return Brick.getData.call(this, payload, wrap);
  1759. }
  1760. });
  1761. /**
  1762. * The ColorPickerBrick prototype. Provides a control to select a color.
  1763. * To instantiate, call {{#crossLink "ColorPickerBrick/new:method"}}{{/crossLink}} on the ColorPickerBrick prototype.
  1764. *
  1765. *
  1766. * ####Imports RAMP Modules:
  1767. * {{#crossLink "Util"}}{{/crossLink}}
  1768. * {{#crossLink "TmplHelper"}}{{/crossLink}}
  1769. * {{#crossLink "Array"}}{{/crossLink}}
  1770. * {{#crossLink "Dictionary"}}{{/crossLink}}
  1771. *
  1772. * ####Uses RAMP Templates:
  1773. * {{#crossLink "templates/bricks_template.json"}}{{/crossLink}}
  1774. *
  1775. *
  1776. * @class ColorPickerBrick
  1777. * @for Bricks
  1778. * @static
  1779. * @uses dojo/_base/lang
  1780. * @extends SimpleInputBrick
  1781. *
  1782. */
  1783. ColorPickerBrick = SimpleInputBrick.extend({
  1784. /**
  1785. * A CSS class of the ColorPickerBrick container node.
  1786. *
  1787. * @property containerClass
  1788. * @private
  1789. * @for ColorPickerBrick
  1790. * @type {String}
  1791. * @default "colorpicker-brick-container"
  1792. */
  1793.  
  1794. /**
  1795. * A name of the default ColorPickerBrick template.
  1796. *
  1797. * @property template
  1798. * @private
  1799. * @type {String}
  1800. * @default "default_colorpicker_brick_template"
  1801. */
  1802. /**
  1803. * Specifies positions of the actual color picker (square wheel) control
  1804. *
  1805. * @property pickerPosition
  1806. * @private
  1807. * @type {String}
  1808. * @default "top"
  1809. */
  1810.  
  1811. /**
  1812. * The actual node of the picker control.
  1813. *
  1814. * @property picker
  1815. * @private
  1816. * @type {Object}
  1817. */
  1818. /**
  1819. * A sample node that is coloured with the selected colour.
  1820. *
  1821. * @property pickerSwatch
  1822. * @private
  1823. * @type {String}
  1824. */
  1825. /**
  1826. * Initializes the ColorPickerBrick by generating a specified template and setting defaults.
  1827. * A random colour is picked as when this Brick is instantiated.
  1828. * This Brick fires a CHANGE event on every time the selected colour changes.
  1829. *
  1830. * @method new
  1831. * @param {String} id specified id of the Brick
  1832. * @param {Object} config a configuration object for the Brick
  1833. * @param {String} [config.header] a Brick header
  1834. * @param {String} [config.instructions] a configuration object for the Brick
  1835. * @param {Array|Object} [config.required] collection of rules specifying what external conditions must be valid for the Brick to be enabled
  1836. * @param {Array} [config.freezeStates] a set of rules specifying states Brick should be frozen
  1837. * @param {String} [config.baseTemplate] a base template name to be used
  1838. * @param {String} [config.noticeTemplate] a notice template name to be used
  1839. * @param {String} [config.containerClass] a CSS class of the specific brick container
  1840. * @param {String} [config.template] a name of the specific Brick template
  1841. * @param {String} [config.label] an input field label. Invisible. Defaults to the Brick's header
  1842. * @param {String} [config.placeholder] a placeholder to be displayed inside the input field
  1843. * @param {String} [config.pickerPosition] specifies positions of the actual color picker (square wheel) control
  1844. * @retun ColorPickerBrick
  1845. * @chainable
  1846. *
  1847. */
  1848. initialize: function (id, config) {
  1849. var that = this,
  1850. newConfig = {};
  1851.  
  1852. // mixin defaults with the given config
  1853. lang.mixin(newConfig,
  1854. {
  1855. template: "default_colorpicker_brick_template",
  1856. containerClass: "colorpicker-brick-container",
  1857. guid: UtilMisc.guid(),
  1858. label: config.header,
  1859.  
  1860. pickerPosition: "top"
  1861. },
  1862. config
  1863. );
  1864.  
  1865. SimpleInputBrick.initialize.call(this, id, newConfig);
  1866.  
  1867. lang.mixin(this,
  1868. {
  1869. picker: null,
  1870. pickerSwatch: this.node.find("#" + this.guid + "pickerSwatch")
  1871. }
  1872. );
  1873.  
  1874. // create the picker control
  1875. this.picker = new jscolor.color(this.inputNode[0], {
  1876. pickerPosition: "top",
  1877. styleElement: this.pickerSwatch[0], //this.guid + "pickerSwatch",
  1878. onImmediateChange: function () {
  1879. that.notify(that.event.CHANGE, that.getData());
  1880. }
  1881. });
  1882.  
  1883. // generate random colour
  1884. this.picker.fromString((new RColor()).get(true).slice(1));
  1885.  
  1886. this.pickerSwatch.on("click", function () {
  1887. that.picker.showPicker();
  1888. });
  1889.  
  1890. },
  1891.  
  1892. setInputValue: function () {
  1893. // chill
  1894. },/*
  1895.  
  1896. isValid: function () {
  1897. // TODO: if allowing color picker to start empty, need to check it's validity; otherwise, it's always valid
  1898. }*/
  1899.  
  1900. /*setData: function (data) {
  1901. //TODO: allow to set colors programmatically
  1902. //this.setInputValue(data.value, ?data.userEntered?);
  1903.  
  1904. return this;
  1905. },*/
  1906.  
  1907. /**
  1908. * Returns ColorPickerBrick's data.
  1909. * Returns different colour representations:
  1910. * - {String} hex hexcode
  1911. * - {Array} rgb array of rgb colours (from 0 to 1)
  1912. * - {Array} rgb_ array of rgb colours (from 0 to 255)
  1913. * - {Array} hsv array of hsv colours (from 0 to 1)
  1914. *
  1915. * @method getData
  1916. * @for ColorPickerBrick
  1917. * @param {Boolean} [wrap] indicates of the payload should be wrapped with a Brick's id; useful when collection information from several Bricks at once.
  1918. * @return {Object} A wrapper object around two properties: inputValue and userEntered
  1919. */
  1920. getData: function (wrap) {
  1921. var payload = {
  1922. hex: this.picker.toString(),
  1923. rgb: this.picker.rgb,
  1924. rgb_: this.picker.rgb.map(function (c) { return Math.round(c * 255); }), // also return a proper rgb
  1925. hsv: this.picker.hsv
  1926. };
  1927.  
  1928. return Brick.getData.call(this, payload, wrap);
  1929. }
  1930. });
  1931. /**
  1932. * The FileInputBrick prototype extends SimpleInputBrick. Provides a control to either select a local file or enter its URL.
  1933. * To instantiate, call {{#crossLink "FileInputBrick/new:method"}}{{/crossLink}} on the FileInputBrick prototype.
  1934. *
  1935. *
  1936. * ####Imports RAMP Modules:
  1937. * {{#crossLink "Util"}}{{/crossLink}}
  1938. * {{#crossLink "TmplHelper"}}{{/crossLink}}
  1939. * {{#crossLink "Array"}}{{/crossLink}}
  1940. * {{#crossLink "Dictionary"}}{{/crossLink}}
  1941. *
  1942. * ####Uses RAMP Templates:
  1943. * {{#crossLink "templates/bricks_template.json"}}{{/crossLink}}
  1944. *
  1945. *
  1946. * @class FileInputBrick
  1947. * @for Bricks
  1948. * @static
  1949. * @uses dojo/_base/lang
  1950. * @extends SimpleInputBrick
  1951. */
  1952. FileInputBrick = SimpleInputBrick.extend({
  1953. /**
  1954. * A CSS class of the FileInputBrick container node.
  1955. *
  1956. * @property containerClass
  1957. * @private
  1958. * @for FileInputBrick
  1959. * @type {String}
  1960. * @default "fileinput-brick-container"
  1961. */
  1962.  
  1963. /**
  1964. * A name of the default FileInputBrick template.
  1965. *
  1966. * @property template
  1967. * @private
  1968. * @type {String}
  1969. * @default "default_fileinput_brick_template"
  1970. */
  1971. /**
  1972. * A file object that is selected through FileAPI.
  1973. *
  1974. * @property fileValue
  1975. * @private
  1976. * @type {Object}
  1977. * @default null
  1978. */
  1979. /**
  1980. * A flag indicating if the user has selected the file or the file has been selected using some magical means.
  1981. *
  1982. * @property userSelected
  1983. * @private
  1984. * @type {Boolean}
  1985. * @default false
  1986. */
  1987. /**
  1988. * A browse files container node
  1989. *
  1990. * @property browseFilesContainer
  1991. * @private
  1992. * @type {Object}
  1993. */
  1994. /**
  1995. * A node of the file input control.
  1996. *
  1997. * @property fileNode
  1998. * @private
  1999. * @type {Object}
  2000. */
  2001. /**
  2002. * A node of the styled pseudo file input control that just looks nice and doesn't do anything.
  2003. *
  2004. * @property filePseudoNode
  2005. * @private
  2006. * @type {Object}
  2007. */
  2008.  
  2009. /**
  2010. * Initializes the FileInputBrick by generating a specified template and setting defaults.
  2011. * This Brick fires a CHANGE event on every change inside the input field and on every file selected.
  2012. *
  2013. * @method new
  2014. * @param {String} id specified id of the Brick
  2015. * @param {Object} config a configuration object for the Brick
  2016. * @param {String} [config.header] a Brick header
  2017. * @param {String} [config.instructions] a configuration object for the Brick
  2018. * @param {Array|Object} [config.required] collection of rules specifying what external conditions must be valid for the Brick to be enabled
  2019. * @param {Array} [config.freezeStates] a set of rules specifying states Brick should be frozen
  2020. * @param {String} [config.baseTemplate] a base template name to be used
  2021. * @param {String} [config.noticeTemplate] a notice template name to be used
  2022. * @param {String} [config.containerClass] a CSS class of the specific brick container
  2023. * @param {String} [config.template] a name of the specific Brick template
  2024. * @param {String} [config.label] an input field label. Invisible. Defaults to the Brick's header
  2025. * @param {String} [config.placeholder] a placeholder to be displayed inside the input field
  2026. * @retun FileInputBrick
  2027. * @chainable
  2028. *
  2029. */
  2030. initialize: function (id, config) {
  2031. var that = this,
  2032. newConfig = {};
  2033.  
  2034. // mixin defaults with the given config
  2035. lang.mixin(newConfig,
  2036. {
  2037. template: "default_fileinput_brick_template",
  2038. containerClass: "fileinput-brick-container",
  2039. guid: UtilMisc.guid(),
  2040. label: config.header
  2041. },
  2042. config
  2043. );
  2044.  
  2045. SimpleInputBrick.initialize.call(this, id, newConfig);
  2046.  
  2047. lang.mixin(this,
  2048. {
  2049. fileValue: null,
  2050. userSelected: false,
  2051. browseFilesContainer: this.node.find(".browse-files"),
  2052. fileNode: this.node.find("input[type='file']#" + this.guid + "realBrowse"),
  2053. filePseudoNode: this.node.find("#" + this.guid + "pseudoBrowse")
  2054. }
  2055. );
  2056.  
  2057. // style the pseudoBrowse control to act as a normal button control
  2058. UtilMisc.styleBrowseFilesButton(this.browseFilesContainer);
  2059.  
  2060. this.fileNode.on("change", function (event) {
  2061. var file = event.target.files[0];
  2062.  
  2063. that.setFileValue(file, true);
  2064. });
  2065. },
  2066.  
  2067. /**
  2068. * Sets the current value of the input field. In this case it's a file URL.
  2069. * If the URL is set, the returned file object is null.
  2070. *
  2071. * First calls setFileValue(null, false) to null the file object, then calls the prototype's setInputValue with the same parameters.
  2072. *
  2073. * @method setInputValue
  2074. * @param {String} value string value to be entered into the input field
  2075. * @param {Boolean} userEntered boolean value indicating if the user is the source of the string value
  2076. * @return {FileInputBrick} itself
  2077. * @chainable
  2078. */
  2079. setInputValue: function (value, userEntered) {
  2080. this.setFileValue(null, false);
  2081.  
  2082. SimpleInputBrick.setInputValue.call(this, value, userEntered);
  2083.  
  2084. return this;
  2085. },
  2086.  
  2087. /**
  2088. * Sets file value of the Brick. When setting file object, input value is set to "". If value is null, the form is reset.
  2089. *
  2090. * @method setFileValue
  2091. * @param {Object} value the selected file object
  2092. * @param {Boolean} userSelected boolean value indicating if the user selected the file
  2093. * @return {FileInputBrick} itself
  2094. * @chainable
  2095. */
  2096. setFileValue: function (value, userSelected) {
  2097. this.userSelected = userSelected ? true : false;
  2098. this.fileValue = value;
  2099. this.filePseudoNode.toggleClass("selected", this.fileValue ? true : false);
  2100.  
  2101. if (this.fileValue) {
  2102. SimpleInputBrick.setInputValue.call(this, this.fileValue.name, false);
  2103.  
  2104. this.notify(this.event.CHANGE, this.getData());
  2105. } else {
  2106. UtilMisc.resetFormElement(this.fileNode);
  2107. }
  2108.  
  2109. return this;
  2110. },
  2111.  
  2112. /**
  2113. * Checks if the file was selected by the user or not.
  2114. *
  2115. * @method isUserSelected
  2116. * @return {Boolean} true if the file was selected by the user; false, otherwise
  2117. */
  2118. isUserSelected: function () {
  2119. return this.userSelected;
  2120. },
  2121.  
  2122. /**
  2123. * Clears the Brick by setting inputValue to "" which sets fileValue to null and userEntered to false.
  2124. *
  2125. * @method clear
  2126. * @return {FileInputBrick} itself
  2127. * @chainable
  2128. */
  2129. clear: function () {
  2130. this.setInputValue("", false);
  2131.  
  2132. Brick.clear.call(this);
  2133.  
  2134. return this;
  2135. },
  2136.  
  2137. /**
  2138. * Checks if the FileInputBrick is valid. It's considered valid if the input value is not "" or a file value is not null.
  2139. *
  2140. * @method isValid
  2141. * @return {Boolean} true if valid; false if not
  2142. */
  2143. isValid: function () {
  2144. return SimpleInputBrick.isValid.call(this) || this.fileValue ? true : false;
  2145. },
  2146.  
  2147. /**
  2148. * Sets SimpleInputBrick's data. First calls setInputValue and calls set data on the Brick prototype.
  2149. * data object may contain:
  2150. * - {Object} fileValue a file object
  2151. * - {String} inputValue a input value (file URL)
  2152. * - {Boolean} userSelected boolean value indicating if the user is the source of the file value
  2153. * - {Boolean} userEntered boolean value indicating if the user is the source of the string value
  2154. *
  2155. * if both fileValue and inputValue are specified, only fileValue is used.
  2156. *
  2157. * @method setData
  2158. * @param {Object} data a wrapper object for the data to be set.
  2159. * @return {FileInputBrick} itself
  2160. * @chainable
  2161. */
  2162. setData: function (data) {
  2163. if (data.fileValue) {
  2164. this.setFileValue(data.fileValue, data.userSelected);
  2165. } else if (data.inputValue) {
  2166. this.setInputValue(data.inputValue, data.userEntered);
  2167. }
  2168.  
  2169. SimpleInputBrick.setData.call(data);
  2170.  
  2171. return this;
  2172. },
  2173.  
  2174. /**
  2175. * Returns FileInputBrick's data. Either a file object or a file URL will be returned along with the file name, not both.
  2176. *
  2177. * Returns an object:
  2178. * - {Object} fileValue file object if any was selected
  2179. * - {String} fileName derived file name
  2180. * - {Boolean} userSelected a flag indicating if the user has selected the file or typed the URL
  2181. *
  2182. * @method getData
  2183. * @for FileInputBrick
  2184. * @param {Boolean} [wrap] indicates of the payload should be wrapped with a Brick's id; useful when collection information from several Bricks at once.
  2185. * @return {Object} A wrapper object around two properties: inputValue and userEntered
  2186. */
  2187. getData: function (wrap) {
  2188. var payload = SimpleInputBrick.getData.call(this);
  2189.  
  2190. lang.mixin(payload,
  2191. {
  2192. fileValue: this.fileValue,
  2193. // derive the file name
  2194. fileName: this.fileValue ? this.fileValue.name : this.inputValue.split("/").pop(),
  2195. userSelected: this.userSelected
  2196. }
  2197. );
  2198.  
  2199. return Brick.getData.call(this, payload, wrap);
  2200. }
  2201. });
  2202.  
  2203. return {
  2204.  
  2205. /**
  2206. * The basic Brick prototype with no special functions. A base from all other Bricks.
  2207. *
  2208. * @for Bricks
  2209. * @property Brick
  2210. * @static
  2211. * @type Brick
  2212. */
  2213. Brick: Brick,
  2214.  
  2215. /**
  2216. * The MultiBrick prototype. Used as a container for multiple independent Bricks if they are required to be displayed side by side.
  2217. *
  2218. * @property MultiBrick
  2219. * @static
  2220. * @type MultiBrick
  2221. */
  2222. MultiBrick: MultiBrick,
  2223.  
  2224. /**
  2225. * The ButtonBrick prototype. A simple Brick with a button template.
  2226. *
  2227. * @property ButtonBrick
  2228. * @static
  2229. * @type ButtonBrick
  2230. */
  2231. ButtonBrick: ButtonBrick,
  2232. /**
  2233. * The OkCancelButtonBrick prototype. A MultiBrick with two ButtonBricks displayed side by side and styled as OK and Cancel buttons.
  2234. *
  2235. * @property OkCancelButtonBrick
  2236. * @static
  2237. * @type OkCancelButtonBrick
  2238. */
  2239. OkCancelButtonBrick: OkCancelButtonBrick,
  2240.  
  2241. /**
  2242. * The ChoiceBrick prototype. Provides a user the ability to choose a single item among several.
  2243. *
  2244. * @property ChoiceBrick
  2245. * @static
  2246. * @type ChoiceBrick
  2247. */
  2248. ChoiceBrick: ChoiceBrick,
  2249.  
  2250. /**
  2251. * The DropDownBrick prototype. Provides a dropdown control to choose an item from.
  2252. *
  2253. * @property DropDownBrick
  2254. * @static
  2255. * @type DropDownBrick
  2256. */
  2257. DropDownBrick: DropDownBrick,
  2258. /**
  2259. * The ColorPickerBrick prototype. Provides a control to select a color.
  2260. *
  2261. * @property ColorPickerBrick
  2262. * @static
  2263. * @type ColorPickerBrick
  2264. */
  2265. ColorPickerBrick: ColorPickerBrick,
  2266. /**
  2267. * The SimpleInputBrick prototype. Provides a control for a simple text input. Can be potentially extended to serve more specific purposes.
  2268. *
  2269. * @property SimpleInputBrick
  2270. * @static
  2271. * @type SimpleInputBrick
  2272. */
  2273. SimpleInputBrick: SimpleInputBrick,
  2274. /**
  2275. * The FileInputBrick prototype extends SimpleInputBrick. Provides a control to either select a local file or enter its URL.
  2276. *
  2277. * @property FileInputBrick
  2278. * @static
  2279. * @type FileInputBrick
  2280. */
  2281. FileInputBrick: FileInputBrick
  2282. };
  2283. });