annotate src/implab/components/ActivationController.js @ 2:7d7059d2a810

Подправлены пути в пакетах
author egor
date Fri, 02 Jun 2017 19:28:20 +0300
parents fc2517695ee1
children 00779cb63b12
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
7d7059d2a810 Подправлены пути в пакетах
egor
parents: 0
diff changeset
1 define([ "dojo/_base/declare", "../guard", "../safe", "../log/_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 function(declare, guard, safe, _LogMixin) {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
4 "use strict";
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
5 return declare([ _LogMixin ], {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
6
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
7 _current : null,
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
8
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
9 _pending : false,
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
10
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
11 getCurrent : function() {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
12 return this._current;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
13 },
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
14
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
15 _start : function() {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
16 if (this._pending)
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
17 throw new Error("The activation/decativation is already pending");
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
18 this._pending = true;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
19 },
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
20
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
21 _await : function(d) {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
22 var me = this;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
23 return d.then(function(x) {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
24 me._pending = false;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
25 return x;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
26 }, function(e) {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
27 me._pending = false;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
28 throw e;
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 activate : function(component) {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
33 safe.argumentNotNull(component, "component");
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
34 var me = this;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
35 if (component.getController() !== this)
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
36 throw new Error("The specified component doesn't belong to 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 return me._await(guard(me, "_start").then(function() {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
39 me._activate(component);
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
40 }));
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
41 },
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
42
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
43 _activate : function(component) {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
44 var me = this;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
45 if (me._current === component)
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
46 return guard(false);
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 // before activation hook
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
49 return guard(me, "onActivating", [ component ]).then(function() {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
50 // deactivate curent
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
51 if (me._current)
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
52 return me._current.deactivate(true).then(function() {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
53 try {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
54 me._current.onDeactivated();
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
55 } catch (err) {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
56 me.error(err);
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 // HACK raise deactivated event
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
59 try {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
60 me.onDeactivated(me._current, component);
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
61 } catch (err) {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
62 // deactivated shouldn't affect the process
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
63 me.error(err);
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 me._current = null;
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 });
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
68 }).then(function() {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
69 return component.activate(true);
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
70 }).then(function() {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
71 me._current = component;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
72 try {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
73 me.onActivated(component);
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
74 } catch (err) {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
75 me.error(err);
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 * Деактивирует текущую компоненту.
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
84 *
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
85 * @async
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
86 * @returns true - компонента была деактивирована, либо нет активной
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
87 * компоненты. false - запрос на деактивацию - отклонен.
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 deactivate : function() {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
90 var me = this;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
91 return me._await(guard(me,"_start").then(function() {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
92 return me._deactivate();
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 },
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
95
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
96 _deactivate : function() {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
97 var me = this;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
98 if (!me._current)
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
99 return guard(false);
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
100
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
101 return guard(me, "onDeactivating").then(function() {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
102 return me._current.deactivate(true);
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
103 }).then(function() {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
104 // HACK raise deactivated event
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
105 try {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
106 me.onDeactivated(me._current);
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
107 } catch (err) {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
108 me.error(err);
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 me._current = null;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
111 });
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
112 },
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
113
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
114 onActivating : function(component) {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
115 },
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
116
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
117 onDeactivating : function(component) {
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 onDeactivated : function(component, next) {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
121 },
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
122
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
123 onActivated : function(component) {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
124 }
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 });