SaveSearchView.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. define([ "require", "backbone", "hbs!tmpl/search/save/SaveSearchView_tmpl", "views/search/save/SaveSearchItemView", "collection/VSearchList", "utils/Utils", "utils/UrlLinks", "utils/CommonViewFunction", "utils/Messages" ], function(require, Backbone, SaveSearchViewTmpl, SaveSearchItemView, VSearchList, Utils, UrlLinks, CommonViewFunction, Messages) {
  2. "use strict";
  3. return Backbone.Marionette.CompositeView.extend({
  4. template: SaveSearchViewTmpl,
  5. childView: SaveSearchItemView,
  6. childViewContainer: "[data-id='itemViewContent']",
  7. ui: {
  8. saveAs: "[data-id='saveAsBtn']",
  9. save: "[data-id='saveBtn']"
  10. },
  11. childViewOptions: function() {
  12. return {
  13. collection: this.collection,
  14. typeHeaders: this.typeHeaders,
  15. applyValue: this.applyValue,
  16. isBasic: this.isBasic,
  17. classificationDefCollection: this.classificationDefCollection,
  18. entityDefCollection: this.entityDefCollection,
  19. fetchFavioriteCollection: this.fetchCollection.bind(this),
  20. searchTypeObj: this.searchTypeObj
  21. };
  22. },
  23. childEvents: function() {
  24. return {
  25. "item:clicked": function() {
  26. this.ui.save.attr("disabled", !1);
  27. }
  28. };
  29. },
  30. events: function() {
  31. var events = {};
  32. return events["click " + this.ui.saveAs] = "saveAs", events["click " + this.ui.save] = "save",
  33. events;
  34. },
  35. initialize: function(options) {
  36. _.extend(this, _.pick(options, "collection", "value", "searchVent", "typeHeaders", "applyValue", "getValue", "isBasic", "fetchCollection", "classificationDefCollection", "entityDefCollection")),
  37. this.searchTypeObj = {
  38. searchType: "dsl",
  39. dslChecked: "true"
  40. }, this.isBasic && (this.searchTypeObj.dslChecked = !1, this.searchTypeObj.searchType = "basic");
  41. },
  42. onRender: function() {
  43. this.bindEvents();
  44. },
  45. bindEvents: function() {
  46. var that = this;
  47. this.listenTo(this.collection, "add reset error remove", function(model, collection) {
  48. this.$(".fontLoader-relative").hide(), this.collection && this.collection.length ? this.$(".noFavoriteSearch").hide() : this.$(".noFavoriteSearch").show();
  49. }, this), $("body").on("click", ".saveSearchPopoverList_" + (this.isBasic ? "isBasic" : "isAdvance") + " li", function(e) {
  50. that.$(".saveSearchPopover").popover("hide");
  51. var id = $(this).parent("ul").data("id");
  52. that[$(this).find("a").data("fn")]({
  53. model: that.collection.find({
  54. guid: id
  55. })
  56. });
  57. });
  58. },
  59. saveAs: function(e) {
  60. var value = this.getValue();
  61. value && (value.type || value.tag || value.query || value.term) ? this.callSaveModalLayoutView({
  62. collection: this.collection,
  63. getValue: this.getValue,
  64. isBasic: this.isBasic
  65. }) : Utils.notifyInfo({
  66. content: Messages.search.favoriteSearch.notSelectedSearchFilter
  67. });
  68. },
  69. save: function() {
  70. var that = this, obj = {}, notifyObj = {
  71. modal: !0,
  72. html: !0,
  73. ok: function(argument) {
  74. that.callSaveModalLayoutView({
  75. saveObj: obj,
  76. collection: that.collection,
  77. getValue: that.getValue,
  78. isBasic: that.isBasic
  79. });
  80. },
  81. cancel: function(argument) {}
  82. }, selectedEl = this.$(".saveSearchList li.active").find("div.item");
  83. obj.name = selectedEl.find("a").text(), obj.guid = selectedEl.data("id"), selectedEl && selectedEl.length ? (notifyObj.text = Messages.search.favoriteSearch.save + " <b>" + _.escape(obj.name) + "</b> ?",
  84. Utils.notifyConfirm(notifyObj)) : Utils.notifyInfo({
  85. content: Messages.search.favoriteSearch.notSelectedFavoriteElement
  86. });
  87. },
  88. callSaveModalLayoutView: function(options) {
  89. require([ "views/search/save/SaveModalLayoutView" ], function(SaveModalLayoutView) {
  90. new SaveModalLayoutView(options);
  91. });
  92. },
  93. onSearch: function(options) {
  94. if (options && options.model) {
  95. var searchParameters = options.model.toJSON().searchParameters, params = CommonViewFunction.generateUrlFromSaveSearchObject({
  96. value: {
  97. searchParameters: searchParameters,
  98. uiParameters: options.model.get("uiParameters")
  99. },
  100. classificationDefCollection: this.classificationDefCollection,
  101. entityDefCollection: this.entityDefCollection
  102. });
  103. Utils.setUrl({
  104. url: "#!/search/searchResult",
  105. urlParams: _.extend({}, this.searchTypeObj, params),
  106. mergeBrowserUrl: !1,
  107. trigger: !0,
  108. updateTabState: !0
  109. });
  110. }
  111. },
  112. onRename: function(options) {
  113. if (options && options.model) {
  114. var that = this;
  115. require([ "views/search/save/SaveModalLayoutView" ], function(SaveModalLayoutView) {
  116. new SaveModalLayoutView({
  117. selectedModel: options.model,
  118. collection: that.collection,
  119. getValue: that.getValue,
  120. isBasic: that.isBasic
  121. });
  122. });
  123. }
  124. },
  125. onDelete: function(options) {
  126. if (options && options.model) {
  127. var that = this, notifyObj = {
  128. modal: !0,
  129. html: !0,
  130. text: Messages.conformation.deleteMessage + "<b>" + _.escape(options.model.get("name")) + "</b> ?",
  131. ok: function(argument) {
  132. that.onDeleteNotifyOk(options);
  133. },
  134. cancel: function(argument) {}
  135. };
  136. Utils.notifyConfirm(notifyObj);
  137. }
  138. },
  139. onDeleteNotifyOk: function(options) {
  140. var that = this;
  141. options.model.urlRoot = UrlLinks.saveSearchApiUrl(), options.model.destroy({
  142. wait: !0,
  143. success: function(model, data) {
  144. that.collection && that.collection.remove(model), Utils.notifySuccess({
  145. content: options.model.get("name") + Messages.getAbbreviationMsg(!1, "deleteSuccessMessage")
  146. });
  147. }
  148. });
  149. }
  150. });
  151. });