From 23c76c15ec36b125d9b0696504321341aebbb9c2 Mon Sep 17 00:00:00 2001 From: vbarkasov Date: Fri, 23 Mar 2018 20:06:03 +0700 Subject: [PATCH] Add pagination request method --- src/apps/callflows/app.js | 52 +++++++++++++++++++ .../submodules/callcenter/callcenter.js | 6 +-- 2 files changed, 55 insertions(+), 3 deletions(-) diff --git a/src/apps/callflows/app.js b/src/apps/callflows/app.js index afd6391..fba4a53 100644 --- a/src/apps/callflows/app.js +++ b/src/apps/callflows/app.js @@ -1915,6 +1915,58 @@ define(function(require){ input.unbind('.link'); } }); + }, + getAll: function(callApiData, startKey, continueData) { + // Warning! Method works for listed data only! + // -- Usage: + // self.getAll({ + // resource: 'user.list', + // success: function(result){}, + // error: function(data){}, + // data: { + // someParam: someValue + // } + // }) + + continueData = continueData || { data:[] }; + var self = this; + + if(typeof(callApiData.resource) === 'undefined') { + self.log('Error! Api keyword is undefined'); + return; + } + + var requestData = $.extend({ + accountId: self.accountId, + generateError: false + }, callApiData.data || {}); + + if(typeof(startKey) !== 'undefined') { + requestData.startKey = startKey; + } + + var newRequestData = { + resource: callApiData.resource, + data: requestData, + success: function(response){ + response.data = $.merge(continueData.data, response.data); + if(response.next_start_key && startKey !== response.next_start_key) { + self.getAll(callApiData, response.next_start_key, response); + return; + } + + if(typeof(callApiData.success) === 'function') { + callApiData.success(response); + } + }, + error: callApiData.error || function(){} + }; + + if(self.requests.hasOwnProperty(callApiData.resource)) { + monster.request(newRequestData); + } else { + self.callApi(newRequestData); + } } }; diff --git a/src/apps/callflows/submodules/callcenter/callcenter.js b/src/apps/callflows/submodules/callcenter/callcenter.js index fbfa1f1..d035e24 100644 --- a/src/apps/callflows/submodules/callcenter/callcenter.js +++ b/src/apps/callflows/submodules/callcenter/callcenter.js @@ -170,7 +170,7 @@ define(function(require){ }); }, listEntities: function(callback) { - monster.request({ + self.getAll({ resource: 'callcenter.queues.list', data: { accountId: self.accountId, @@ -435,7 +435,7 @@ define(function(require){ getUsersList: function(callback) { var self = this; - self.callApi({ + self.getAll({ resource: 'user.list', data: { accountId: self.accountId, @@ -480,7 +480,7 @@ define(function(require){ getQueuesList: function(callback) { var self = this; - monster.request({ + self.getAll({ resource: 'callcenter.queues.list', data: { accountId: self.accountId,