Skip to content

Commit fc0ea1b

Browse files
yiwenliuyiwenliu
yiwenliu
authored and
yiwenliu
committed
Check if it is always disabled before enabling any editor
1 parent 26e2215 commit fc0ea1b

11 files changed

+49
-37
lines changed

src/editors/array.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,22 @@ JSONEditor.defaults.editors.array = JSONEditor.AbstractEditor.extend({
2929
}
3030
},
3131
enable: function() {
32-
if(this.add_row_button) this.add_row_button.disabled = false;
33-
if(this.remove_all_rows_button) this.remove_all_rows_button.disabled = false;
34-
if(this.delete_last_row_button) this.delete_last_row_button.disabled = false;
35-
36-
if(this.rows) {
37-
for(var i=0; i<this.rows.length; i++) {
38-
this.rows[i].enable();
39-
40-
if(this.rows[i].moveup_button) this.rows[i].moveup_button.disabled = false;
41-
if(this.rows[i].movedown_button) this.rows[i].movedown_button.disabled = false;
42-
if(this.rows[i].delete_button) this.rows[i].delete_button.disabled = false;
32+
if(!this.always_disabled) {
33+
if(this.add_row_button) this.add_row_button.disabled = false;
34+
if(this.remove_all_rows_button) this.remove_all_rows_button.disabled = false;
35+
if(this.delete_last_row_button) this.delete_last_row_button.disabled = false;
36+
37+
if(this.rows) {
38+
for(var i=0; i<this.rows.length; i++) {
39+
this.rows[i].enable();
40+
41+
if(this.rows[i].moveup_button) this.rows[i].moveup_button.disabled = false;
42+
if(this.rows[i].movedown_button) this.rows[i].movedown_button.disabled = false;
43+
if(this.rows[i].delete_button) this.rows[i].delete_button.disabled = false;
44+
}
4345
}
46+
this._super();
4447
}
45-
this._super();
4648
},
4749
disable: function() {
4850
if(this.add_row_button) this.add_row_button.disabled = true;

src/editors/base64.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,10 @@ JSONEditor.defaults.editors.base64 = JSONEditor.AbstractEditor.extend({
6767
}
6868
},
6969
enable: function() {
70-
if(this.uploader) this.uploader.disabled = false;
71-
this._super();
70+
if(!this.always_disabled) {
71+
if(this.uploader) this.uploader.disabled = false;
72+
this._super();
73+
}
7274
},
7375
disable: function() {
7476
if(this.uploader) this.uploader.disabled = true;

src/editors/checkbox.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ JSONEditor.defaults.editors.checkbox = JSONEditor.AbstractEditor.extend({
4545
enable: function() {
4646
if(!this.always_disabled) {
4747
this.input.disabled = false;
48+
this._super();
4849
}
49-
this._super();
5050
},
5151
disable: function() {
5252
this.input.disabled = true;

src/editors/enum.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,10 @@ JSONEditor.defaults.editors["enum"] = JSONEditor.AbstractEditor.extend({
6262
this.display_area.innerHTML = this.html_values[this.selected];
6363
},
6464
enable: function() {
65-
if(!this.always_disabled) this.switcher.disabled = false;
66-
this._super();
65+
if(!this.always_disabled) {
66+
this.switcher.disabled = false;
67+
this._super();
68+
}
6769
},
6870
disable: function() {
6971
this.switcher.disabled = true;

src/editors/multiple.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,16 @@ JSONEditor.defaults.editors.multiple = JSONEditor.AbstractEditor.extend({
2424
return Math.max(this.editors[this.type].getNumColumns(),4);
2525
},
2626
enable: function() {
27-
if(this.editors) {
28-
for(var i=0; i<this.editors.length; i++) {
29-
if(!this.editors[i]) continue;
30-
this.editors[i].enable();
27+
if(!this.always_disabled) {
28+
if(this.editors) {
29+
for(var i=0; i<this.editors.length; i++) {
30+
if(!this.editors[i]) continue;
31+
this.editors[i].enable();
32+
}
3133
}
34+
this.switcher.disabled = false;
35+
this._super();
3236
}
33-
this.switcher.disabled = false;
34-
this._super();
3537
},
3638
disable: function() {
3739
if(this.editors) {

src/editors/multiselect.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,8 @@ JSONEditor.defaults.editors.multiselect = JSONEditor.AbstractEditor.extend({
176176
}
177177
}
178178
if(this.select2) this.select2.select2("enable",true);
179+
this._super();
179180
}
180-
this._super();
181181
},
182182
disable: function() {
183183
if(this.input) {

src/editors/object.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,16 @@ JSONEditor.defaults.editors.object = JSONEditor.AbstractEditor.extend({
2727
return Math.max(Math.min(12,this.maxwidth),3);
2828
},
2929
enable: function() {
30-
if(this.editjson_button) this.editjson_button.disabled = false;
31-
if(this.addproperty_button) this.addproperty_button.disabled = false;
32-
33-
this._super();
34-
if(this.editors) {
35-
for(var i in this.editors) {
36-
if(!this.editors.hasOwnProperty(i)) continue;
37-
this.editors[i].enable();
30+
if(!this.always_disabled) {
31+
if(this.editjson_button) this.editjson_button.disabled = false;
32+
if(this.addproperty_button) this.addproperty_button.disabled = false;
33+
34+
this._super();
35+
if(this.editors) {
36+
for(var i in this.editors) {
37+
if(!this.editors.hasOwnProperty(i)) continue;
38+
this.editors[i].enable();
39+
}
3840
}
3941
}
4042
},

src/editors/select.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,8 @@ JSONEditor.defaults.editors.select = JSONEditor.AbstractEditor.extend({
333333
if(!this.always_disabled) {
334334
this.input.disabled = false;
335335
if(this.select2) this.select2.select2("enable",true);
336+
this._super();
336337
}
337-
this._super();
338338
},
339339
disable: function() {
340340
this.input.disabled = true;

src/editors/selectize.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,8 @@ JSONEditor.defaults.editors.selectize = JSONEditor.AbstractEditor.extend({
324324
if(this.selectize) {
325325
this.selectize[0].selectize.unlock();
326326
}
327+
this._super();
327328
}
328-
this._super();
329329
},
330330
disable: function() {
331331
this.input.disabled = true;

src/editors/string.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,8 @@ JSONEditor.defaults.editors.string = JSONEditor.AbstractEditor.extend({
277277
if(!this.always_disabled) {
278278
this.input.disabled = false;
279279
// TODO: WYSIWYG and Markdown editors
280+
this._super();
280281
}
281-
this._super();
282282
},
283283
disable: function() {
284284
this.input.disabled = true;

src/editors/upload.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,10 @@ JSONEditor.defaults.editors.upload = JSONEditor.AbstractEditor.extend({
109109
});
110110
},
111111
enable: function() {
112-
if(this.uploader) this.uploader.disabled = false;
113-
this._super();
112+
if(!this.always_disabled) {
113+
if(this.uploader) this.uploader.disabled = false;
114+
this._super();
115+
}
114116
},
115117
disable: function() {
116118
if(this.uploader) this.uploader.disabled = true;

0 commit comments

Comments
 (0)