Built files from Bizgaze WebServer
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

autocomplete.component.js 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
  2. function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
  3. return new (P || (P = Promise))(function (resolve, reject) {
  4. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  5. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  6. function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
  7. step((generator = generator.apply(thisArg, _arguments || [])).next());
  8. });
  9. };
  10. var Unibase;
  11. (function (Unibase) {
  12. let Forms;
  13. (function (Forms) {
  14. let Controls;
  15. (function (Controls) {
  16. class AutoComplete extends Unibase.Platform.Core.BaseComponent {
  17. constructor() {
  18. super(...arguments);
  19. this.FormAutoUniqueId = null;
  20. this.loadCascading = true;
  21. this.container = null;
  22. this.DocPropertyId = 0;
  23. this.FormPropertyId = 0;
  24. this.FormPropertyName = "";
  25. this.FormId = 0;
  26. this.totalreportdatafilter = [];
  27. this.totalreportid = 0;
  28. this.mappingtextcolumn = null;
  29. this.mappingidcolumn = null;
  30. }
  31. init(formpropertyid, prop, callback) {
  32. var instance = AutoComplete.Instance();
  33. var container = $("#txtAutoComplete_" + prop.UniqueId);
  34. instance.LoadAutoComplete(container, null).then(function () {
  35. if (callback != null)
  36. callback();
  37. });
  38. var autoSettingData = JSON.parse(prop.ControlJsonText);
  39. if (autoSettingData.AppConfigId != 0) {
  40. $(container).change(function () {
  41. if ($("#txtAutoComplete_" + prop.UniqueId + " option:selected").text() == "Create New") {
  42. var autoContainer = "autocomplete_" + prop.FormPropertyId;
  43. Unibase.Platform.Forms.Managers.FormManager.Instance().getFormByAppConfiguration(autoSettingData.AppConfigId).then(function (response) {
  44. var formid = response.result.FormId;
  45. $("#txtAutoComplete_" + prop.UniqueId).text('');
  46. $("#hfAutoCompleteId_" + prop.UniqueId).val('');
  47. Unibase.Forms.Controls.AutoComplete.localInstance(autoContainer).FormPropertyName = prop.FormPropertyName;
  48. Unibase.Forms.Controls.AutoComplete.localInstance(autoContainer).container = "#txtAutoComplete_" + prop.UniqueId;
  49. Unibase.Forms.Controls.AutoComplete.localInstance(autoContainer).DocPropertyId = prop.DocPropertyId;
  50. Unibase.Forms.Controls.AutoComplete.localInstance(autoContainer).FormPropertyId = prop.FormPropertyId;
  51. Unibase.Forms.Controls.AutoComplete.localInstance(autoContainer).FormId = formid;
  52. Unibase.Forms.Controls.AutoComplete.localInstance(autoContainer).FormAutoUniqueId = "autocomplete_" + prop.UniqueId + "_" + response.result.FormId;
  53. var successCallBack = {
  54. CallBack: function (id) {
  55. let AppConfigType = Unibase.Platform.Forms.Components.FormViewer.instance.AppConfigType;
  56. Unibase.Platform.Forms.Components.FormViewer.instance.AppConfigType = 0;
  57. Unibase.Platform.Forms.Managers.FormManager.Instance().getAutocompleteSelectedData(Unibase.Forms.Controls.AutoComplete.localInstance(autoContainer).DocPropertyId, id, Unibase.Forms.Controls.AutoComplete.localInstance(autoContainer).FormPropertyId, 0).then(function (response) {
  58. var selectedOptions = new Option(response.result[0].DisplayText, response.result[0].Value, true);
  59. $(Unibase.Forms.Controls.AutoComplete.localInstance(autoContainer).container).append(selectedOptions).trigger('change');
  60. Unibase.Platform.Forms.Components.FormViewer.instance.AppConfigType = AppConfigType;
  61. });
  62. },
  63. Parameters: null,
  64. };
  65. var formviewerObj = {
  66. FormId: formid,
  67. AppConfigurationId: autoSettingData.AppConfigId,
  68. Pk_Value: 0,
  69. PortletWidgetId: 0,
  70. OnSuccess: successCallBack,
  71. OnFail: null,
  72. OnLoad: null,
  73. FormContainer: null,
  74. };
  75. Unibase.Platform.Forms.Components.FormViewer.instance.init(formviewerObj);
  76. });
  77. }
  78. else {
  79. var IdFormPropertyid = $("#hfAutoCompleteId_" + prop.UniqueId).data("textformpropertyid");
  80. $("#hdn_" + IdFormPropertyid).val($("#txtAutoComplete_" + prop.UniqueId + " option:selected").text());
  81. }
  82. });
  83. }
  84. }
  85. loadControl(containerid, prop) {
  86. var instance = this;
  87. var jsfiles = ["platform/controls/cascadingautocomplete/cascadingautocomplete.component.js", "platform/controls/cascadingautocomplete/cascadingautocomplete.settings.js"];
  88. var Isrequired = prop.IsRequired != true ? 'hidden' : '';
  89. var required = prop.IsRequired != true ? '' : 'required';
  90. var CurrentStageId = $("#hf_" + $("#hfLayout_InstalledPageId").val() + "_StageId").val();
  91. if (prop.StagesForRequired != null && prop.StagesForRequired != "") {
  92. var StagesForRequired = prop.StagesForRequired.split('|');
  93. Isrequired = StagesForRequired.find(x => x == CurrentStageId) ? '' : 'hidden';
  94. required = StagesForRequired.find(x => x == CurrentStageId) ? 'required' : '';
  95. }
  96. var IsTagSelect = false;
  97. var text;
  98. if (prop.ControlJsonText != "" && prop.ControlJsonText != null && prop.ControlJsonText != undefined) {
  99. var text = JSON.parse(prop.ControlJsonText);
  100. if (text["IsTagSelect"] == true) {
  101. IsTagSelect = true;
  102. }
  103. }
  104. var divclass = text.ShowTotalReportData == true ? 'col-sm-11 col-11' : 'col-sm-12';
  105. const { helpTooltipHtml, helpTextHtml } = Unibase.Platform.Forms.Components.FormViewer.Instance().getControlHelpHtml(prop);
  106. var html = `<div id="div_${prop.DocPropertyName}" style=""><label for="lbl" id="lbl_${prop.DocPropertyName}">${helpTooltipHtml}<span class="label-name">${prop.LabelName}</span><span class="text-danger hide ${Isrequired}" id="spnIsRequired_${prop.FormPropertyId}"> *</span></label><div class="input-group ">` +
  107. '<div class="' + divclass + '" style="margin:0px;padding:0px;"><select id="txtAutoComplete_' + prop.UniqueId + '" class="txtAutoComplete_' + prop.DocPropertyName + ' form-control type-control text-control select_address ' + required + ' " data-isdefault="' + prop.IsDefault + '" style="width:100%;" placeholder = "' + prop.Placeholder + '" data-placeholder="' + prop.Placeholder + '" data-label="' + prop.LabelName + '" data-istagselect="' + IsTagSelect + '" data-propertyid="' + prop.DocPropertyId + '" data-propertyname="' + prop.DocPropertyName + '" data-formpropertyid="' + prop.FormPropertyId + '" data-formid="' + text.FormId + '" value="0" data-textformpropertyid="' + text.TextFormPropertyId + '" data-showtotalreportdata="' + text.ShowTotalReportData + '" ></select>' +
  108. '<input type="hidden" id="hfAutoCompleteId_' + prop.UniqueId + '" value="0" class="hfAutoCompleteId_' + prop.DocPropertyName + ' form-control value-control" data-autotextid="txtAutoComplete_' + prop.UniqueId + '" data-required="' + prop.IsRequired + '" data- data-regularexp="" data-validatemsg="" />' + helpTextHtml + '</div>';
  109. if (text.ShowTotalReportData == true) {
  110. html += '<div class=" col-sm-1 col-1 input-group-append" style=";margin:0px;padding:0px;">' +
  111. '<a class="CheckOutButton align-items-center btn btn-primary btn-xs d-flex h-100 justify-content-center" href="javascript:;" id="hf_totalreportdata_' + prop.UniqueId + '" onclick="javascript:return Unibase.Forms.Controls.AutoComplete.Instance().loadTotalReportData(' + text.TotalDataReportId + ',' + "'" + text.MappingTextColumn + "'" + ',' + "'" + text.MappingIdColumn + "','" + "txtAutoComplete_" + prop.UniqueId + "'" + ',' + prop.FormPropertyId + ')" > <i class="la la-retweet font-18 line-height-12"></i></a></div>';
  112. }
  113. html += '</div><input type="hidden" id="hfId_' + prop.DocPropertyName + '" value=""><label for="Validation" id="lblValidation_' + prop.DocPropertyName + '"></label></div>';
  114. $("#" + containerid).html(html);
  115. $("#" + containerid).find("#txtAutoComplete_" + prop.UniqueId).on('change', function () {
  116. instance.fileCacheHelper.loadJsFiles(jsfiles, function () {
  117. var controlJson = prop.ControlJsonText;
  118. if (instance.loadCascading) {
  119. Unibase.Forms.Controls.CascadingAutocomplete.Instance().ChildCascadingData(false, prop.FormPropertyId, Number($("#txtAutoComplete_" + prop.UniqueId).val()), 0, '');
  120. }
  121. instance.loadCascading = true;
  122. });
  123. });
  124. }
  125. loadTotalReportData(ReportId, TextColumn, IdColumn, Element, FormPropertyId) {
  126. Unibase.Platform.Analytics.Viewers.TableViewer.Instance().IsSelectable = true;
  127. Unibase.Platform.Analytics.Viewers.TableViewer.Instance().TextColumn = TextColumn;
  128. Unibase.Platform.Analytics.Viewers.TableViewer.Instance().IdColumn = IdColumn;
  129. Unibase.Platform.Analytics.Viewers.TableViewer.Instance().AutoCompleteElement = Element;
  130. var localinstance = Unibase.Platform.Analytics.Components.ReportViewer.Instance();
  131. let reportViewerInstance = Unibase.Platform.Helpers.NavigationHelper.reportViewerInstance;
  132. var isInstance = false;
  133. const containerid = "reportviewer_" + ReportId;
  134. if (reportViewerInstance.length > 0)
  135. isInstance = reportViewerInstance.find(rv => rv.childcontainerid == "reportviewer_" + ReportId) ? true : false;
  136. if (!isInstance) {
  137. reportViewerInstance.push({
  138. instance: localinstance,
  139. childcontainerid: containerid,
  140. parentcontainerid: null
  141. });
  142. }
  143. else {
  144. var tempinstance = reportViewerInstance.find(rv => rv.childcontainerid == "reportviewer_" + ReportId);
  145. localinstance = tempinstance.instance;
  146. }
  147. var autoContainer = "autocomplete_" + FormPropertyId;
  148. localinstance.dynamicFilters = Unibase.Forms.Controls.AutoComplete.localInstance(autoContainer).totalreportdatafilter;
  149. if (ReportId != undefined)
  150. Unibase.Platform.Helpers.NavigationHelper.Instance().popup(ReportId, containerid, localinstance, function () {
  151. $(`#ViewerFooter_${containerid}`).removeClass('d-none').find(`#div_pagination_${containerid}`).addClass('d-none');
  152. $(`#ReportClose_${containerid}`).removeClass('hidden pull-right');
  153. $(`#reportCloseBtn_${containerid}`).removeClass('d-none');
  154. }, Unibase.Platform.Helpers.Size.DockLeft);
  155. }
  156. reportOnClick(TextColumn, IdColumn, element) {
  157. var selectedOptions = new Option(TextColumn, IdColumn, true);
  158. $("#" + element).append(selectedOptions);
  159. jQuery("#" + element).val(IdColumn).trigger('change');
  160. Unibase.Platform.Helpers.NavigationHelper.Instance().closePopUp();
  161. Unibase.Platform.Analytics.Viewers.TableViewer.Instance().IsSelectable = false;
  162. }
  163. loadControlSettings() {
  164. return ``;
  165. }
  166. LoadAutoComplete(Container, Parameters) {
  167. return __awaiter(this, void 0, void 0, function* () {
  168. var DocPropertyId = Container.data('propertyid');
  169. var DocPropertyName = Container.data('propertyname');
  170. var FormPropertyId = Container.data('formpropertyid');
  171. var FormId = Container.data('formid');
  172. var ColumnName = "0";
  173. var Value = "0";
  174. var reportfilter = [];
  175. if (Parameters != null && Parameters != "") {
  176. ColumnName = Parameters.map(function (item) { return item.ColumnName; }).toString();
  177. Value = Parameters.map(function (item) { return item.Value + "|"; }).toString();
  178. }
  179. var uniqueid = $(Container).attr('id').split('_')[1];
  180. var textCol = Container;
  181. var idCol = $("#hfAutoCompleteId_" + uniqueid);
  182. var istagselect = false;
  183. if ($("#txtAutoComplete_" + uniqueid).data("istagselect") == true) {
  184. istagselect = true;
  185. }
  186. var showtotalreportdata = $(Container).data("showtotalreportdata");
  187. if (showtotalreportdata) {
  188. if (Parameters != null && Parameters != "") {
  189. Parameters.map(function (item) {
  190. var reportfilterobj = { ParameterName: item.ColumnName, ParameterValue: item.Value.toString(), ExpOp: Unibase.Platform.Core.Enums.ExpressionOperator.Equals };
  191. reportfilter.push(reportfilterobj);
  192. });
  193. }
  194. var autoContainer = "autocomplete_" + FormPropertyId;
  195. Unibase.Forms.Controls.AutoComplete.localInstance(autoContainer).totalreportdatafilter = reportfilter;
  196. }
  197. var bindedData = undefined;
  198. var url = _appsettings.server_url() + '/apis/v4/unibase/platform/forms/autocomplete/docpropertyid/' + DocPropertyId + '/columnname/' + ColumnName + '/value/' + Value + '/formpropertyid/' + FormPropertyId + '/formid/' + FormId + '/bindeddata/' + bindedData;
  199. AutoCompleteHelper.getHelper().Create(textCol, idCol, url, function (response) {
  200. var data = response;
  201. }, istagselect);
  202. $(textCol).on('select2:open', function () {
  203. var id = $(textCol).attr("id");
  204. let searchField = $('#select2-' + id + '-results').parents('.select2-container').find('.select2-search__field');
  205. if (istagselect == true && searchField.val() == "") {
  206. searchField.val($("#" + id + " option:selected").text());
  207. }
  208. });
  209. $(textCol).on('select2:select', function () {
  210. if (istagselect == true) {
  211. var id = $(textCol).attr("id");
  212. var isFreeText = $("#" + id + " option:selected").attr('data-select2-tag');
  213. if (isFreeText == "true") {
  214. $(textCol).attr('data-addldata', "");
  215. }
  216. }
  217. });
  218. var autocompleteid1 = $(".txtAutoComplete_" + DocPropertyName).attr('id');
  219. });
  220. }
  221. loadPropertySettings(propertysettings, formpropertyid) {
  222. return ``;
  223. }
  224. bindEditFormDetails(formpropertyid, propval, DocPropertyName) {
  225. if (propval != "null") {
  226. var instance = this;
  227. var autojson = JSON.parse(propval);
  228. var IdValue = autojson.AutoCompleteIdColumn;
  229. var TextValue = autojson.AutoCompleteTextColumn;
  230. var selectedOptions = new Option(TextValue, IdValue, true);
  231. if (IdValue != "0") {
  232. $("#txtAutoComplete_" + formpropertyid).append(selectedOptions);
  233. instance.loadCascading = false;
  234. jQuery("#txtAutoComplete_" + formpropertyid).val(IdValue).trigger("change");
  235. }
  236. }
  237. }
  238. GetOrAddCurrentAutoCompleteInstance(ContainerId) {
  239. if (ContainerId != undefined && ContainerId != null && ContainerId != "") {
  240. let isInstance = false;
  241. let formControlInstance = Unibase.Platform.Forms.Components.FormViewer.formControlInstances;
  242. if (formControlInstance.length > 0)
  243. isInstance = formControlInstance.find(fv => fv.containerid == ContainerId) ? true : false;
  244. var viewerInstance = new Unibase.Forms.Controls.AutoComplete();
  245. var currentinstance = {
  246. instance: viewerInstance,
  247. containerid: ContainerId,
  248. };
  249. if (isInstance == true) {
  250. viewerInstance = formControlInstance.find(fv => fv.containerid == ContainerId).instance;
  251. }
  252. if (!isInstance)
  253. formControlInstance.push(currentinstance);
  254. return viewerInstance;
  255. }
  256. }
  257. static localInstance(ContainerId) {
  258. var formobj = new Unibase.Forms.Controls.AutoComplete();
  259. this.instance = formobj.GetOrAddCurrentAutoCompleteInstance(ContainerId);
  260. return this.instance;
  261. }
  262. static Instance() {
  263. if (this.instance === undefined) {
  264. this.instance = new AutoComplete();
  265. }
  266. return this.instance;
  267. }
  268. }
  269. Controls.AutoComplete = AutoComplete;
  270. })(Controls = Forms.Controls || (Forms.Controls = {}));
  271. })(Forms = Unibase.Forms || (Unibase.Forms = {}));
  272. })(Unibase || (Unibase = {}));