annotate core/src/js/components/ActivationController.js @ 31:40d2e49a7219

working on dependencies
author cin
date Wed, 27 Jun 2018 04:31:39 +0300
parents acdcdf1a8d21
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", "../safe", "../log/_LogMixin"], function (declare, guard, safe, _LogMixin) {
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
2 "use strict";
3
00779cb63b12 formatting
cin
parents: 2
diff changeset
3 return declare([_LogMixin], {
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
4
3
00779cb63b12 formatting
cin
parents: 2
diff changeset
5 _current: null,
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
6
3
00779cb63b12 formatting
cin
parents: 2
diff changeset
7 _pending: false,
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
8
3
00779cb63b12 formatting
cin
parents: 2
diff changeset
9 getCurrent: function () {
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
10 return this._current;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
11 },
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
12
3
00779cb63b12 formatting
cin
parents: 2
diff changeset
13 _start: function () {
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
14 if (this._pending)
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
15 throw new Error("The activation/decativation is already pending");
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
16 this._pending = true;
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
3
00779cb63b12 formatting
cin
parents: 2
diff changeset
19 _await: function (d) {
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
20 var me = this;
3
00779cb63b12 formatting
cin
parents: 2
diff changeset
21 return d.then(function (x) {
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
22 me._pending = false;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
23 return x;
3
00779cb63b12 formatting
cin
parents: 2
diff changeset
24 }, function (e) {
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
25 me._pending = false;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
26 throw e;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
27 });
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
28 },
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
29
3
00779cb63b12 formatting
cin
parents: 2
diff changeset
30 activate: function (component) {
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
31 safe.argumentNotNull(component, "component");
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
32 var me = this;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
33 if (component.getController() !== this)
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
34 throw new Error("The specified component doesn't belong to this controller");
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
35
3
00779cb63b12 formatting
cin
parents: 2
diff changeset
36 return me._await(guard(me, "_start").then(function () {
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
37 me._activate(component);
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
3
00779cb63b12 formatting
cin
parents: 2
diff changeset
41 _activate: function (component) {
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
42 var me = this;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
43 if (me._current === component)
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
44 return guard(false);
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 // before activation hook
3
00779cb63b12 formatting
cin
parents: 2
diff changeset
47 return guard(me, "onActivating", [component]).then(function () {
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
48 // deactivate curent
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
49 if (me._current)
3
00779cb63b12 formatting
cin
parents: 2
diff changeset
50 return me._current.deactivate(true).then(function () {
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
51 try {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
52 me._current.onDeactivated();
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
53 } catch (err) {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
54 me.error(err);
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
55 }
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
56 // HACK raise deactivated event
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
57 try {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
58 me.onDeactivated(me._current, component);
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
59 } catch (err) {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
60 // deactivated shouldn't affect the process
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
61 me.error(err);
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 me._current = null;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
64
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
65 });
3
00779cb63b12 formatting
cin
parents: 2
diff changeset
66 }).then(function () {
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
67 return component.activate(true);
3
00779cb63b12 formatting
cin
parents: 2
diff changeset
68 }).then(function () {
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
69 me._current = component;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
70 try {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
71 me.onActivated(component);
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
72 } catch (err) {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
73 me.error(err);
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 });
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
77
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
78 },
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
79
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
80 /**
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
81 * Деактивирует текущую компоненту.
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
82 *
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
83 * @async
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
84 * @returns true - компонента была деактивирована, либо нет активной
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
85 * компоненты. false - запрос на деактивацию - отклонен.
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
86 */
3
00779cb63b12 formatting
cin
parents: 2
diff changeset
87 deactivate: function () {
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
88 var me = this;
3
00779cb63b12 formatting
cin
parents: 2
diff changeset
89 return me._await(guard(me, "_start").then(function () {
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
90 return me._deactivate();
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
3
00779cb63b12 formatting
cin
parents: 2
diff changeset
94 _deactivate: function () {
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
95 var me = this;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
96 if (!me._current)
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
97 return guard(false);
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
98
3
00779cb63b12 formatting
cin
parents: 2
diff changeset
99 return guard(me, "onDeactivating").then(function () {
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
100 return me._current.deactivate(true);
3
00779cb63b12 formatting
cin
parents: 2
diff changeset
101 }).then(function () {
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
102 // HACK raise deactivated event
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
103 try {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
104 me.onDeactivated(me._current);
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
105 } catch (err) {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
106 me.error(err);
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
107 }
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
108 me._current = null;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
109 });
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
110 },
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
111
3
00779cb63b12 formatting
cin
parents: 2
diff changeset
112 onActivating: function (component) {},
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
113
3
00779cb63b12 formatting
cin
parents: 2
diff changeset
114 onDeactivating: function (component) {},
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
115
3
00779cb63b12 formatting
cin
parents: 2
diff changeset
116 onDeactivated: function (component, next) {},
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
117
3
00779cb63b12 formatting
cin
parents: 2
diff changeset
118 onActivated: function (component) {}
0
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 });