Skip to content

Commit

Permalink
feat: add isUpdateOriginal option to request()
Browse files Browse the repository at this point in the history
  • Loading branch information
dongwoo committed Jan 16, 2017
1 parent 2256a21 commit df9207f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/js/addon/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -482,20 +482,24 @@ var Net = View.extend(/**@lends module:addon/net.prototype */{
* @param {String} [options.isOnlyChecked=true] - Whether the request param only contains checked rows
* @param {String} [options.isOnlyModified=true] - Whether the request param only contains modified rows
* @param {String} [options.isSkipConfirm=false] - Whether to show confirm dialog before sending request
* @param {String} [options.isUpdateOriginal=false] - Whether to update original data with current data
*/
request: function(requestType, options) {
var defaultOptions = {
url: this.api[requestType],
type: null,
hasDataParam: true,
isOnlyChecked: true,
isOnlyModified: true,
isSkipConfirm: false
},
newOptions = $.extend(defaultOptions, options),
param = this._getRequestParam(requestType, newOptions);
var newOptions = _.extend({
url: this.api[requestType],
type: null,
hasDataParam: true,
isOnlyChecked: true,
isOnlyModified: true,
isSkipConfirm: false,
isUpdateOriginal: false
}, options);
var param = this._getRequestParam(requestType, newOptions);

if (param) {
if (newOptions.isUpdateOriginal) {
this.dataModel.setOriginalRowList();
}
this._ajax(param);
}
},
Expand Down
8 changes: 8 additions & 0 deletions test/unit/js/addon/net.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,14 @@ describe('addon.net', function() {
net.request('createData');
expect(net._ajax).not.toHaveBeenCalled();
});

it('call setOriginalRowList() if isUpdateOriginal is true', function() {
spyOn(net.dataModel, 'setOriginalRowList');
net.request('updateData', {
isUpdateOriginal: true
});
expect(net.dataModel.setOriginalRowList).toHaveBeenCalled();
});
});

describe('request', function() {
Expand Down

0 comments on commit df9207f

Please sign in to comment.