SessionDataAdaptor.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. "use strict";
  2. /**
  3. *  * Licensed Materials - Property of IBM  * IBM Cognos Products: Cognos
  4. * Analytics  * Copyright IBM Corp. 2015, 2016  * US Government Users Restricted
  5. * Rights - Use, duplication or disclosure restricted by GSA ADP Schedule
  6. * Contract with IBM Corp.  
  7. */
  8. define(['doT', 'q', 'jquery', 'underscore', 'bi/admin/nls/StringResource', 'bi/admin/common/ui/listview/ListDataAdaptor'], function (dot, Q, $, _, StringResource, ListDataAdaptor) {
  9. var SessionDataAdaptor = ListDataAdaptor.extend({
  10. pageSize: 2000,
  11. session: null,
  12. init: function init(options) {
  13. SessionDataAdaptor.inherited('init', this, arguments);
  14. $.extend(this, options);
  15. },
  16. hasMore: function hasMore() {
  17. return this.hasNextPage();
  18. },
  19. onConditionChanged: function onConditionChanged() {
  20. this.clearSession();
  21. },
  22. _hasSecondaryRequest: function _hasSecondaryRequest(name) {
  23. var found = null;
  24. var sr = this.session ? this.session['secondaryRequest'] : null;
  25. if (sr) {
  26. found = _.find(sr, function (item) {
  27. return item.name === name;
  28. });
  29. }
  30. return !!found;
  31. },
  32. hasNextPage: function hasNextPage() {
  33. return this._hasSecondaryRequest('nextPage');
  34. },
  35. hasRelease: function hasRelease() {
  36. return this._hasSecondaryRequest('release');
  37. },
  38. clearSession: function clearSession() {
  39. this.session = null;
  40. },
  41. getResultRowsKey: function getResultRowsKey() {
  42. if (this.activityType === 'schedule') {
  43. return 'schedules';
  44. } else {
  45. return 'activities';
  46. }
  47. },
  48. cacheSession: function cacheSession(result) {
  49. this.session = null;
  50. this.session = _.pick(result, 'secondaryRequest', 'primaryRequest', 'tracking', this.getResultRowsKey());
  51. }
  52. });
  53. return SessionDataAdaptor;
  54. });