API Docs for: 1.0.0
Show:

File: Resources/public/js/views/fields/ez-selection-view.js

  1. /*
  2. * Copyright (C) eZ Systems AS. All rights reserved.
  3. * For full copyright and license information view LICENSE file distributed with this source code.
  4. */
  5. YUI.add('ez-selection-view', function (Y) {
  6. "use strict";
  7. /**
  8. * Provides the Selection View class
  9. *
  10. * @module ez-selection-view
  11. */
  12. Y.namespace('eZ');
  13.  
  14. /**
  15. * The selection view
  16. *
  17. * @namespace eZ
  18. * @class SelectionView
  19. * @constructor
  20. * @extends eZ.FieldView
  21. */
  22. Y.eZ.SelectionView = Y.Base.create('selectionView', Y.eZ.FieldView, [], {
  23. /**
  24. * Returns the value to be used in the template.
  25. *
  26. * @method _getFieldValue
  27. * @protected
  28. * @return {Array|String}
  29. */
  30. _getFieldValue: function () {
  31. var fieldValue = this.get('field').fieldValue, res,
  32. fieldDefinitionSettings = this.get('fieldDefinition').fieldSettings;
  33.  
  34. if ( fieldValue.length === 0 ) {
  35. return res;
  36. }
  37. if ( fieldDefinitionSettings.isMultiple ) {
  38. res = [];
  39. Y.Array.each(fieldValue, function (key) {
  40. res.push(fieldDefinitionSettings.options[key]);
  41. });
  42. } else {
  43. res = fieldDefinitionSettings.options[fieldValue];
  44. }
  45.  
  46. return res;
  47. },
  48.  
  49. /**
  50. * Returns isMultiple variable in the template
  51. *
  52. * @method _variables
  53. * @protected
  54. * @return Object
  55. */
  56. _variables: function () {
  57. return {
  58. "isMultiple": this.get('fieldDefinition').fieldSettings.isMultiple
  59. };
  60. },
  61. });
  62.  
  63. Y.eZ.FieldView.registerFieldView('ezselection', Y.eZ.SelectionView);
  64. });
  65.