File: Resources/public/js/views/fields/ez-keyword-editview.js
- /*
- * Copyright (C) eZ Systems AS. All rights reserved.
- * For full copyright and license information view LICENSE file distributed with this source code.
- */
- YUI.add('ez-keyword-editview', function (Y) {
- "use strict";
- /**
- * Provides the field edit view for the keyword fields
- *
- * @module ez-keyword-editview
- */
- Y.namespace('eZ');
-
- var FIELDTYPE_IDENTIFIER = 'ezkeyword';
-
- /**
- * Keyword edit view
- *
- * @namespace eZ
- * @class KeywordEditView
- * @constructor
- * @extends eZ.FieldEditView
- */
- Y.eZ.KeywordEditView = Y.Base.create('keywordEditView', Y.eZ.FieldEditView, [], {
- events: {
- '.ez-keyword-input-ui input': {
- 'blur': 'validate',
- 'valuechange': 'validate'
- }
- },
-
- /**
- * Validates the current input of keyword field
- *
- * @method validate
- */
- validate: function () {
- var validity = this._getInputValidity();
- if ( validity.valueMissing ) {
- this.set('errorStatus', Y.eZ.trans('this.field.is.required', {}, 'fieldedit'));
- } else {
- this.set('errorStatus', false);
- }
- },
-
- /**
- * Defines the variables to imported in the field edit template for keyword
- *
- * @protected
- * @method _variables
- * @return {Object} containing isRequired
- */
- _variables: function () {
- var def = this.get('fieldDefinition');
- return {
- "isRequired": def.isRequired
- };
- },
-
- /**
- * Returns the input validity state object for the input generated by
- * the keyword template
- *
- * See https://developer.mozilla.org/en-US/docs/Web/API/ValidityState
- *
- * @protected
- * @method _getInputValidity
- * @return {ValidityState}
- */
- _getInputValidity: function () {
- return this.get('container').one('.ez-keyword-input-ui input').get('validity');
- },
-
- /**
- * Returns the currently filled keyword value
- *
- * @protected
- * @method _getFieldValue
- * @return String
- */
- _getFieldValue: function () {
- var tags = [],
- str = this.get('container').one('.ez-keyword-input-ui input').get('value');
-
- if (str) {
- Y.Array.each(str.split(","), function (value) {
- tags.push(value.trim());
- });
- }
- return tags;
- }
- });
-
- Y.eZ.FieldEditView.registerFieldEditView(
- FIELDTYPE_IDENTIFIER, Y.eZ.KeywordEditView
- );
- });
-
-