CreateBusinessMetadataLayoutView.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. define([ "require", "backbone", "hbs!tmpl/business_metadata/CreateBusinessMetadataLayoutView_tmpl", "utils/Utils", "utils/Messages", "views/business_metadata/BusinessMetadataAttributeItemView", "models/VEntity" ], function(require, Backbone, CreateBusinessMetadataLayoutViewTmpl, Utils, Messages, BusinessMetadataAttributeItemView, VEntity) {
  2. var CreateBusinessMetadataLayoutView = Backbone.Marionette.CompositeView.extend({
  3. _viewName: "CreateBusinessMetadataLayoutView",
  4. template: CreateBusinessMetadataLayoutViewTmpl,
  5. templateHelpers: function() {
  6. return {
  7. create: this.create,
  8. description: this.description,
  9. fromTable: this.fromTable,
  10. isEditAttr: this.isEditAttr
  11. };
  12. },
  13. regions: {},
  14. childView: BusinessMetadataAttributeItemView,
  15. childViewContainer: "[data-id='addAttributeDiv']",
  16. childViewOptions: function() {
  17. return {
  18. typeHeaders: this.typeHeaders,
  19. businessMetadataDefCollection: this.businessMetadataDefCollection,
  20. enumDefCollection: this.enumDefCollection,
  21. isAttrEdit: this.isAttrEdit,
  22. viewId: this.cid,
  23. collection: this.collection
  24. };
  25. },
  26. ui: {
  27. name: "[data-id='name']",
  28. description: "[data-id='description']",
  29. title: "[data-id='title']",
  30. attributeData: "[data-id='attributeData']",
  31. addAttributeDiv: "[data-id='addAttributeDiv']",
  32. createForm: '[data-id="createForm"]',
  33. businessMetadataAttrPageCancle: '[data-id="businessMetadataAttrPageCancle"]',
  34. businessMetadataAttrPageOk: '[data-id="businessMetadataAttrPageOk"]'
  35. },
  36. events: function() {
  37. var events = {};
  38. return events["click " + this.ui.attributeData] = "onClickAddAttriBtn", events["click " + this.ui.businessMetadataAttrPageOk] = function(e) {
  39. var that = this;
  40. that.$el;
  41. "attributeEdit" == e.target.dataset.action || "addAttribute" == e.target.dataset.action ? that.onUpdateAttr() : that.onCreateBusinessMetadata();
  42. }, events["click " + this.ui.businessMetadataAttrPageCancle] = function(e) {
  43. this.options.onUpdateBusinessMetadata();
  44. }, events;
  45. },
  46. initialize: function(options) {
  47. _.extend(this, _.pick(options, "businessMetadataDefCollection", "selectedBusinessMetadata", "enumDefCollection", "model", "isNewBusinessMetadata", "isAttrEdit", "typeHeaders", "attrDetails")),
  48. this.fromTable = !!this.isNewBusinessMetadata, this.isEditAttr = !this.isAttrEdit,
  49. this.businessMetadataModel = new VEntity(), this.model ? this.description = this.model.get("description") : this.create = !0,
  50. this.isNewBusinessMetadata ? this.collection = new Backbone.Collection() : this.collection = this.isAttrEdit ? new Backbone.Collection([ this.attrDetails ]) : new Backbone.Collection([ {
  51. name: "",
  52. typeName: "string",
  53. isOptional: !0,
  54. cardinality: "SINGLE",
  55. valuesMinCount: 0,
  56. valuesMaxCount: 1,
  57. isUnique: !1,
  58. isIndexable: !0
  59. } ]);
  60. },
  61. bindEvents: function() {},
  62. onRender: function() {
  63. var that = this;
  64. this.$(".fontLoader").show(), "placeholder" in HTMLInputElement.prototype || this.ui.createForm.find("input,textarea").placeholder(),
  65. 1 == this.isNewBusinessMetadata ? (that.ui.businessMetadataAttrPageOk.text("Create"),
  66. that.ui.businessMetadataAttrPageOk.attr("data-action", "newBusinessMetadata")) : (that.ui.businessMetadataAttrPageOk.text("Save"),
  67. that.ui.businessMetadataAttrPageOk.attr("data-action", "attributeEdit")), this.hideLoader();
  68. },
  69. hideLoader: function() {
  70. this.$(".fontLoader").hide(), this.$(".hide").removeClass("hide");
  71. },
  72. collectionAttribute: function() {
  73. this.collection.add(new Backbone.Model({
  74. name: "",
  75. typeName: "string",
  76. isOptional: !0,
  77. cardinality: "SINGLE",
  78. valuesMinCount: 0,
  79. valuesMaxCount: 1,
  80. isUnique: !1,
  81. isIndexable: !0
  82. }));
  83. },
  84. onClickAddAttriBtn: function() {
  85. this.collectionAttribute(), "placeholder" in HTMLInputElement.prototype || this.ui.addAttributeDiv.find("input,textarea").placeholder();
  86. },
  87. loaderStatus: function(isActive) {
  88. isActive ? (parent.$(".business-metadata-attr-tableOverlay").show(), parent.$(".business-metadata-attr-fontLoader").show()) : (parent.$(".business-metadata-attr-tableOverlay").hide(),
  89. parent.$(".business-metadata-attr-fontLoader").hide());
  90. },
  91. validateValues: function(attributeDefs) {
  92. var isValidate = !0, isAttrDuplicate = !0, validationFileds = this.$el.find(".require"), attrNames = [];
  93. return attributeDefs && !this.isAttrEdit && (attrNames = _.map(attributeDefs, function(model) {
  94. return model.name.toLowerCase();
  95. })), validationFileds.each(function(elements) {
  96. $(this).removeClass("errorValidate"), "" != validationFileds[elements].value.trim() && null != validationFileds[elements].value || "none" != validationFileds[elements].style.display && ($(validationFileds[elements]).addClass("errorValidate"),
  97. $(this).addClass("errorValidate"), isValidate && (isValidate = !1));
  98. }), isValidate && this.$el.find(".attributeInput").each(function(element) {
  99. var attrValue = this.value.toLowerCase();
  100. attrNames.indexOf(attrValue) > -1 ? (Utils.notifyInfo({
  101. content: "Attribute name already exist"
  102. }), $(this).addClass("errorValidate"), isAttrDuplicate && (isAttrDuplicate = !1)) : attrValue.length && attrNames.push(attrValue);
  103. }), isValidate ? !isAttrDuplicate || void 0 : (Utils.notifyInfo({
  104. content: "Please fill the details"
  105. }), !0);
  106. },
  107. onCreateBusinessMetadata: function() {
  108. var that = this;
  109. if (!this.validateValues()) {
  110. this.loaderStatus(!0);
  111. var name = this.ui.name.val(), description = this.ui.description.val(), attributeObj = this.collection.toJSON();
  112. 1 === this.collection.length && "" === this.collection.first().get("name") && (attributeObj = []),
  113. this.json = {
  114. enumDefs: [],
  115. structDefs: [],
  116. classificationDefs: [],
  117. entityDefs: [],
  118. businessMetadataDefs: [ {
  119. category: "BUSINESS_METADATA",
  120. createdBy: "admin",
  121. updatedBy: "admin",
  122. version: 1,
  123. typeVersion: "1.1",
  124. name: name.trim(),
  125. description: description.trim(),
  126. attributeDefs: attributeObj
  127. } ]
  128. };
  129. var apiObj = {
  130. sort: !1,
  131. data: this.json,
  132. success: function(model, response) {
  133. var nameSpaveDef = model.businessMetadataDefs;
  134. nameSpaveDef && (that.businessMetadataDefCollection.fullCollection.add(nameSpaveDef),
  135. Utils.notifySuccess({
  136. content: "业务元数据 " + name + Messages.getAbbreviationMsg(!1, "addSuccessMessage")
  137. })), that.options.onUpdateBusinessMetadata(!0);
  138. },
  139. silent: !0,
  140. reset: !0,
  141. complete: function(model, status) {
  142. that.loaderStatus(!1);
  143. }
  144. };
  145. apiObj.type = "POST", that.businessMetadataModel.saveBusinessMetadata(apiObj);
  146. }
  147. },
  148. onUpdateAttr: function() {
  149. var that = this, selectedBusinessMetadataClone = $.extend(!0, {}, that.selectedBusinessMetadata.toJSON()), attributeDefs = selectedBusinessMetadataClone.attributeDefs;
  150. if (!this.validateValues(attributeDefs)) if (this.collection.length > 0) {
  151. this.loaderStatus(!0), void 0 === selectedBusinessMetadataClone.attributeDefs && (selectedBusinessMetadataClone.attributeDefs = []),
  152. selectedBusinessMetadataClone.attributeDefs = selectedBusinessMetadataClone.attributeDefs.concat(this.collection.toJSON()),
  153. this.json = {
  154. enumDefs: [],
  155. structDefs: [],
  156. classificationDefs: [],
  157. entityDefs: [],
  158. businessMetadataDefs: [ selectedBusinessMetadataClone ]
  159. };
  160. var apiObj = {
  161. sort: !1,
  162. data: this.json,
  163. success: function(model, response) {
  164. Utils.notifySuccess({
  165. content: "一个或多个业务元数据属性" + Messages.getAbbreviationMsg(!0, "editSuccessMessage")
  166. }), model.businessMetadataDefs && model.businessMetadataDefs.length && that.selectedBusinessMetadata.set(model.businessMetadataDefs[0]),
  167. that.options.onEditCallback(), that.options.onUpdateBusinessMetadata(!0);
  168. },
  169. silent: !0,
  170. reset: !0,
  171. complete: function(model, status) {
  172. that.loaderStatus(!1);
  173. }
  174. };
  175. apiObj.type = "PUT", that.businessMetadataModel.saveBusinessMetadata(apiObj);
  176. } else Utils.notifySuccess({
  177. content: "No attribute updated"
  178. }), this.loaderStatus(!1), that.options.onUpdateBusinessMetadata();
  179. }
  180. });
  181. return CreateBusinessMetadataLayoutView;
  182. });