API Docs for: 1.0.0
Show:

File: Resources/public/js/views/fields/ez-keyword-editview.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-keyword-editview', function (Y) {
  6. "use strict";
  7. /**
  8. * Provides the field edit view for the keyword fields
  9. *
  10. * @module ez-keyword-editview
  11. */
  12. Y.namespace('eZ');
  13.  
  14. var FIELDTYPE_IDENTIFIER = 'ezkeyword';
  15.  
  16. /**
  17. * Keyword edit view
  18. *
  19. * @namespace eZ
  20. * @class KeywordEditView
  21. * @constructor
  22. * @extends eZ.FieldEditView
  23. */
  24. Y.eZ.KeywordEditView = Y.Base.create('keywordEditView', Y.eZ.FieldEditView, [], {
  25. events: {
  26. '.ez-keyword-input-ui input': {
  27. 'blur': 'validate',
  28. 'valuechange': 'validate'
  29. }
  30. },
  31.  
  32. /**
  33. * Validates the current input of keyword field
  34. *
  35. * @method validate
  36. */
  37. validate: function () {
  38. var validity = this._getInputValidity();
  39. if ( validity.valueMissing ) {
  40. this.set('errorStatus', Y.eZ.trans('this.field.is.required', {}, 'fieldedit'));
  41. } else {
  42. this.set('errorStatus', false);
  43. }
  44. },
  45.  
  46. /**
  47. * Defines the variables to imported in the field edit template for keyword
  48. *
  49. * @protected
  50. * @method _variables
  51. * @return {Object} containing isRequired
  52. */
  53. _variables: function () {
  54. var def = this.get('fieldDefinition');
  55. return {
  56. "isRequired": def.isRequired
  57. };
  58. },
  59.  
  60. /**
  61. * Returns the input validity state object for the input generated by
  62. * the keyword template
  63. *
  64. * See https://developer.mozilla.org/en-US/docs/Web/API/ValidityState
  65. *
  66. * @protected
  67. * @method _getInputValidity
  68. * @return {ValidityState}
  69. */
  70. _getInputValidity: function () {
  71. return this.get('container').one('.ez-keyword-input-ui input').get('validity');
  72. },
  73.  
  74. /**
  75. * Returns the currently filled keyword value
  76. *
  77. * @protected
  78. * @method _getFieldValue
  79. * @return String
  80. */
  81. _getFieldValue: function () {
  82. var tags = [],
  83. str = this.get('container').one('.ez-keyword-input-ui input').get('value');
  84.  
  85. if (str) {
  86. Y.Array.each(str.split(","), function (value) {
  87. tags.push(value.trim());
  88. });
  89. }
  90. return tags;
  91. }
  92. });
  93.  
  94. Y.eZ.FieldEditView.registerFieldEditView(
  95. FIELDTYPE_IDENTIFIER, Y.eZ.KeywordEditView
  96. );
  97. });
  98.