@dualbox/editor 1.0.20 → 1.0.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -112,7 +112,11 @@ class GraphView {
112
112
  }
113
113
 
114
114
  // add main template
115
- this.templateMgr.appendTemplate(this.div, "main", {showLoadSaveButtons: this.attrs.showLoadSaveButtons}, () => {
115
+ this.templateMgr.appendTemplate(this.div, "main", {
116
+ showLoadButton: this.attrs.showLoadButton,
117
+ showSaveButton: this.attrs.showSaveButton,
118
+ saveButtonFunction: this.attrs.saveButtonFunction
119
+ }, () => {
116
120
  // for convenience, define thoses once the main div is ready
117
121
  this.div.ready(() => {
118
122
  this.graphContainer = this.div.find('.dualbox-graph-container');
@@ -10,12 +10,14 @@
10
10
  </li>
11
11
  </ul>
12
12
 
13
- @if (attrs.showLoadSaveButtons) {
14
- <div class="nav navbar-right" style="vertical-align: top; margin-top: 5px; margin-right: 10px; margin-bottom: 5px;">
15
- <button class="load-app btn btn-sm btn-light" style="position: relative; bottom: 3px;">Load App</button>
16
- <button class="save-app btn btn-sm btn-light" style="position: relative; bottom: 3px;">Save App</button>
17
- </div>
18
- }
13
+ <div class="nav navbar-right" style="vertical-align: top; margin-top: 5px; margin-right: 10px; margin-bottom: 5px;">
14
+ @if (attrs.showLoadButton) {
15
+ <button class="load-app btn btn-sm btn-light" style="position: relative; bottom: 3px;">Load App</button>
16
+ }
17
+ @if (attrs.showSaveButton) {
18
+ <button class="save-app btn btn-sm btn-light" style="position: relative; bottom: 3px;">Save App</button>
19
+ }
20
+ </div>
19
21
  </nav>
20
22
  <div class="tab-content dualbox-graph-tab" style="width: 100%; height: calc(100% - 46px);">
21
23
  <div class="tab-pane active" id="1" style="width: 100%; height: 100%;">
@@ -1,7 +1,7 @@
1
1
  const swal = require('sweetalert2');
2
2
  var CodeMirror = require('../../libs/CodeMirror.js');
3
3
 
4
- var TemplateBinds = function(view, div) {
4
+ var TemplateBinds = function(view, div, data) {
5
5
  // instanciate main settings first
6
6
  view.setMainMenu();
7
7
 
@@ -32,7 +32,6 @@ var TemplateBinds = function(view, div) {
32
32
  })
33
33
  });
34
34
 
35
- // bind the app load
36
35
  div.find('.load-app').click(function(e) {
37
36
  // create a fake input and click it to select a file
38
37
  var input = $('<input/>', { "type": "file", "class": "upload", "accept" : ".json" });
@@ -55,24 +54,33 @@ var TemplateBinds = function(view, div) {
55
54
  });
56
55
 
57
56
  // bind the app load
58
- div.find('.save-app').click(function(e) {
59
- var app = view.m.getCleanJson();
60
- var text = JSON.stringify(app, null, 2);
61
- var blob = new Blob([text], { "type" : "application/octet-stream" });
62
-
63
- var a = document.createElement('a');
64
- a.href = window.URL.createObjectURL(blob);
65
- a.download = "app.json";
66
-
67
- // simulate a click on the link
68
- if (document.createEvent) {
69
- var event = document.createEvent("MouseEvents");
70
- event.initEvent("click", true, true);
71
- a.dispatchEvent(event);
72
- } else {
73
- a.click();
57
+ if( data.saveButtonFunction ) {
58
+ var saveButtonFunction = function(e) {
59
+ var json = view.m.getCleanJson();
60
+ return data.saveButtonFunction(json);
74
61
  }
75
- });
62
+ }
63
+ else {
64
+ var saveButtonFunction = function(e) {
65
+ var app = view.m.getCleanJson();
66
+ var text = JSON.stringify(app, null, 2);
67
+ var blob = new Blob([text], { "type" : "application/octet-stream" });
68
+
69
+ var a = document.createElement('a');
70
+ a.href = window.URL.createObjectURL(blob);
71
+ a.download = "app.json";
72
+
73
+ // simulate a click on the link
74
+ if (document.createEvent) {
75
+ var event = document.createEvent("MouseEvents");
76
+ event.initEvent("click", true, true);
77
+ a.dispatchEvent(event);
78
+ } else {
79
+ a.click();
80
+ }
81
+ }
82
+ }
83
+ div.find('.save-app').click(saveButtonFunction);
76
84
 
77
85
  div.find('.add-box').click(function(e) {
78
86
  $('#add-node-modal').modal();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dualbox/editor",
3
- "version": "1.0.20",
3
+ "version": "1.0.21",
4
4
  "description": "Editor of Dualbox apps",
5
5
  "browser": "js/dist/GraphEditor.js",
6
6
  "main": "js/dist/GraphEditor.js",