1
1
import { getList } from "../server" ;
2
2
import { AutoGrid } from "../autoGrid" ;
3
3
import { getCardElement } from "./card" ;
4
- import { block } from "../utils" ;
4
+ import { block } from "../domUtils" ;
5
+ import { saveChanges } from "./changes" ;
5
6
6
7
var PATH = "" ,
7
8
INITIALIZED = false ,
@@ -14,11 +15,15 @@ let initCallbacks = [];
14
15
*/
15
16
let grid = onInit ( ( ) => grid = new AutoGrid ( document . querySelector ( "#classBuilderBody" ) ) ) ;
16
17
18
+ /**
19
+ * Function which updates current grid.
20
+ */
17
21
export function updateGrid ( ) {
18
22
grid . updateGrid ( ) ;
19
23
}
20
24
21
25
/**
26
+ * Behaviors for elements on page.
22
27
* @type {HTMLElement }
23
28
*/
24
29
let backButton = onInit ( ( ) => {
@@ -44,12 +49,28 @@ let backButton = onInit(() => {
44
49
updateHeaderNamespaceWidth ( NAMESPACE ) ;
45
50
loadLevel ( "" ) ;
46
51
} ) ;
52
+ } ) ,
53
+ saveButton = onInit ( ( ) => {
54
+ saveButton = document . querySelector ( "#saveIndicator" ) ;
55
+ saveButton . style . opacity = 0 ;
56
+ saveButton . addEventListener ( "click" , ( ) => {
57
+ saveChanges ( NAMESPACE , ( res ) => {
58
+ if ( ! res [ "error" ] ) saveButton . style . opacity = 0 ;
59
+ } ) ;
60
+ } ) ;
47
61
} ) ;
48
62
49
63
/**
50
- * This function uses a bit of trick to compute the width of the namespace element in header, but it
51
- * does its job.
52
- * @param {string } namespace
64
+ * This function applies visual effects regarding to changes were made and
65
+ * indicates that changes are needed to be saved.
66
+ */
67
+ export function changeIsMade ( ) {
68
+ saveButton . style . opacity = 1 ;
69
+ }
70
+
71
+ /**
72
+ * This function uses a bit of trick to compute the width of the namespace element in header.
73
+ * @param {string } namespace - Currently selected namespace.
53
74
*/
54
75
function updateHeaderNamespaceWidth ( namespace ) {
55
76
let temp = block ( "select" , "topNamespace" ) ,
@@ -85,12 +106,9 @@ function setTitle (text) {
85
106
}
86
107
87
108
/**
88
- * This namespace should be trusted - setting wrong namespace will result as "no data".
109
+ * Displays the classes and packages located on the current level.
110
+ * @param {string } level - Class part.
89
111
*/
90
- function setNamespace ( namespace ) {
91
- topNamespace . textContent = namespace ;
92
- }
93
-
94
112
export function loadLevel ( level ) {
95
113
96
114
PATH = level ;
@@ -118,9 +136,13 @@ export function onInit (callback) {
118
136
callback ( ) ;
119
137
else
120
138
initCallbacks . push ( callback ) ;
121
- return "Duck" ;
139
+ return "Duck" ; // Property has to be redefined in onInit callback.
122
140
}
123
141
142
+ /**
143
+ * Application entry point.
144
+ * @param {* } data - Server response to the /Informer/init request.
145
+ */
124
146
export function init ( data ) {
125
147
126
148
INITIALIZED = true ;
0 commit comments