11import { getList } from "../server" ;
22import { AutoGrid } from "../autoGrid" ;
33import { getCardElement } from "./card" ;
4- import { block } from "../utils" ;
4+ import { block } from "../domUtils" ;
5+ import { saveChanges } from "./changes" ;
56
67var PATH = "" ,
78 INITIALIZED = false ,
@@ -14,11 +15,15 @@ let initCallbacks = [];
1415 */
1516let grid = onInit ( ( ) => grid = new AutoGrid ( document . querySelector ( "#classBuilderBody" ) ) ) ;
1617
18+ /**
19+ * Function which updates current grid.
20+ */
1721export function updateGrid ( ) {
1822 grid . updateGrid ( ) ;
1923}
2024
2125/**
26+ * Behaviors for elements on page.
2227 * @type {HTMLElement }
2328 */
2429let backButton = onInit ( ( ) => {
@@ -44,12 +49,28 @@ let backButton = onInit(() => {
4449 updateHeaderNamespaceWidth ( NAMESPACE ) ;
4550 loadLevel ( "" ) ;
4651 } ) ;
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+ } ) ;
4761 } ) ;
4862
4963/**
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.
5374 */
5475function updateHeaderNamespaceWidth ( namespace ) {
5576 let temp = block ( "select" , "topNamespace" ) ,
@@ -85,12 +106,9 @@ function setTitle (text) {
85106}
86107
87108/**
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.
89111 */
90- function setNamespace ( namespace ) {
91- topNamespace . textContent = namespace ;
92- }
93-
94112export function loadLevel ( level ) {
95113
96114 PATH = level ;
@@ -118,9 +136,13 @@ export function onInit (callback) {
118136 callback ( ) ;
119137 else
120138 initCallbacks . push ( callback ) ;
121- return "Duck" ;
139+ return "Duck" ; // Property has to be redefined in onInit callback.
122140}
123141
142+ /**
143+ * Application entry point.
144+ * @param {* } data - Server response to the /Informer/init request.
145+ */
124146export function init ( data ) {
125147
126148 INITIALIZED = true ;
0 commit comments