4 * Copyright(c) 2006-2007, Ext JS, LLC.
6 * Originally Released Under LGPL - original licence link has changed is not relivant.
9 * <script type="text/javascript">
13 * @class Roo.form.Signature
14 * @extends Roo.form.Field
18 * @param {Object} config Configuration options
21 Roo.form.Signature = function(config){
22 Roo.form.Signature.superclass.constructor.call(this, config);
24 this.addEvents({// not in used??
27 * Fires when the 'confirm' icon is pressed (add a listener to enable add button)
28 * @param {Roo.form.ComboBox} combo This combo box
33 * Fires when the 'edit' icon is pressed (add a listener to enable add button)
34 * @param {Roo.form.ComboBox} combo This combo box
35 * @param {Roo.data.Record|false} record The data record returned from the underlying store (or false on nothing selected)
41 Roo.extend(Roo.form.Signature, Roo.form.Field, {
43 * @cfg {Object} fieldLabel Label to use when rendering a form.
55 * @cfg {Number} width The signature panel width (defaults to 300)
59 * @cfg {Number} height The signature panel height (defaults to 100)
63 * @cfg {Object} signPanel The signature SVG panel element (defaults to {})
67 * @cfg {Boolean} allowBlank False to validate that the value length > 0 (defaults to false)
71 * @cfg {Boolean} isMouseDown False to validate that the mouse down event (defaults to false)
75 * @cfg {Boolean} isConfirmed validate the signature is confirmed or not for submitting form (defaults to false)
79 * @cfg {String} signatureTmp SVG mapping string (defaults to empty string)
83 defaultAutoCreate : { // modified by initCompnoent..
89 onRender : function(ct, position){
91 Roo.form.Signature.superclass.onRender.call(this, ct, position);
93 this.wrap = this.el.wrap({
94 cls:'x-form-signature-wrap', style : 'width: ' + this.width + 'px', cn:{cls:'x-form-signature'}
97 this.createToolbar(this);
98 this.signPanel = this.wrap.createChild({
100 style: 'width: ' + this.width + 'px; height: ' + this.height + 'px; border: 0;'
104 this.svgEl = this.signPanel.createChild({
105 xmlns : 'http://www.w3.org/2000/svg',
109 viewBox: '0 0 '+this.width+' '+this.height,
126 'stroke-dasharray': "3",
127 'shape-rendering': "crispEdges",
128 'pointer-events': "none"
136 'pointer-events': 'none'
141 this.svgBox = this.svgEl.dom.getScreenCTM();
143 createSVG : function(){
144 var svg = this.signPanel;
145 var r = svg.select('#svg-r', true).first().dom;
148 r.addEventListener('mousedown', function(e) { return t.down(e); }, false);
149 r.addEventListener('mousemove', function(e) { return t.move(e); }, false);
150 r.addEventListener('mouseup', function(e) { return t.up(e); }, false);
151 r.addEventListener('mouseout', function(e) { return t.up(e); }, false);
152 r.addEventListener('touchstart', function(e) { return t.down(e); }, false);
153 r.addEventListener('touchmove', function(e) { return t.move(e); }, false);
154 r.addEventListener('touchend', function(e) { return t.up(e); }, false);
157 isTouchEvent : function(e){
158 return e.type.match(/^touch/);
160 getCoords : function (e) {
161 var pt = this.svgEl.dom.createSVGPoint();
164 if (this.isTouchEvent(e)) {
165 pt.x = e.targetTouches[0].clientX
166 pt.y = e.targetTouches[0].clientY;
168 var a = this.svgEl.dom.getScreenCTM();
170 var mx = pt.matrixTransform(b);
171 return mx.x + ',' + mx.y;
173 //mouse event headler
174 down : function (e) {
175 this.signatureTmp += 'M' + this.getCoords(e) + ' ';
176 this.signPanel.select('#svg-p', true).first().attr('d', this.signatureTmp);
178 this.isMouseDown = true;
182 move : function (e) {
183 if (this.isMouseDown) {
184 this.signatureTmp += 'L' + this.getCoords(e) + ' ';
185 this.signPanel.select('#svg-p', true).first().attr('d', this.signatureTmp);
191 this.isMouseDown = false;
192 var sp = this.signatureTmp.split(' ');
195 if(!sp[sp.length-2].match(/^L/)){
199 this.signatureTmp = sp.join(" ");
202 if(this.getValue() != this.signatureTmp){
203 this.signPanel.select('#svg-r', true).first().attr('fill', '#ffa');
204 this.isConfirmed = false;
210 * Protected method that will not generally be called directly. It
211 * is called when the editor creates its toolbar. Override this method if you need to
212 * add custom toolbar buttons.
213 * @param {HtmlEditor} editor
215 createToolbar : function(editor){
216 function btn(id, toggle, handler){
217 var xid = fid + '-'+ id ;
221 cls : 'x-btn-icon x-edit-'+id,
222 enableToggle:toggle !== false,
223 scope: editor, // was editor...
224 handler:handler||editor.relayBtnCmd,
225 clickEvent:'mousedown',
226 tooltip: etb.buttonTips[id] || undefined, ///tips ???
232 var tb = new Roo.Toolbar(editor.wrap.dom.firstChild);
236 cls : ' x-signature-btn x-signature-'+id,
237 scope: editor, // was editor...
239 clickEvent:'mousedown',
240 text: this.labels.clear
247 cls : ' x-signature-btn x-signature-'+id,
248 scope: editor, // was editor...
249 handler: this.setConfirmed,
250 clickEvent:'mousedown',
251 text: this.labels.confirm
257 getSignature : function(){
258 return this.signatureTmp;
262 this.signatureTmp = '';
263 this.signPanel.select('#svg-r', true).first().attr('fill', '#ffa');
264 this.signPanel.select('#svg-p', true).first().attr('d', '');
265 this.isConfirmed = false;
266 Roo.form.Signature.superclass.reset.call(this);
269 // Roo.log(this.signPanel.dom.contentWindow.up())
272 setConfirmed : function(){
273 if(!this.getSignature()){
276 this.signPanel.select('#svg-r', true).first().attr('fill', '#cfc');
277 this.setValue(this.getSignature());
278 this.isConfirmed = true;
279 // Roo.log(Roo.get(this.signPanel.dom.contentWindow.r).attr('fill', '#cfc'));
282 // Subclasses should provide the validation implementation by overriding this
283 validateValue : function(value){
288 if(this.isConfirmed){