CommonViewFunction.js 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  1. define([ "require", "utils/Utils", "modules/Modal", "utils/Messages", "utils/Enums", "moment", "utils/Globals", "moment-timezone" ], function(require, Utils, Modal, Messages, Enums, moment, Globals) {
  2. "use strict";
  3. var CommonViewFunction = {};
  4. return CommonViewFunction.deleteTag = function(options) {
  5. require([ "models/VTag" ], function(VTag) {
  6. if (options && options.guid && options.tagName) {
  7. var tagModel = new VTag(), noticeRef = null, notifyObj = {
  8. modal: !0,
  9. okCloses: !1,
  10. okShowLoader: !0,
  11. text: options.msg,
  12. title: options.titleMessage,
  13. okText: options.okText,
  14. ok: function(notice) {
  15. noticeRef = notice, options.showLoader && options.showLoader(), tagModel.deleteAssociation(options.guid, options.tagName, options.associatedGuid, {
  16. defaultErrorMessage: options.tagName + Messages.deleteErrorMessage,
  17. success: function(data) {
  18. noticeRef && noticeRef.remove(), Utils.notifySuccess({
  19. content: "Classification " + options.tagName + Messages.getAbbreviationMsg(!1, "removeSuccessMessage")
  20. }), options.callback && options.callback(), options.collection && options.collection.fetch({
  21. reset: !0
  22. });
  23. },
  24. cust_error: function(model, response) {
  25. noticeRef && noticeRef.hideButtonLoader(), options.hideLoader && options.hideLoader();
  26. }
  27. });
  28. },
  29. cancel: function(argument) {
  30. options.hideLoader && options.hideLoader();
  31. }
  32. };
  33. Utils.notifyConfirm(notifyObj);
  34. }
  35. });
  36. }, CommonViewFunction.propertyTable = function(options) {
  37. var scope = options.scope, sortBy = options.sortBy, valueObject = options.valueObject, extractJSON = options.extractJSON, getArrayOfStringElement = options.getArrayOfStringElement, getArrayOfStringFormat = options.getArrayOfStringFormat, isTable = !!_.isUndefined(options.isTable) || options.isTable, attributeDefs = options.attributeDefs, formatIntVal = options.formatIntVal, showListCount = options.showListCount || !0, highlightString = options.highlightString, formatStringVal = options.formatStringVal, numberFormat = options.numberFormat || _.numberFormatWithComma, table = "", getHighlightedString = function(resultStr) {
  38. if (!highlightString || !highlightString.length) return resultStr;
  39. try {
  40. return resultStr.replace(new RegExp(highlightString, "gi"), function(foundStr) {
  41. return "<span class='searched-term-highlight'>" + foundStr + "</span>";
  42. });
  43. } catch (error) {
  44. return resultStr;
  45. }
  46. }, getEmptyString = function(key) {
  47. return options.getEmptyString ? options.getEmptyString(key) : "N/A";
  48. }, getValue = function(val, key) {
  49. if (options && options.getValue && (val = options.getValue(val, key)), _.isUndefined(val) || _.isNull(val)) return getEmptyString(key);
  50. if (!_.isNumber(val) && _.isNaN(parseInt(val)) || !formatIntVal) {
  51. var newVal = val;
  52. return formatStringVal && (newVal = parseInt(val), newVal = _.isNaN(newVal) ? val : numberFormat(newVal)),
  53. getHighlightedString(_.escape(newVal));
  54. }
  55. return numberFormat(val);
  56. }, fetchInputOutputValue = function(id, defEntity) {
  57. scope.entityModel.getEntityHeader(id, {
  58. success: function(serverData) {
  59. var value = "", deleteButton = "", data = serverData;
  60. value = Utils.getName(data);
  61. var id = "";
  62. data.guid && (Enums.entityStateReadOnly[data.status || data.entityStatus] && (deleteButton += '<button title="Deleted" class="btn btn-action btn-md deleteBtn"><i class="fa fa-trash"></i></button>'),
  63. id = data.guid), value.length > 0 ? scope.$('td div[data-id="' + id + '"]').html('<a href="#!/detailPage/' + id + '">' + getValue(value) + "</a>") : scope.$('td div[data-id="' + id + '"]').html('<a href="#!/detailPage/' + id + '">' + _.escape(id) + "</a>"),
  64. deleteButton.length && (scope.$('td div[data-id="' + id + '"]').addClass("block readOnlyLink"),
  65. scope.$('td div[data-id="' + id + '"]').append(deleteButton));
  66. },
  67. cust_error: function(error, xhr) {
  68. 403 == xhr.status ? scope.$('td div[data-id="' + id + '"]').html('<div><span class="text-danger"><i class="fa fa-exclamation-triangle" aria-hidden="true"></i> Not Authorized</span></div>') : defEntity && defEntity.options && "true" === defEntity.options.isSoftReference ? scope.$('td div[data-id="' + id + '"]').html("<div> " + id + "</div>") : scope.$('td div[data-id="' + id + '"]').html('<div><span class="text-danger"><i class="fa fa-exclamation-triangle" aria-hidden="true"></i> ' + Messages.defaultErrorMessage + "</span></div>");
  69. },
  70. complete: function() {}
  71. });
  72. }, extractObject = function(opt) {
  73. var valueOfArray = [], keyValue = opt.keyValue, key = opt.key, defEntity = opt.defEntity;
  74. !_.isArray(keyValue) && _.isObject(keyValue) && (keyValue = [ keyValue ]);
  75. for (var subLink = "", i = 0; i < keyValue.length; i++) {
  76. var inputOutputField = keyValue[i], id = inputOutputField.guid || (_.isObject(inputOutputField.id) ? inputOutputField.id.id : inputOutputField.id), tempLink = "", status = inputOutputField.status || inputOutputField.entityStatus || (_.isObject(inputOutputField.id) ? inputOutputField.id.state : inputOutputField.state), readOnly = Enums.entityStateReadOnly[status];
  77. if (!inputOutputField.attributes && inputOutputField.values && (inputOutputField.attributes = inputOutputField.values),
  78. _.isString(inputOutputField) || _.isBoolean(inputOutputField) || _.isNumber(inputOutputField)) {
  79. var tempVarfor$check = inputOutputField.toString();
  80. if (tempVarfor$check.indexOf("$") == -1) {
  81. var tmpVal = getValue(inputOutputField, key);
  82. getArrayOfStringElement ? valueOfArray.push(getArrayOfStringElement(tmpVal, key)) : valueOfArray.push('<span class="json-string">' + tmpVal + "</span>");
  83. }
  84. } else if (_.isObject(inputOutputField) && !id) {
  85. var attributesList = inputOutputField;
  86. if (scope.typeHeaders && inputOutputField.typeName) {
  87. var typeNameCategory = scope.typeHeaders.fullCollection.findWhere({
  88. name: inputOutputField.typeName
  89. });
  90. attributesList.attributes && typeNameCategory && "STRUCT" === typeNameCategory.get("category") && (attributesList = attributesList.attributes);
  91. }
  92. if (extractJSON && extractJSON.extractKey) {
  93. var newAttributesList = {};
  94. _.each(attributesList, function(objValue, objKey) {
  95. var value = _.isObject(objValue) ? objValue : _.escape(objValue), tempVarfor$check = objKey.toString();
  96. tempVarfor$check.indexOf("$") == -1 && (_.isObject(extractJSON.extractKey) ? _.each(extractJSON.extractKey, function(extractKey) {
  97. objKey === extractKey && (newAttributesList[_.escape(objKey)] = value);
  98. }) : _.isString(extractJSON.extractKey) && extractJSON.extractKey === objKey && (newAttributesList[_.escape(objKey)] = value));
  99. }), valueOfArray.push(Utils.JSONPrettyPrint(newAttributesList, getValue));
  100. } else valueOfArray.push(Utils.JSONPrettyPrint(attributesList, getValue));
  101. }
  102. if (id && inputOutputField) {
  103. var name = Utils.getName(inputOutputField);
  104. if ("-" !== name && name !== id || inputOutputField.attributes) tempLink += "AtlasGlossaryTerm" == inputOutputField.typeName ? '<a href="#!/glossary/' + id + "?guid=" + id + '&gType=term&viewType=term">' + name + "</a>" : '<a href="#!/detailPage/' + id + '">' + name + "</a>"; else {
  105. var fetch = !0, fetchId = _.isObject(id) ? id.id : id;
  106. fetchInputOutputValue(fetchId, defEntity), tempLink += '<div data-id="' + fetchId + '"><div class="value-loader"></div></div>';
  107. }
  108. }
  109. readOnly ? fetch ? (fetch = !1, subLink += tempLink) : (tempLink += '<button title="Deleted" class="btn btn-action btn-md deleteBtn"><i class="fa fa-trash"></i></button>',
  110. subLink += '<div class="block readOnlyLink">' + tempLink + "</div>") : tempLink.search("href") != -1 ? subLink += "<div>" + tempLink + "</div>" : tempLink.length && (subLink += tempLink);
  111. }
  112. return valueOfArray.length && (subLink = getArrayOfStringFormat ? getArrayOfStringFormat(valueOfArray, key) : valueOfArray.join(", ")),
  113. "" === subLink ? getEmptyString(key) : subLink;
  114. }, valueObjectKeysList = _.keys(valueObject);
  115. return (_.isUndefined(sortBy) || 1 == sortBy) && (valueObjectKeysList = _.sortBy(valueObjectKeysList)),
  116. valueObjectKeysList.map(function(key) {
  117. if ("profileData" != key) {
  118. var keyValue = valueObject[key], listCount = showListCount && _.isArray(keyValue) && keyValue.length > 0 ? " (" + numberFormat(keyValue.length) + ")" : "", defEntity = _.find(attributeDefs, {
  119. name: key
  120. });
  121. if (defEntity && defEntity.typeName) {
  122. var defEntityType = defEntity.typeName.toLocaleLowerCase();
  123. "date" === defEntityType ? keyValue = keyValue > 0 ? Utils.formatDate({
  124. date: keyValue
  125. }) : null : _.isObject(keyValue) && (keyValue = extractObject({
  126. keyValue: keyValue,
  127. key: key,
  128. defEntity: defEntity
  129. }));
  130. } else _.isObject(keyValue) && (keyValue = extractObject({
  131. keyValue: keyValue,
  132. key: key
  133. }));
  134. var val = "";
  135. if (val = _.isObject(valueObject[key]) ? keyValue : "guid" === key || "__guid" === key ? options.guidHyperLink === !1 ? getValue(keyValue, key) : '<a title="' + key + '" href="#!/detailPage/' + _.escape(keyValue) + '">' + getValue(keyValue, key) + "</a>" : getValue(keyValue, key),
  136. isTable) {
  137. var value = val, appendClass = "N/A" == value ? "hide-row" : "", htmlTag = '<div class="scroll-y">' + value + "</div>";
  138. if (_.isObject(valueObject[key]) && !_.isEmpty(valueObject[key])) {
  139. var matchedLinkString = val.match(/href|value-loader\w*/g), matchedJson = val.match(/json-value|json-string\w*/g), isMatchJSONStringIsSingle = (val.match(/json-key\w*/g),
  140. matchedLinkString && matchedLinkString.length <= 5, matchedJson && 1 == matchedJson.length), expandCollapseButton = "";
  141. if (matchedJson || matchedLinkString) {
  142. var className = "code-block fixed-height";
  143. isMatchJSONStringIsSingle || (className += " shrink", expandCollapseButton = '<button class="expand-collapse-button"><i class="fa"></i></button>'),
  144. htmlTag = '<pre class="' + className + '">' + expandCollapseButton + "<code>" + val + "</code></pre>";
  145. }
  146. }
  147. table += '<tr class="' + appendClass + '"><td>' + (_.escape(key) + listCount) + "</td><td>" + htmlTag + "</td></tr>";
  148. } else table += "<span>" + val + "</span>";
  149. }
  150. }), table && table.length > 0 ? table : '<tr class="empty"><td colspan="22"><span>No Record found!</span></td></tr>';
  151. }, CommonViewFunction.tagForTable = function(obj) {
  152. var traits = obj.classifications, tagHtml = "", addTag = "", popTag = "", count = 0, entityName = Utils.getName(obj);
  153. return traits && traits.map(function(tag) {
  154. var className = "btn btn-action btn-sm btn-blue btn-icon", deleteIcon = "";
  155. obj.guid === tag.entityGuid ? deleteIcon = '<i class="fa fa-times" data-id="delete" data-assetname="' + entityName + '" data-name="' + tag.typeName + '" data-type="tag" data-guid="' + obj.guid + '" ></i>' : obj.guid !== tag.entityGuid && "DELETED" === tag.entityStatus ? deleteIcon = '<i class="fa fa-times" data-id="delete" data-assetname="' + entityName + '" data-name="' + tag.typeName + '" data-type="tag" data-entityguid="' + tag.entityGuid + '" data-guid="' + obj.guid + '" ></i>' : className += " propagte-classification";
  156. var tagString = '<a class="' + className + '" data-id="tagClick"><span title="' + tag.typeName + '">' + tag.typeName + "</span>" + deleteIcon + "</a>";
  157. count >= 1 ? popTag += tagString : tagHtml += tagString, ++count;
  158. }), Enums.entityStateReadOnly[obj.status || obj.entityStatus] || (addTag += obj.guid ? '<a href="javascript:void(0)" data-id="addTag" class="btn btn-action btn-sm assignTag" data-guid="' + obj.guid + '" ><i class="fa fa-plus"></i></a>' : '<a href="javascript:void(0)" data-id="addTag" class="btn btn-action btn-sm assignTag"><i style="right:0" class="fa fa-plus"></i></a>'),
  159. count > 1 && (addTag += '<div data-id="showMoreLess" class="btn btn-action btn-sm assignTag"><i class="fa fa-ellipsis-h" aria-hidden="true"></i><div class="popup-tag-term">' + popTag + "</div></div>"),
  160. '<div class="tagList btn-inline btn-fixed-width">' + tagHtml + addTag + "</div>";
  161. }, CommonViewFunction.termForTable = function(obj) {
  162. var terms = obj.meanings, termHtml = "", addTerm = "", popTerm = "", count = 0, entityName = Utils.getName(obj);
  163. return terms && terms.map(function(term) {
  164. var displayText = _.escape(term.displayText), className = "btn btn-action btn-sm btn-blue btn-icon", deleteIcon = '<i class="fa fa-times" data-id="delete" data-assetname="' + entityName + '" data-name="' + displayText + '" data-type="term" data-guid="' + obj.guid + '" data-termGuid="' + term.termGuid + '" ></i>', termString = '<a class="' + className + '" data-id="termClick"><span title="' + displayText + '">' + displayText + "</span>" + deleteIcon + "</a>";
  165. count >= 1 ? popTerm += termString : termHtml += termString, ++count;
  166. }), Enums.entityStateReadOnly[obj.status || obj.entityStatus] || (addTerm += obj.guid ? '<a href="javascript:void(0)" data-id="addTerm" class="btn btn-action btn-sm assignTag" data-guid="' + obj.guid + '" ><i class="fa fa-plus"></i></a>' : '<a href="javascript:void(0)" data-id="addTerm" class="btn btn-action btn-sm assignTag"><i style="right:0" class="fa fa-plus"></i></a>'),
  167. count > 1 && (addTerm += '<div data-id="showMoreLess" class="btn btn-action btn-sm assignTerm"><i class="fa fa-ellipsis-h" aria-hidden="true"></i><div class="popup-tag-term">' + popTerm + "</div></div>"),
  168. '<div class="tagList btn-inline btn-fixed-width">' + termHtml + addTerm + "</div>";
  169. }, CommonViewFunction.generateQueryOfFilter = function(value, isCapsuleView) {
  170. function objToString(filterObj, type) {
  171. var generatedQuery = _.map(filterObj.rules, function(obj, key) {
  172. var obj = $.extend(!0, {}, obj);
  173. return _.has(obj, "condition") ? '<span class="operator">' + obj.condition + "</span>(" + objToString(obj).join("") + ")" : isCapsuleView ? ("date" === obj.type && (Enums.queryBuilderDateRangeUIValueToAPI[obj.value] ? obj.value = Enums.queryBuilderDateRangeUIValueToAPI[obj.value] : obj.value = obj.value + " (" + moment.tz(moment.tz.guess()).zoneAbbr() + ")"),
  174. '<div class="capsuleView"><span class="key">' + (Enums.systemAttributes[obj.id] ? Enums.systemAttributes[obj.id] : _.escape(obj.id)) + '</span><span class="operator">' + _.escape(obj.operator) + '</span><span class="value">' + (Enums[obj.id] ? Enums[obj.id][obj.value] : _.escape(obj.value)) + '</span><div class="fa fa-close clear-attr" data-type=' + type + ' data-id="' + _.escape(obj.id) + key + '"></div></div>') : '<span class="key">' + (Enums.systemAttributes[obj.id] ? Enums.systemAttributes[obj.id] : _.escape(obj.id)) + '</span><span class="operator">' + _.escape(obj.operator) + '</span><span class="value">' + (Enums[obj.id] ? Enums[obj.id][obj.value] : _.escape(obj.value)) + "</span>";
  175. });
  176. return generatedQuery;
  177. }
  178. value = Utils.getUrlState.getQueryParams();
  179. var entityFilters = CommonViewFunction.attributeFilter.extractUrl({
  180. value: value.entityFilters,
  181. formatDate: !0
  182. }), tagFilters = CommonViewFunction.attributeFilter.extractUrl({
  183. value: value.tagFilters,
  184. formatDate: !0
  185. }), queryArray = [];
  186. if (value.type) {
  187. var typeKeyValue = isCapsuleView ? '<div class="capsuleView"><span class="key">Type:</span><span class="value">' + _.escape(value.type) + '</span><div class="fa fa-close clear-attr" data-type="type"></div></div>' : '<span class="key">Type:</span><span class="value">' + _.escape(value.type) + "</span>";
  188. if (entityFilters) {
  189. var conditionForEntity = 1 == entityFilters.rules.length ? "" : "AND";
  190. typeKeyValue += '<span class="operator">' + conditionForEntity + '</span><div class="sub-group"><span>(</span><span class="operator">' + entityFilters.condition + "</span><span>(</span>" + objToString(entityFilters, "entityFilters").join("") + "<span>)</span><span>)</span></div>";
  191. }
  192. queryArray.push('<div class="group">' + typeKeyValue + "</div>");
  193. }
  194. if (value.tag) {
  195. var tagKeyValue = isCapsuleView ? '<div class="capsuleView"><span class="key">Classification:</span><span class="value">' + _.escape(value.tag) + '</span><div class="fa fa-close clear-attr" data-type="tag"></div></div>' : '<span class="key">Classification:</span><span class="value">' + _.escape(value.tag) + "</span>";
  196. if (tagFilters) {
  197. var conditionFortag = 1 == tagFilters.rules.length ? "" : "AND";
  198. tagKeyValue += '<span class="operator">' + conditionFortag + '</span><div class="sub-group"><span>(</span><span class="operator">' + tagFilters.condition + "</span><span>(</span>" + objToString(tagFilters, "tagFilters").join("") + "<span>)</span><span>)</span></div>";
  199. }
  200. queryArray.push('<div class="group">' + tagKeyValue + "</div>");
  201. }
  202. if (value.term) {
  203. var termKeyValue = isCapsuleView ? '<div class="capsuleView"><span class="key">Term:</span><span class="value">' + _.escape(value.term) + '</span><div class="fa fa-close clear-attr" data-type="term"></div></div>' : '<span class="key">Term:</span><span class="value">' + _.escape(value.term) + "</span>";
  204. queryArray.push('<div class="group">' + termKeyValue + "</div>");
  205. }
  206. if (value.query) {
  207. var queryKeyValue = isCapsuleView ? '<div class="capsuleView"><span class="key">Query:</span><span class="value">' + _.trim(_.escape(value.query)) + '</span><div class="fa fa-close clear-attr" data-type="query"></div></div>' : '<span class="key">Query:</span><span class="value">' + _.trim(_.escape(value.query)) + "</span>";
  208. queryArray.push('<div class="group">' + queryKeyValue + "</div>");
  209. }
  210. if (value.excludeST) {
  211. var queryExcludeST = isCapsuleView ? '<div class="capsuleView"><span class="key">Exclude sub-types:</span><span class="value">' + _.escape(value.excludeST) + '</span><div class="fa fa-close clear-attr" data-type="excludeST"></div></div>' : '<span class="key">Type:</span><span class="value">' + _.escape(value.excludeST) + "</span>";
  212. queryArray.push('<div class="group">' + queryExcludeST + "</div>");
  213. }
  214. if (value.excludeSC) {
  215. var queryExcludeSC = isCapsuleView ? '<div class="capsuleView"><span class="key">Exclude sub-classifications: </span><span class="value">' + _.escape(value.excludeSC) + '</span><div class="fa fa-close clear-attr" data-type="excludeSC"></div></div>' : '<span class="key">Type:</span><span class="value">' + _.escape(value.excludeSC) + "</span>";
  216. queryArray.push('<div class="group">' + queryExcludeSC + "</div>");
  217. }
  218. if (value.includeDE) {
  219. var queryIncludeDE = isCapsuleView ? '<div class="capsuleView"><span class="key">Show historical entities: </span><span class="value">' + _.escape(value.includeDE) + '</span><div class="fa fa-close clear-attr" data-type="includeDE"></div></div>' : '<span class="key">Type:</span><span class="value">' + _.escape(value.includeDE) + "</span>";
  220. queryArray.push('<div class="group">' + queryIncludeDE + "</div>");
  221. }
  222. return 1 == queryArray.length ? queryArray.join() : "<span>(</span>" + queryArray.join("<span>)</span><span>AND</span><span>(</span>") + "<span>)</span>";
  223. }, CommonViewFunction.generateObjectForSaveSearchApi = function(options) {
  224. var obj = {
  225. name: options.name,
  226. guid: options.guid
  227. }, value = options.value;
  228. if (value) return _.each(Enums.extractFromUrlForSearch, function(svalue, skey) {
  229. _.isObject(svalue) ? _.each(svalue, function(v, k) {
  230. var val = value[k];
  231. _.isUndefinedNull(val) || ("attributes" == k ? val = val.split(",") : _.contains([ "tagFilters", "entityFilters" ], k) ? val = CommonViewFunction.attributeFilter.generateAPIObj(val) : _.contains([ "includeDE", "excludeST", "excludeSC" ], k) && (val = !val)),
  232. _.contains([ "includeDE", "excludeST", "excludeSC" ], k) && (val = !!_.isUndefinedNull(val) || val),
  233. obj[skey] || (obj[skey] = {}), obj[skey][v] = val;
  234. }) : obj[skey] = value[skey];
  235. }), obj;
  236. }, CommonViewFunction.generateUrlFromSaveSearchObject = function(options) {
  237. var value = options.value, classificationDefCollection = options.classificationDefCollection, entityDefCollection = options.entityDefCollection, obj = {};
  238. if (value) return _.each(Enums.extractFromUrlForSearch, function(svalue, skey) {
  239. _.isObject(svalue) ? _.each(svalue, function(v, k) {
  240. var val = value[skey][v];
  241. if (!_.isUndefinedNull(val)) if ("attributes" == k) val = val.join(","); else if ("tagFilters" == k) {
  242. if (classificationDefCollection) {
  243. var classificationDef = classificationDefCollection.fullCollection.findWhere({
  244. name: value[skey].classification
  245. }), attributeDefs = [];
  246. classificationDef && (attributeDefs = Utils.getNestedSuperTypeObj({
  247. collection: classificationDefCollection,
  248. attrMerge: !0,
  249. data: classificationDef.toJSON()
  250. })), Globals[value[skey].typeName] && (attributeDefs = Globals[value[skey].typeName].attributeDefs),
  251. Globals._ALL_CLASSIFICATION_TYPES && Globals._ALL_CLASSIFICATION_TYPES.attributeDefs && (attributeDefs = attributeDefs.concat(Globals._ALL_CLASSIFICATION_TYPES.attributeDefs));
  252. }
  253. val = CommonViewFunction.attributeFilter.generateUrl({
  254. value: val,
  255. attributeDefs: attributeDefs
  256. });
  257. } else if ("entityFilters" == k) {
  258. if (entityDefCollection) {
  259. var entityDef = entityDefCollection.fullCollection.findWhere({
  260. name: value[skey].typeName
  261. }), attributeDefs = [];
  262. entityDef && (attributeDefs = Utils.getNestedSuperTypeObj({
  263. collection: entityDefCollection,
  264. attrMerge: !0,
  265. data: entityDef.toJSON()
  266. })), Globals[value[skey].typeName] && (attributeDefs = Globals[value[skey].typeName].attributeDefs),
  267. Globals._ALL_ENTITY_TYPES && Globals._ALL_ENTITY_TYPES.attributeDefs && (attributeDefs = attributeDefs.concat(Globals._ALL_ENTITY_TYPES.attributeDefs));
  268. }
  269. val = CommonViewFunction.attributeFilter.generateUrl({
  270. value: val,
  271. attributeDefs: attributeDefs
  272. });
  273. } else _.contains([ "includeDE", "excludeST", "excludeSC" ], k) && (val = !val);
  274. obj[k] = val;
  275. }) : obj[skey] = value[skey];
  276. }), obj;
  277. }, CommonViewFunction.attributeFilter = {
  278. generateUrl: function(options) {
  279. function conditionalURl(options, spliter) {
  280. return options ? _.map(options.rules || options.criterion, function(obj, key) {
  281. if (_.has(obj, "condition")) return obj.condition + "(" + conditionalURl(obj, spliter + 1) + ")";
  282. if (attributeDefs) {
  283. var attributeDef = _.findWhere(attributeDefs, {
  284. name: obj.attributeName
  285. });
  286. attributeDef && (obj.attributeValue = obj.attributeValue, obj.attributeType = attributeDef.typeName);
  287. }
  288. var type = obj.type || obj.attributeType, value = _.isString(obj.value) && _.contains([ "is_null", "not_null" ], obj.operator) && "date" === type || _.isObject(obj.value) ? "" : _.trim(obj.value || obj.attributeValue), url = [ obj.id || obj.attributeName, mapApiOperatorToUI(obj.operator), value ];
  289. return "TIME_RANGE" === obj.operator ? value.indexOf("-") > -1 ? url[2] = value.split("-").map(function(udKey) {
  290. return Date.parse(udKey.trim()).toString();
  291. }).join(",") : url[2] = Enums.queryBuilderDateRangeUIValueToAPI[_.trim(value)] || value : value.length && "date" === type && formatedDateToLong && (url[2] = Date.parse(value)),
  292. type && url.push(type), url.join("::");
  293. }).join("|" + spliter + "|") : null;
  294. }
  295. function mapApiOperatorToUI(oper) {
  296. return Enums.queryBuilderApiOperatorToUI[oper] || oper;
  297. }
  298. var attrQuery = [], attrObj = options.value, formatedDateToLong = options.formatedDateToLong, attributeDefs = options.attributeDefs, spliter = 1;
  299. return attrQuery = conditionalURl(attrObj, spliter), attrQuery.length ? attrObj.condition + "(" + attrQuery + ")" : null;
  300. },
  301. extractUrl: function(options) {
  302. var attrObj = {}, urlObj = options.value, formatDate = options.formatDate, spliter = 1, apiObj = options.apiObj, mapUiOperatorToAPI = function(oper) {
  303. return Enums.queryBuilderUIOperatorToAPI[oper] || oper;
  304. }, createObject = function(urlObj) {
  305. var finalObj = {};
  306. return finalObj.condition = /^AND\(/.test(urlObj) ? "AND" : "OR", urlObj = "AND" === finalObj.condition ? urlObj.substr(4).slice(0, -1) : urlObj.substr(3).slice(0, -1),
  307. finalObj[apiObj ? "criterion" : "rules"] = _.map(urlObj.split("|" + spliter + "|"), function(obj, key) {
  308. var isStringNested = obj.split("|" + (spliter + 1) + "|").length > 1, isCondition = /^AND\(/.test(obj) || /^OR\(/.test(obj);
  309. if (isStringNested && isCondition) return ++spliter, createObject(obj);
  310. if (isCondition) return createObject(obj);
  311. var temp = obj.split("::") || obj.split("|" + spliter + "|"), rule = {};
  312. return apiObj ? (rule = {
  313. attributeName: temp[0],
  314. operator: mapUiOperatorToAPI(temp[1]),
  315. attributeValue: _.trim(temp[2])
  316. }, rule.attributeValue = "date" === rule.type && formatDate && rule.attributeValue.length ? Utils.formatDate({
  317. date: parseInt(rule.attributeValue),
  318. zone: !1
  319. }) : rule.attributeValue) : (rule = {
  320. id: temp[0],
  321. operator: temp[1],
  322. value: _.trim(temp[2])
  323. }, temp[3] && (rule.type = temp[3]), "TIME_RANGE" === rule.operator ? temp[2].indexOf(",") > -1 ? rule.value = temp[2].split(",").map(function(udKey) {
  324. return Utils.formatDate({
  325. date: parseInt(udKey.trim()),
  326. zone: !1
  327. });
  328. }).join(" - ") : rule.value = Enums.queryBuilderDateRangeAPIValueToUI[_.trim(rule.value)] || rule.value : "date" === rule.type && formatDate && rule.value.length && (rule.value = Utils.formatDate({
  329. date: parseInt(rule.value),
  330. zone: !1
  331. }))), rule;
  332. }), finalObj;
  333. };
  334. return urlObj && urlObj.length ? attrObj = createObject(urlObj) : null;
  335. },
  336. generateAPIObj: function(url) {
  337. return url && url.length ? this.extractUrl({
  338. value: url,
  339. apiObj: !0
  340. }) : null;
  341. }
  342. }, CommonViewFunction.createEditGlossaryCategoryTerm = function(options) {
  343. if (options) var model = options.model, isTermView = options.isTermView, isGlossaryView = options.isGlossaryView, collection = options.collection;
  344. require([ "views/glossary/CreateEditCategoryTermLayoutView", "views/glossary/CreateEditGlossaryLayoutView", "modules/Modal" ], function(CreateEditCategoryTermLayoutView, CreateEditGlossaryLayoutView, Modal) {
  345. var view = null, title = null;
  346. isGlossaryView ? (view = new CreateEditGlossaryLayoutView({
  347. glossaryCollection: collection,
  348. model: model
  349. }), title = "Glossary") : (view = new CreateEditCategoryTermLayoutView({
  350. glossaryCollection: collection,
  351. modelJSON: model
  352. }), title = isTermView ? "Term" : "Category");
  353. var modal = new Modal({
  354. title: (model ? "Update " : "Create ") + title,
  355. content: view,
  356. cancelText: "Cancel",
  357. okCloses: !1,
  358. okText: model ? "Update" : "Create",
  359. allowCancel: !0
  360. }).open();
  361. modal.$el.find("input[data-id=shortDescription]").on("input keydown", function(e) {
  362. $(this).val($(this).val().replace(/\s+/g, " "));
  363. }), modal.$el.find("button.ok").attr("disabled", "true"), modal.on("ok", function() {
  364. modal.$el.find("button.ok").showButtonLoader(), CommonViewFunction.createEditGlossaryCategoryTermSubmit(_.extend({
  365. ref: view,
  366. modal: modal
  367. }, options));
  368. }), modal.on("closeModal", function() {
  369. modal.trigger("cancel"), options.onModalClose && options.onModalClose();
  370. });
  371. });
  372. }, CommonViewFunction.createEditGlossaryCategoryTermSubmit = function(options) {
  373. if (options) var ref = options.ref, modal = options.modal, model = options.model, node = options.node, isTermView = options.isTermView, isCategoryView = options.isCategoryView, collection = options.collection, isGlossaryView = options.isGlossaryView, data = ref.ui[isGlossaryView ? "glossaryForm" : "categoryTermForm"].serializeArray().reduce(function(obj, item) {
  374. return obj[item.name] = item.value.trim(), obj;
  375. }, {}), newModel = new options.collection.model(), messageType = "Glossary ";
  376. isTermView ? messageType = "Term " : isCategoryView && (messageType = "Category ");
  377. var ajaxOptions = {
  378. silent: !0,
  379. success: function(rModel, response) {
  380. var msgType = model ? "editSuccessMessage" : "addSuccessMessage";
  381. Utils.notifySuccess({
  382. content: messageType + ref.ui.name.val() + Messages.getAbbreviationMsg(!1, msgType)
  383. }), options.callback && options.callback(rModel), modal.trigger("closeModal");
  384. },
  385. cust_error: function() {
  386. modal.$el.find("button.ok").hideButtonLoader();
  387. }
  388. };
  389. if (model) isGlossaryView ? model.clone().set(data, {
  390. silent: !0
  391. }).save(null, ajaxOptions) : newModel[isTermView ? "createEditTerm" : "createEditCategory"](_.extend(ajaxOptions, {
  392. guid: model.guid,
  393. data: JSON.stringify(_.extend({}, model, data))
  394. })); else if (isGlossaryView) new collection.model().set(data).save(null, ajaxOptions); else {
  395. if (node) {
  396. data.anchor = {
  397. glossaryGuid: node.glossaryId || node.guid,
  398. displayText: node.glossaryName || node.text
  399. }, "GlossaryCategory" == node.type && (data.parentCategory = {
  400. categoryGuid: node.guid
  401. });
  402. }
  403. newModel[isTermView ? "createEditTerm" : "createEditCategory"](_.extend(ajaxOptions, {
  404. data: JSON.stringify(data)
  405. }));
  406. }
  407. }, CommonViewFunction.removeCategoryTermAssociation = function(options) {
  408. if (options) {
  409. var selectedGuid = options.selectedGuid, termGuid = options.termGuid, isCategoryView = options.isCategoryView, isTermView = options.isTermView, isEntityView = options.isEntityView, model = (options.collection,
  410. options.model), newModel = new options.collection.model(), noticeRef = null, ajaxOptions = {
  411. success: function(rModel, response) {
  412. noticeRef && noticeRef.remove(), Utils.notifySuccess({
  413. content: (isCategoryView || isEntityView ? "Term" : "Category") + " association is removed successfully"
  414. }), options.callback && options.callback();
  415. },
  416. cust_error: function() {
  417. noticeRef && noticeRef.hideButtonLoader(), options.hideLoader && options.hideLoader();
  418. }
  419. }, notifyObj = {
  420. modal: !0,
  421. okCloses: !1,
  422. okShowLoader: !0,
  423. text: options.msg,
  424. title: options.titleMessage,
  425. okText: options.buttonText,
  426. ok: function(notice) {
  427. if (noticeRef = notice, options.showLoader && options.showLoader(), isEntityView && model) {
  428. var data = [ model ];
  429. newModel.removeTermFromEntity(termGuid, _.extend(ajaxOptions, {
  430. data: JSON.stringify(data)
  431. }));
  432. } else {
  433. var data = _.extend({}, model);
  434. isTermView ? data.categories = _.reject(data.categories, function(term) {
  435. return term.categoryGuid == selectedGuid;
  436. }) : data.terms = _.reject(data.terms, function(term) {
  437. return term.termGuid == selectedGuid;
  438. }), newModel[isTermView ? "createEditTerm" : "createEditCategory"](_.extend(ajaxOptions, {
  439. guid: model.guid,
  440. data: JSON.stringify(_.extend({}, model, data))
  441. }));
  442. }
  443. },
  444. cancel: function() {}
  445. };
  446. Utils.notifyConfirm(notifyObj);
  447. }
  448. }, CommonViewFunction.addRestCsrfCustomHeader = function(xhr, settings) {
  449. if (null != settings.url) {
  450. var method = settings.type, csrfToken = CommonViewFunction.restCsrfValue;
  451. null == CommonViewFunction.restCsrfCustomHeader || CommonViewFunction.restCsrfMethodsToIgnore[method] || xhr.setRequestHeader(CommonViewFunction.restCsrfCustomHeader, csrfToken);
  452. }
  453. }, CommonViewFunction.restCsrfCustomHeader = null, CommonViewFunction.restCsrfMethodsToIgnore = null,
  454. CommonViewFunction.userDataFetch = function(options) {
  455. function getTrimmedStringArrayValue(string) {
  456. var str = string, array = [];
  457. if (str) for (var splitStr = str.split(","), i = 0; i < splitStr.length; i++) array.push(splitStr[i].trim());
  458. return array;
  459. }
  460. var csrfEnabled = !1, header = null, methods = [];
  461. options.url && $.ajax({
  462. url: options.url,
  463. success: function(response) {
  464. if (response) {
  465. if (response["atlas.rest-csrf.enabled"]) {
  466. var str = "" + response["atlas.rest-csrf.enabled"];
  467. csrfEnabled = "true" == str.toLowerCase();
  468. }
  469. if (response["atlas.rest-csrf.custom-header"] && (header = response["atlas.rest-csrf.custom-header"].trim()),
  470. response["atlas.rest-csrf.methods-to-ignore"] && (methods = getTrimmedStringArrayValue(response["atlas.rest-csrf.methods-to-ignore"])),
  471. csrfEnabled) {
  472. CommonViewFunction.restCsrfCustomHeader = header, CommonViewFunction.restCsrfMethodsToIgnore = {},
  473. CommonViewFunction.restCsrfValue = response._csrfToken || '""', methods.map(function(method) {
  474. CommonViewFunction.restCsrfMethodsToIgnore[method] = !0;
  475. });
  476. var statusCodeErrorFn = function(error) {
  477. Utils.defaultErrorHandler(null, error);
  478. };
  479. Backbone.$.ajaxSetup({
  480. statusCode: {
  481. 401: statusCodeErrorFn,
  482. 419: statusCodeErrorFn,
  483. 403: statusCodeErrorFn
  484. },
  485. beforeSend: CommonViewFunction.addRestCsrfCustomHeader
  486. });
  487. }
  488. }
  489. },
  490. complete: function(response) {
  491. options.callback && options.callback(response.responseJSON);
  492. }
  493. });
  494. }, CommonViewFunction.CheckDuplicateAndEmptyInput = function(elements, datalist, view) {
  495. for (var keyMap = new Map(), validation = !0, hasDup = [], i = 0; i < elements.length; i++) {
  496. var input = elements[i], pEl = input.nextElementSibling, classes = "form-control", val = input.value.trim();
  497. if (pEl.innerText = "", "" === val) validation = !1, pEl.innerText = "Required!"; else if (val.includes(":")) {
  498. validation = !1;
  499. var errorText = $(".errorMsg[data-id='charSupportMsg']").text();
  500. errorText && 0 === errorText.length && (pEl.innerText = "These special character '(:)' are not supported.");
  501. } else if ("INPUT" === input.tagName) {
  502. var duplicates = datalist.filter(function(c) {
  503. return c.key === val;
  504. });
  505. keyMap.has(val) || duplicates.length > 1 ? (classes = "form-control errorClass",
  506. hasDup.push("duplicate"), pEl.innerText = "Duplicate key") : keyMap.set(val, val);
  507. }
  508. validation === !1 && (classes = "form-control errorClass"), input.setAttribute("class", classes);
  509. }
  510. return {
  511. validation: validation,
  512. hasDuplicate: 0 !== hasDup.length
  513. };
  514. }, CommonViewFunction.getRandomIdAndAnchor = function() {
  515. var randomId = "collapse_" + parseInt(100 * Math.random()) + "_" + new Date().getUTCMilliseconds();
  516. return {
  517. id: randomId,
  518. anchor: "#" + randomId
  519. };
  520. }, CommonViewFunction.udKeysStringParser = function(udKeys) {
  521. var o = {};
  522. return _.each(udKeys.split(","), function(udKey) {
  523. var ud = udKey.split(":");
  524. o[ud[0]] = ud[1];
  525. }), o;
  526. }, CommonViewFunction.udKeysObjectToStringParser = function(udKeys) {
  527. var list = _.map(udKeys, function(udKey) {
  528. var t = udKey.key + ":" + udKey.value;
  529. return t;
  530. });
  531. return list.join(",");
  532. }, CommonViewFunction.fetchRootEntityAttributes = function(options) {
  533. $.ajax({
  534. url: options.url,
  535. methods: "GET",
  536. dataType: "json",
  537. cache: !0,
  538. success: function(response) {
  539. response && _.each(options.entity, function(rootEntity) {
  540. Globals[rootEntity] = $.extend(!0, {}, response, {
  541. name: rootEntity,
  542. guid: rootEntity
  543. });
  544. });
  545. },
  546. complete: function(response) {
  547. options.callback && options.callback(response);
  548. }
  549. });
  550. }, CommonViewFunction.fetchRootClassificationAttributes = function(options) {
  551. $.ajax({
  552. url: options.url,
  553. methods: "GET",
  554. dataType: "json",
  555. cache: !0,
  556. success: function(response) {
  557. response && _.each(options.classification, function(rootClassification) {
  558. Globals[rootClassification] = $.extend(!0, {}, response, {
  559. name: rootClassification,
  560. guid: rootClassification
  561. });
  562. });
  563. },
  564. complete: function(response) {
  565. options.callback && options.callback(response);
  566. }
  567. });
  568. }, CommonViewFunction;
  569. });