/*! * Aloha Editor * Author & Copyright (c) 2010 Gentics Software GmbH * aloha-sales@gentics.com * Licensed unter the terms of http://www.aloha-editor.com/license.html */ /** * @name block.editor * @namespace Block attribute editors */ define(['aloha/jquery', 'aloha/observable'], function(jQuery, Observable) { /** * This is the base class for all editors in the sidebar. You need to extend * this class if you need to write your own editor. In most cases, however, * it is sufficent to subclass the AbstractFormElementEditor. * * @name block.editor.AbstractEditor * @class An abstract editor */ var AbstractEditor = Class.extend(Observable, /** @lends block.editor.AbstractEditor */ { /** * Schema of the current element * * @param {Object} * @api */ schema: null, /** * @constructor */ _constructor: function(schema) { this.schema = schema; }, /** * Template method to render the editor elements. Override it * in your subclass! Needs to return the jQuery element which * should be added to the DOM * * @return {jQuery} * @api */ render: function() { // Implement in subclass! }, /** * Template method to get the current editor value * * Override it in your subclass! * * @return {String} * @api */ getValue: function() { // Implement in subclass! }, /** * Method which is called at initialization time, to set the current value. * * Override it in your subclass! * * You should not throw any change event here, as we need to break the loop "Block" -> "Editor" -> "Block" * * @param {String} value * @api */ setValue: function(value) { // Implement in subclass! }, /** * Destroy the editor elements and unbind events * @api */ destroy: function() { // Implement in subclass! }, /** * On deactivating, we still need to trigger a change event if the value has been modified. * * @private */ _deactivate: function() { this.trigger('change', this.getValue()); this.destroy(); } }); /** * This is a more specialized FormElementEditor which should be used * for form-based editors. * * @name block.editor.AbstractFormElementEditor * @class An abstract form editor with label * @extends block.editor.AbstractEditor */ var AbstractFormElementEditor = AbstractEditor.extend( /** @lends block.editor.AbstractFormElementEditor */ { /** * Input element HTML definition * * You need to override this in your subclass. * * @type String * * @api */ formInputElementDefinition: null, /** * The jQuery element of the form input element. * * @type {jQuery} */ _$formInputElement: null, /** * Render the label and form element * @return {jQuery} */ render: function() { var $wrapper = jQuery('
'); var guid = GENTICS.Utils.guid(); $wrapper.append(this.renderLabel().attr('id', guid)); $wrapper.append(this.renderFormElement().attr('id', guid)); return $wrapper; }, /** * Render the label for the editor, by using the "label" property * from the schema. * * @return {jQuery} */ renderLabel: function() { var element = jQuery('