comparison src/djol/_OneshotTool.js @ 17:9c21e656cbec

Разработка кнопки выбора координат с карт
author nickolay
date Tue, 19 Sep 2017 20:37:56 +0300
parents f0035923ff3e
children
comparison
equal deleted inserted replaced
16:1eeae195b234 17:9c21e656cbec
1 define([ "dojo/_base/declare", "implab/safe", "implab/guard", "ol3/_ToolBase", "ol3/ToolType" ], 1 define(["dojo/_base/declare", "implab/safe", "implab/guard", "ol3/_ToolBase", "ol3/ToolType"],
2 2
3 function(declare, safe, guard, _ToolBase, ToolType) { 3 function (declare, safe, guard, _ToolBase, ToolType) {
4 return declare([ _ToolBase ], { 4 return declare([_ToolBase], {
5 _pending : null, 5 _pending: null,
6
7 _lastResult : null,
8 6
9 toolType : ToolType.Oneshot, 7 _lastResult: null,
10 8
11 invoke : function() { 9 toolType: ToolType.Oneshot,
12 },
13 10
14 onActivating : function() { 11 invoke: function () {
15 var me = this; 12 },
16 13
17 // start the operation 14 onActivating: function () {
18 me._lastResult = me._pending = guard(me,"invoke"); 15 var me = this;
19 16
20 return this.inherited(arguments); 17 // start the operation
21 }, 18 me._lastResult = me._pending = guard(me, "invoke");
22 19
23 onActivated : function() { 20 return this.inherited(arguments);
24 var me = this; 21 },
25 22
26 // fire the activate event 23 onActivated: function () {
27 this.inherited(arguments); 24 var me = this;
28 25
29 me._pending.then(function() { 26 // fire the activate event
30 if (me._pending) { 27 this.inherited(arguments);
31 me.log("Operation finished, deactivating."); 28
32 me._pending = null; 29 me._pending.then(function () {
33 me.deactivate(); 30 if (me._pending) {
31 me.log("Operation finished, deactivating.");
32 me._pending = null;
33 me.deactivate();
34 }
35 }, function (ex) {
36 if (me._pending) {
37 me.error("Operation failed, deactivating: {0}", ex);
38 me._pending = null;
39 me.deactivate();
40 }
41 });
42 },
43
44 onDeactivated: function () {
45 var d = this._pending;
46 if (d) {
47 this.log("Cancelling pending operation");
48 this._pending = null;
49 d.cancel();
34 } 50 }
35 }, function(ex) {
36 if (me._pending) {
37 me.error("Operation failed, deactivating: {0}", ex);
38 me._pending = null;
39 me.deactivate();
40 }
41 });
42 },
43 51
44 onDeactivated : function() { 52 return this.inherited(arguments);
45 var d = this._pending; 53 },
46 if (d) { 54
47 this.log("Cancelling pending operation"); 55 run: function () {
48 this._pending = null; 56 var me = this;
49 d.cancel(); 57
58 return me.activate().then(function () {
59 return me._lastResult;
60 });
50 } 61 }
51 62 });
52 return this.inherited(arguments);
53 },
54
55 run : function() {
56 var me = this;
57
58 return me.activate().then(function(success) {
59 if (success)
60 return me._lastResult;
61 throw new Error("Operation declined");
62 });
63 }
64 }); 63 });
65 });