File: Resources/public/js/views/fields/ez-url-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-url-editview', function (Y) {
"use strict";
/**
* Provides the field edit view for the Url (ezurl) fields
*
* @module ez-url-editview
*/
Y.namespace('eZ');
var FIELDTYPE_IDENTIFIER = 'ezurl';
/**
* Url edit view
*
* @namespace eZ
* @class UrlEditView
* @constructor
* @extends eZ.FieldEditView
*/
Y.eZ.UrlEditView = Y.Base.create('urlEditView', Y.eZ.FieldEditView, [], {
events: {
'.ez-url-field-value': {
'blur': 'validate',
'valuechange': 'validate'
}
},
/**
* Validates the current input of primary url field
*
* @method validate
*/
validate: function () {
if ( this._getInputValidity().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 the
* url field
*
* @protected
* @method _variables
* @return {Object} containing isRequired entry
*/
_variables: function () {
return {
"isRequired": this.get('fieldDefinition').isRequired
};
},
/**
* Returns the primary input validity state object for the input
* generated by the url 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-url-field-value').get('validity');
},
/**
* Returns the currently filled value as an object containing the link
* and the text.
*
* @protected
* @method _getFieldValue
* @return Object
*/
_getFieldValue: function () {
var container = this.get('container');
return {
link: container.one('.ez-url-field-value').get('value'),
text: container.one('.ez-url-title-value').get('value')
};
},
});
Y.eZ.FieldEditView.registerFieldEditView(
FIELDTYPE_IDENTIFIER, Y.eZ.UrlEditView
);
});