Skip to content

Commit

Permalink
array editor editing events triggers (#317)
Browse files Browse the repository at this point in the history
* json editor move event where child editors can subscribe

* updated move event test

* addRow, moveRow, deleteRow, deleteAllRows

* updated array test
  • Loading branch information
German Bisurgi authored and marc7000 committed Mar 1, 2019
1 parent 806ea72 commit afb927e
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 19 deletions.
19 changes: 6 additions & 13 deletions src/editors/array.js
Expand Up @@ -540,6 +540,7 @@ JSONEditor.defaults.editors.array = JSONEditor.AbstractEditor.extend({
}

self.onChange(true);
self.jsoneditor.trigger('deleteRow');
});

if(controls_holder) {
Expand Down Expand Up @@ -595,13 +596,7 @@ JSONEditor.defaults.editors.array = JSONEditor.AbstractEditor.extend({

self.onChange(true);

self.jsoneditor.trigger('move');

// TODO we can remove this eventually
self.rows.forEach(function (row) {
row.onMove();
});

self.jsoneditor.trigger('moveRow');
});

if(controls_holder) {
Expand Down Expand Up @@ -629,12 +624,7 @@ JSONEditor.defaults.editors.array = JSONEditor.AbstractEditor.extend({
self.refreshTabs();
self.onChange(true);

self.jsoneditor.trigger('move');

// TODO we can remove this eventually
self.rows.forEach(function (row) {
row.onMove();
});
self.jsoneditor.trigger('moveRow');
});

if(controls_holder) {
Expand Down Expand Up @@ -709,6 +699,7 @@ JSONEditor.defaults.editors.array = JSONEditor.AbstractEditor.extend({
self.refreshTabs();
self.refreshValue();
self.onChange(true);
self.jsoneditor.trigger('addRow');
});
self.controls.appendChild(this.add_row_button);

Expand Down Expand Up @@ -739,6 +730,7 @@ JSONEditor.defaults.editors.array = JSONEditor.AbstractEditor.extend({
}

self.onChange(true);
self.jsoneditor.trigger('deleteRow');
});
self.controls.appendChild(this.delete_last_row_button);

Expand All @@ -755,6 +747,7 @@ JSONEditor.defaults.editors.array = JSONEditor.AbstractEditor.extend({
self.empty(true);
self.setValue([]);
self.onChange(true);
self.jsoneditor.trigger('deleteAllRows');
});
self.controls.appendChild(this.remove_all_rows_button);

Expand Down
31 changes: 28 additions & 3 deletions tests/codeceptjs/editors/array_test.js
Expand Up @@ -10,7 +10,7 @@ Scenario('should have correct initial value', async (I) => {
assert.equal(value, '[]');
});

Scenario('should move events when array elements are moved au or down', async (I) => {
Scenario('should array editing triggers', async (I) => {
I.amOnPage('array-move-events.html');
I.seeElement('[data-schemapath="root.0"]');
I.seeElement('[data-schemapath="root.1"]');
Expand All @@ -19,18 +19,43 @@ Scenario('should move events when array elements are moved au or down', async (I
assert.equal(value, '["A","B"]');

I.click('.json-editor-btn-moveup');
I.seeInPopup('item array moved');
I.seeInPopup('moveRow');
I.acceptPopup();
I.click('.get-value');
value = await I.grabValueFrom('.debug');
assert.equal(value, '["B","A"]');

I.click('.json-editor-btn-movedown');
I.seeInPopup('item array moved');
I.seeInPopup('moveRow');
I.acceptPopup();
I.click('.get-value');
value = await I.grabValueFrom('.debug');
assert.equal(value, '["A","B"]');

I.click('.json-editor-btntype-add');
I.seeInPopup('addRow');
I.acceptPopup();
I.click('.get-value');
value = await I.grabValueFrom('.debug');
assert.equal(value, '["A","B",""]');

I.click('.json-editor-btntype-deletelast');
I.seeInPopup('Are you sure you want to remove this node?');
I.acceptPopup();
I.seeInPopup('deleteRow');
I.acceptPopup();
I.click('.get-value');
value = await I.grabValueFrom('.debug');
assert.equal(value, '["A","B"]');

I.click('.json-editor-btntype-deleteall');
I.seeInPopup('Are you sure you want to remove this node?');
I.acceptPopup();
I.seeInPopup('deleteAllRows');
I.acceptPopup();
I.click('.get-value');
value = await I.grabValueFrom('.debug');
assert.equal(value, '[]');
});

Scenario('should work well with string editors', async (I) => {
Expand Down
21 changes: 18 additions & 3 deletions tests/pages/array-move-events.html
Expand Up @@ -32,9 +32,24 @@

editor.setValue(["A","B"]);

editor.on('move', function () {
alert('item array moved')
console.log('moved')
editor.on('moveRow', function () {
alert('moveRow')
console.log('moveRow')
});

editor.on('addRow', function () {
alert('addRow')
console.log('addRow')
});

editor.on('deleteRow', function () {
alert('deleteRow')
console.log('deleteRow')
});

editor.on('deleteAllRows', function () {
alert('deleteAllRows')
console.log('deleteAllRows')
});


Expand Down

0 comments on commit afb927e

Please sign in to comment.