1 /** 2 * @fileOverview 3 * Copyright (c) 2013 Regione Autonoma della Sardegna 4 * Published under the GPL license.<br> 5 * See <a href="https://sardegnageoportale.it/webgis/license.txt">https://sardegnageoportale.it/webgis/license.txt</a> 6 * for the full text of the license. 7 * @version 0.1 8 */ 9 10 /** 11 * @namespace framework.plugins 12 */ 13 Ext.namespace("framework.widgets"), 14 15 /** 16 * Form-popup panel for addGroup action 17 * @name_ PanelAddGroup 18 * @class Form-popup panel for addGroup action. 19 * @constructor 20 * @extends <a target="_blank" href="http://docs.sencha.com/extjs/4.1.3/#!/api/Ext.panel.Panel">Ext.Panel</a> 21 */ 22 framework.widgets.PanelAddGroup = Ext.extend(Ext.Panel, 23 /** 24 * @lends framework.widgets.PanelAddGroup.prototype 25 */ 26 { 27 28 /** 29 * Text for reset button item (i18n). 30 * @public 31 * @type string 32 */ 33 cancelText: "Cancel", 34 35 /** 36 * Text for submit button item (i18n). 37 * @public 38 * @type string 39 */ 40 addGroupText: "Add Group", 41 42 /** 43 * label text for import file (i18n). 44 * @public 45 * @type string 46 */ 47 fieldLabel: "Group name", 48 49 /** 50 * bodyStyle sets the padding to 0px 51 * default padding = 5px 52 * @public 53 * @type string 54 */ 55 bodyStyle: "padding: 5px", 56 57 /** 58 * text for required field (i18n). 59 * @public 60 * @type string 61 */ 62 blankText : 'This field is required', 63 64 /** Init the component creating a form panel to manage addGroup request. 65 * @public 66 */ 67 initComponent: function() { 68 69 this.addEvents("groupselected"); 70 71 this.textField = new Ext.form.TextField({ 72 fieldLabel: this.fieldLabel, 73 allowBlank: false, 74 blankText : this.blankText, 75 width: 150, 76 msgTarget: "under", 77 listeners: { 78 specialkey: function(f, e) { 79 if (e.getKey() === e.ENTER) { 80 this.addGroup(); 81 } 82 }, 83 scope: this 84 } 85 }); 86 87 this.form = new Ext.form.FormPanel({ 88 items: [ 89 this.textField 90 ], 91 border: false, 92 labelWidth: 100, 93 bodyStyle: this.bodyStyle, 94 autoWidth: true, 95 autoHeight: true, 96 listeners: { 97 afterrender: function() { 98 this.textField.focus(false, true); 99 }, 100 scope: this 101 } 102 }); 103 104 this.bbar = [ 105 new Ext.Button({ 106 text: this.cancelText, 107 handler: this.hide, 108 scope: this 109 }), 110 new Ext.Toolbar.Fill(), 111 new Ext.Button({ 112 text: this.addGroupText, 113 iconCls: "add", 114 handler: this.addGroup, 115 scope: this 116 }) 117 ]; 118 119 this.items = this.form; 120 121 framework.widgets.PanelAddGroup.superclass.initComponent.call(this); 122 123 this.on({ 124 afterrender: function(){ 125 this.textField.focus(false,500); 126 }, 127 hide: this.reset, 128 removed: this.reset, 129 scope: this 130 }); 131 this.on("groupselected", function(cmp, groupName) { 132 }, this); 133 }, 134 135 /** Fire event 'groupselected' if the group name is valid. 136 * @private 137 */ 138 addGroup: function() { 139 if (this.textField.getValue().length > 1) { 140 this.fireEvent("groupselected", this, this.textField.getValue()); 141 } 142 }, 143 144 /** Reset TextField. 145 * @private 146 */ 147 reset: function() { 148 // Reset values so it looks right the next time it pops up. 149 this.textField.reset(); 150 } 151 }); 152 153 /** api: xtype = framework_paneladdgroup */ 154 Ext.reg("framework_paneladdgroup", framework.widgets.PanelAddGroup); 155 156