1 /** 2 * The 'field-editor' namespace 3 * @namespace 4 * The field-editor namespace provides an field-editor instance to manipulate 5 * the value and model of a field in Content Studio. The field-editor instance 6 * itself is an <code>EventEmitter</code> which emits event when the field value is changed. 7 * It also provides functionality to create a modal popup with some url specified by the user. 8 * @name field-editor 9 * @example 10 * window.onload = function (){ 11 * var editor = require("field-editor"); 12 * }; 13 */ 14 15 function Editor() { 16 EventEmitter.call(this); 17 /** 18 * The <code>value-changed</code> event is fired whenever the <code>value</code> 19 * of the particular field is changed. This event means that the Content Studio field 20 * value is changed. 21 * <p> 22 * The event is passed with an object of <code>String</code> type, which is the string representation 23 * of the Content Studio field value. 24 * @event 25 * @name field-editor-value-changed 26 * @memberOf field-editor 27 * @param {String} value the string representation of the value of a field . 28 * @example 29 * editor.on("value-changed", function (value) { 30 * document.getElementById("value").value = value; 31 * }); 32 */ 33 34 //This instance variable is used only for documentation purpose 35 //Please do not delete it. 36 37 /** 38 * The model of the content in VDF format. 39 * 40 * @memberOf field-editor 41 * @type {String} 42 * @example 43 * var model = editor.model 44 */ 45 this.model = ""; 46 //This instance variable is used only for documentation purpose 47 //Please do not delete it. 48 49 /** 50 * The value of the field. 51 * @memberOf field-editor 52 * @type {String} 53 * @example 54 * The value can be set like below: 55 * editor.value = document.getElementById("value").value; 56 */ 57 this.value = ""; 58 59 this.initEditor = function (javaFieldEditor) { 60 this.javaFieldEditor = javaFieldEditor; 61 }; 62 63 64 this.__defineGetter__("model", function () { 65 return this.javaFieldEditor.getModel(); 66 }); 67 68 this.__defineGetter__("value", function () { 69 return this.javaFieldEditor.getValue(); 70 }); 71 72 this.__defineSetter__("value", function (value) { 73 this.javaFieldEditor.setValue(value); 74 }); 75 76 this.__defineGetter__("showing", function () { 77 return this.javaFieldEditor.isShowing(); 78 }); 79 80 /** 81 * Shows a modal popup with the given <code>uri</code>. 82 * @param {String} pUri the uri which content will be shown in the modal popup. 83 * @param {Object} pData initial data for the popup. 84 * @memberOf field-editor 85 * @function 86 * @name createPopup 87 * @example 88 * var handle = editor.createPopup("./dialog.html", initial-value); 89 * 90 * This handle is an <code>EventEmitter</code> which can emit event for it's certain property change. We can listen to 91 * the property change event in the field editor like below: 92 * 93 * handle = editor.createDialog("./dialog.html"); 94 * handle.on("popup-value-changed", function (value) { 95 * document.getElementById("value").value = value; 96 * }); 97 * handle.show(); 98 */ 99 this.createPopup = function (pUri, pData) { 100 if (arguments.length < 1 || typeof pData == 'undefined') { 101 pData = null; 102 } 103 var jsPopupHandler = new PopupHandler(pData); 104 var javaPopupHandler = this.javaFieldEditor.createPopup(pUri, jsPopupHandler); 105 jsPopupHandler.setHandler(javaPopupHandler); 106 return jsPopupHandler; 107 }; 108 } 109 function heir(p) { 110 /** @ignore */ 111 function F() { 112 } 113 114 F.prototype = p; 115 return new F(); 116 } 117 118 Editor.prototype = heir(EventEmitter.prototype); 119 120 // set the constructor to the subclass prototype 121 Editor.prototype.constructor = Editor; 122 123 var fieldEditor = require('field-editor'); 124 if (fieldEditor == undefined || fieldEditor == null) { 125 Require['field-editor'] = new Editor(); 126 } 127