annotate src/implab/components/_ActivatableMixin.js @ 17:9c21e656cbec

Разработка кнопки выбора координат с карт
author nickolay
date Tue, 19 Sep 2017 20:37:56 +0300
parents 00779cb63b12
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
00779cb63b12 formatting
cin
parents: 2
diff changeset
1 define(["dojo/_base/declare", "../guard", "./StateMachine", "../log/_LogMixin", ], function (declare, guard, StateMachine, _LogMixin) {
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
2
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
3 var states = {
3
00779cb63b12 formatting
cin
parents: 2
diff changeset
4 inactive: {
00779cb63b12 formatting
cin
parents: 2
diff changeset
5 activate: "activating"
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
6 },
3
00779cb63b12 formatting
cin
parents: 2
diff changeset
7 activating: {
00779cb63b12 formatting
cin
parents: 2
diff changeset
8 success: "active",
00779cb63b12 formatting
cin
parents: 2
diff changeset
9 failed: "inactive"
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
10 },
3
00779cb63b12 formatting
cin
parents: 2
diff changeset
11 active: {
00779cb63b12 formatting
cin
parents: 2
diff changeset
12 deactivate: "deactivating"
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
13 },
3
00779cb63b12 formatting
cin
parents: 2
diff changeset
14 deactivating: {
00779cb63b12 formatting
cin
parents: 2
diff changeset
15 success: "inactive",
00779cb63b12 formatting
cin
parents: 2
diff changeset
16 failed: "active"
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
17 }
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
18 };
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
19
3
00779cb63b12 formatting
cin
parents: 2
diff changeset
20 return declare([_LogMixin], {
00779cb63b12 formatting
cin
parents: 2
diff changeset
21 _controller: null,
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
22
3
00779cb63b12 formatting
cin
parents: 2
diff changeset
23 _active: null,
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
24
3
00779cb63b12 formatting
cin
parents: 2
diff changeset
25 constructor: function () {
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
26 this._active = new StateMachine({
3
00779cb63b12 formatting
cin
parents: 2
diff changeset
27 states: states,
00779cb63b12 formatting
cin
parents: 2
diff changeset
28 initial: "inactive"
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
29 });
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
30 },
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
31
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
32 /**
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
33 * @returns {Object} контроллер для активации текущей компоненты
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
34 */
3
00779cb63b12 formatting
cin
parents: 2
diff changeset
35 getController: function () {
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
36 return this._controller;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
37 },
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
38
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
39 /**
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
40 * @param {Object}
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
41 * v Контроллер для активации текущей компоненты
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
42 */
3
00779cb63b12 formatting
cin
parents: 2
diff changeset
43 setController: function (v) {
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
44 this._controller = v;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
45 },
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
46
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
47 /**
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
48 * @returns {Boolean} текущая компонента активна
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
49 */
3
00779cb63b12 formatting
cin
parents: 2
diff changeset
50 isActive: function () {
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
51 return this._active.current == "active";
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
52 },
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
53
3
00779cb63b12 formatting
cin
parents: 2
diff changeset
54 assertActive: function () {
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
55 if (!this.isActive())
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
56 throw new Error("The object must be active to perform the operation");
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
57 },
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
58
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
59 /**
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
60 * Активирует текущую компоненту, если у текущей компоненты задан
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
61 * контроллер, то активация будет осуществляться через него
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
62 *
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
63 * @async
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
64 * @param{Boolean}
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
65 * direct вызов должен осуществится напрямую, без участия
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
66 * контроллера.
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
67 * @return{Boolean} успешно/неуспешно
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
68 */
3
00779cb63b12 formatting
cin
parents: 2
diff changeset
69 activate: function (direct) {
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
70 var me = this;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
71 if (!direct && this._controller)
3
00779cb63b12 formatting
cin
parents: 2
diff changeset
72 return me._controller.activate(me).then(function () {
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
73 me.onActivated();
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
74 });
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
75
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
76 me._active.move("activate");
3
00779cb63b12 formatting
cin
parents: 2
diff changeset
77 return guard(me, "onActivating").then(function () {
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
78 me.log("Activated");
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
79 me._active.move("success");
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
80 if (!me._controller)
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
81 me.onActivated();
3
00779cb63b12 formatting
cin
parents: 2
diff changeset
82 }, function (err) {
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
83 console.error(err);
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
84 me.error("Activation failed: {0}", err);
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
85 me._active.move("failed");
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
86 throw err;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
87 });
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
88 },
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
89
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
90 /**
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
91 * Деактивирует текущую компоненту, если у компоненты задан контроллер,
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
92 * то деактивация будет осуществляться через него.
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
93 *
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
94 * @async
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
95 * @param{Boolean} direct вызов должен осуществится напрямую, без
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
96 * участия контроллера.
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
97 *
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
98 */
3
00779cb63b12 formatting
cin
parents: 2
diff changeset
99 deactivate: function (direct) {
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
100 var me = this;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
101 if (!direct && me._controller)
3
00779cb63b12 formatting
cin
parents: 2
diff changeset
102 return me._controller.deactivate(me).then(function () {
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
103 me.onDeactivated();
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
104 });
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
105
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
106 me._active.move("deactivate");
3
00779cb63b12 formatting
cin
parents: 2
diff changeset
107 return guard(me, "onDeactivating").then(function () {
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
108 me.log("Deactivated");
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
109 me._active.move("success");
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
110 if (!me._controller)
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
111 me.onDeactivated();
3
00779cb63b12 formatting
cin
parents: 2
diff changeset
112 }, function (err) {
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
113 console.error(err);
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
114 me.error("Deactivation failed: {0}", err);
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
115 me.move("failed");
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
116 throw err;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
117 });
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
118
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
119 },
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
120
3
00779cb63b12 formatting
cin
parents: 2
diff changeset
121 toogleActive: function () {
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
122 var me = this;
3
00779cb63b12 formatting
cin
parents: 2
diff changeset
123 return (me.isActive() ? me.deactivate() : me.activate()).then(function () {
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
124 return me.isActive();
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
125 });
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
126 },
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
127
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
128 /**
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
129 * Событие вызывается перед активацией текущей компоненты
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
130 *
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
131 * @returns{Boolean|undefined} если false - активация будет отменена
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
132 */
3
00779cb63b12 formatting
cin
parents: 2
diff changeset
133 onActivating: function () {},
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
134
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
135 /**
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
136 * Событие вызывается перед деактивацией текущей компоненты
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
137 *
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
138 * @returns {Boolean|undefined} если false - деактивация будет отменена
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
139 */
3
00779cb63b12 formatting
cin
parents: 2
diff changeset
140 onDeactivating: function () {},
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
141
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
142 /**
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
143 * Событие вызывается после активации текущей компоненты
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
144 */
3
00779cb63b12 formatting
cin
parents: 2
diff changeset
145 onActivated: function () {},
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
146
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
147 /**
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
148 * Событие вызывается после деактивации текущей компоненты
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
149 */
3
00779cb63b12 formatting
cin
parents: 2
diff changeset
150 onDeactivated: function () {}
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
151
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
152 });
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
153 });