Built files from Bizgaze WebServer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

rulebuilder.rule.js 73KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950
  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 Platform;
  13. (function (Platform) {
  14. let Automation;
  15. (function (Automation) {
  16. let Components;
  17. (function (Components) {
  18. class Rule extends Platform.Core.BaseComponent {
  19. constructor() {
  20. super(...arguments);
  21. this.RuleInstalledAppId = 0;
  22. this.CurrentEventIndex = 0;
  23. }
  24. jsFiles() {
  25. var jsfiles = ["platform/automation/managers/rulemanager.js",
  26. "platform/datasources/managers/doctypemanager.js",
  27. "platform/analytics/managers/reportmanager.js",
  28. "platform/forms/managers/formmanager.js",
  29. "platform/automation/enums/eventtype.js",
  30. "platform/automation/enums/ruletype.js",
  31. "platform/automation/enums/expop.js",
  32. "platform/automation/enums/automationmode.js",
  33. "platform/automation/enums/executeactionstatus.js",
  34. "platform/automation/components/conditions.js",
  35. "platform/automation/requests/rule.js",
  36. "platform/automation/requests/ruleevent.js",
  37. "platform/automation/requests/ruleaction.js",
  38. "platform/automation/requests/rulecondition.js",
  39. "platform/automation/components/rulebuilder/rulebuilder.condition.js",
  40. "libs/querybuilder/query-builder.min.js",
  41. "libs/querybuilder/query-builder.standalone.min.js",
  42. "libs/querybuilder/query-builder.standalone.js",
  43. "libs/querybuilder/sql-parser.min.js",
  44. "platform/datasources/components/datalistbuilder/querybuilder.js",
  45. "platform/forms/components/formviewer/formviewer.js",
  46. "libs/parsley/parsley.min.js", "platform/automation/components/rulebuilder/rulebuilder.js"
  47. ];
  48. return jsfiles;
  49. }
  50. cssFiles() {
  51. var cssfiles = ["libs/querybuilder/query-builder.default.css"];
  52. return cssfiles;
  53. }
  54. html(id, containerid) {
  55. let html = `<form id="frmUnibase_Rule" data-validate="parsley" data-isdynamic="false">
  56. <div class="card bg-light">
  57. <div class="b-b bg-white card-header header">
  58. <strong class="text-dark title" id="Form_Rule">Create Rule</strong>
  59. <span class="pull-right" id="ModeType">
  60. <a href="javascript:;" id="link_AdvancedMode" class="pull-right">Advanced Mode</a>
  61. <a href="javascript:;" id="link_NormalMode" class="pull-right hidden">Normal Mode</a>
  62. </span>
  63. </div>
  64. <div class="card-body scrollable" style="overflow-y: scroll;">
  65. <div id="Validate_Rule" class="clear"></div>
  66. <div class="row">
  67. <div class="col-sm-3" id="InstalledAppsList">
  68. <div id="Search" class="mb-15 mt-1">
  69. <input type="text" id="txt_Search" onkeyup="Unibase.Platform.Automation.Components.Rule.Instance().SearchBlocks();" class="form-control value-control floating-label-control" placeholder="Search App">
  70. </div>
  71. <div id="txt_noresults" class="hidden" style="text-align:center;">No Results Found</div>
  72. </div>
  73. <div class="col-sm-9 hidden" id="RuleSection">
  74. <div class="bg-white card" id="RuleDetails">
  75. <div class="card-body">
  76. <div class="row">
  77. <div class="col-sm-12">
  78. <div class="floating-label-form-group">
  79. <label for="lbl_Rule" id="lbl_Rule">Rule Name<span class="text-danger">*</span></label>
  80. <input type="text" id="txt_Rule" class="form-control required value-control floating-label-control" data-isdynamic="false" placeholder="Rule Name*" data-placeholder="Enter Rule Name" data-label="Rule Name*" />
  81. <input type="hidden" id="hf_Rule" />
  82. <label for="Validation" id="lblValidation_Rule"></label>
  83. </div>
  84. </div>
  85. <div class="col-sm-12">
  86. Rule Provider<span class="text-danger">*</span>
  87. <select id="ddl_RuleProvider" class="required form-control value-control" data-isdynamic="true">
  88. </select>
  89. <input type="hidden" id="hf_RuleProvider" value="" />
  90. </div>
  91. </div>
  92. </div>
  93. </div>
  94. <div class="bg-white card hidden" id="EventModeEvent">
  95. <div class="card-header">When</div>
  96. <div class="card-body">
  97. <div class="row" id="AddEvents">
  98. <div class="card col-sm-4">
  99. <div class="card-body">Order Created</div>
  100. </div>
  101. </div>
  102. <div class="row pull-right">
  103. <button type="button" id="btn_EventNames" class="btn btn-primary" onclick="Unibase.Platform.Automation.Components.Rule.Instance().ToggleEventNames();">Show More</button>
  104. </div>
  105. </div>
  106. </div>
  107. <div class="bg-white card hidden" id="NormalModeEvent">
  108. <div class="card-header">
  109. When
  110. <span class="pull-right" id="AddEvent">
  111. <a id="" title="Create" onclick="Unibase.Platform.Automation.Components.Rule.Instance().AddEvent();">
  112. <i class="fa fa-plus"></i>
  113. </a>
  114. </span>
  115. </div>
  116. <div class="card-body" id="MultipleEvents">
  117. <div class="ml-5" id="AddNewEvents">
  118. <!--- <div class="row eventrow" id="row_0">
  119. <lable class="hidden" id="EventGroupId_0">0</lable>
  120. <lable class="hidden" id="RuleActionId_0">0</lable>
  121. <div class="col-sm-2 mt-10"><label>When </label></div>
  122. <div class="col-sm-3 mt-10" id="ELable_0" onclick="Unibase.Platform.Automation.Components.Rule.Instance().ToggleEventColumnLable(0);">
  123. <u><b style="font-weight: bold;" id="EventColumnLable_0"></b></u>
  124. </div>
  125. <div class="col-sm-3 hidden" id="EAutocomplete_0">
  126. <div id="div_EventColumns" class="floating-label-form-group" style="border-bottom:0;"><input type="hidden" class="event_name_0">
  127. <select id="select2_EventColumns_0" class="select2_0_EventColumns required value-control form-control text-control" multiple="multiple" style="width:100%;" onchange="Unibase.Platform.Automation.Components.Rule.Instance().OnChangeEventColumn(0);"></select>
  128. <input type="hidden" id="hfSelect2Id_EventColumns_0" value="0" class="form-control text-control" data-isdynamic="true" />
  129. <input type="hidden" id="hfId_EventColumns" value=""><label for="Validation" id="lblValidation_EventColumns"></label>
  130. </div>
  131. </div>
  132. <div class="col-sm-1 mt-10"><label id="Event_0"></label></div>
  133. <div class="col-sm-1 mt-10"><label>Then </label></div>
  134. <div class="col-sm-3 mt-10" id="ALable_0" onclick="Unibase.Platform.Automation.Components.Rule.Instance().ToggleActions(0);"><u><b style="font-weight: bold;" class="" id="ActionLable_0"></b></u></div>
  135. <div class="col-sm-3 hidden" id="AAutocomplete_0">
  136. <div class="floating-label-form-group floating-label-form-group-with-value focus">
  137. <select id="Action_Autocomplete_0" onchange="Unibase.Platform.Automation.Components.Rule.Instance().OnChangeActions(0);" style="-webkit-appearance: none;" class="required form-control value-control" data-isdynamic="true">
  138. </select>
  139. <input type="hidden" value="0" id="hf_Action_0" />
  140. </div>
  141. </div>
  142. <div class="col-sm-1 mt-10"><a href="javascript:;" id="link_Configure"><i class="fa fa-cog"></i></a></div>
  143. <div class="col-sm-1 mt-10"><a id="delete_0" title="Delete" style="cursor:pointer" onclick="Unibase.Platform.Automation.Components.Rule.Instance().DeleteEventGroupRow(0,0);"><i class="fa fa-close"></i></a></div>
  144. </div>---->
  145. </div>
  146. </div>
  147. </div>
  148. <div class="bg-white card" id="btn_Conditions">
  149. <button type="button" class="btn btn-primary" onclick="Unibase.Platform.Automation.Components.Rule.Instance().ToggleGlobalConditions();">Conditions</button>
  150. </div>
  151. <div class="bg-white card hidden" id="ConditionDetailsDiv">
  152. <div class="card-header">Global Condition Details</div>
  153. <div class="card-body">
  154. <div class="ConditionDetails">
  155. </div>
  156. </div>
  157. </div>
  158. </div>
  159. </div>
  160. </div>
  161. <div class="bg-white card-footer footer" id="CreateRuleFooter">
  162. <a href="javascript:;" id="btnCloseRule" class="btn btn-light btn-sm mr-auto "> Close</a>
  163. <a href="javascript:;" id="btnSaveRule" class="btn btn-primary btn-sm"> Save</a>
  164. </div>
  165. </div>
  166. </form>`;
  167. return html;
  168. }
  169. load(id, containerid, callback) {
  170. Unibase.Platform.Automation.Components.Rule.AutomationMode = Unibase.Platform.Automation.Enums.AutomationMode.NormalMode;
  171. Unibase.Platform.Automation.Components.Rule.Instance().GetActions();
  172. Unibase.Platform.Automation.Components.Rule.RuleId = id;
  173. Unibase.Platform.Automation.Components.Rule.Instance().default_event();
  174. $("#btnCloseRule").click(function () {
  175. $('#' + containerid).modal('hide');
  176. $('#' + containerid).remove();
  177. Unibase.Platform.Automation.Components.Rule.keysindex = 0;
  178. Unibase.Platform.Automation.Components.Rule.keyscount = 0;
  179. Unibase.Platform.Automation.Components.Rule.keysflag = 0;
  180. Unibase.Platform.Automation.Components.Rule.RuleId = 0;
  181. Unibase.Platform.Automation.Components.Rule.ActionsArray = [];
  182. Unibase.Platform.Automation.Components.Rule.EventColumnData = [];
  183. Unibase.Platform.Automation.Components.Rule.RuleActionsData = [];
  184. Unibase.Platform.Automation.Components.RuleCondition.ruleConditionArray = [];
  185. });
  186. $("#btnSaveRule").click(function () {
  187. let appcontrolid = "frmUnibase_Rule";
  188. let result = Unibase.Platform.Forms.Components.FormViewer.Instance().requiredFieldValidation(appcontrolid);
  189. if (result == false) {
  190. MessageHelper.Instance().showError("Mandatory fields are missing", "Validate_Rule");
  191. $(".eventrow").each(function () {
  192. let id = $(this).find(".eventrow");
  193. let index = (id.prevObject[0].id).split('_');
  194. index = index[1];
  195. let eventcolumns = $("#select2_EventColumns_" + index + "").val();
  196. if (eventcolumns.length == 0) {
  197. $("#EventColumnLable_" + index + "").addClass('form-group-required');
  198. }
  199. });
  200. return false;
  201. }
  202. else {
  203. Unibase.Platform.Automation.Components.Rule.Instance().SaveRule(id, containerid);
  204. }
  205. });
  206. $("#link_AdvancedMode").click(function () {
  207. $("#link_NormalMode").removeClass("hidden");
  208. $("#link_AdvancedMode").addClass("hidden");
  209. $('#' + containerid).modal('hide');
  210. $('#' + containerid).remove();
  211. Unibase.Platform.Automation.Components.Rule.Instance().AdvancedMode(id, containerid);
  212. });
  213. $("#link_NormalMode").click(function () {
  214. $("#link_NormalMode").addClass("hidden");
  215. $("#link_AdvancedMode").removeClass("hidden");
  216. });
  217. $("#InstalledAppsList").height($(window).outerHeight() - 90).css("overflow", "hidden auto");
  218. $("#Action_Autocomplete").change(function () {
  219. $("#ALable").removeClass('hidden');
  220. $("#AAutocomplete").addClass('hidden');
  221. $("#ActionLable").text($('#Action_Autocomplete option:selected').text());
  222. });
  223. let rule = Unibase.Platform.Automation.Components.Rule.Instance();
  224. $("#ddl_RuleProvider").change(function () {
  225. $("#NormalModeEvent").removeClass("hidden");
  226. $('#AddNewEvents').html('');
  227. Unibase.Platform.Automation.Components.Rule.EventColumnData = [];
  228. Unibase.Platform.Automation.Components.Rule.Instance().default_event();
  229. rule.loadEventColomns();
  230. rule.loadActions(0);
  231. rule.loadQueryBuilder(Number($("#ddl_RuleProvider option:selected").val()), null);
  232. });
  233. rule.LoadInstalledApps();
  234. rule.loadActions(0);
  235. if (id != "") {
  236. Unibase.Platform.Automation.Components.Rule.Instance().EditRule(id, containerid);
  237. }
  238. }
  239. loadForm(FormId, Pk_Value, AppConfigurationId, Callback, ElementId) {
  240. Rule.Instance().init(Pk_Value, null);
  241. Unibase.Platform.Apps.Managers.AppManager.Instance().getAppConfiguration(AppConfigurationId).then(function (response) {
  242. Unibase.Platform.Automation.Components.Rule.installedappid = response.result.InstalledAppId;
  243. });
  244. }
  245. loadNotificationRule(iscreate) {
  246. var Pk_Value = 0;
  247. if (!iscreate) {
  248. Pk_Value = Unibase.Themes.Providers.DetailHelper.recordId;
  249. }
  250. this.navigationHelper.popup(Pk_Value, '', Unibase.Platform.Automation.Components.Rule.Instance(), null, Platform.Helpers.Size.DockLeft);
  251. }
  252. init(id, callback) {
  253. this.render(id, callback);
  254. }
  255. render(id, callback) {
  256. this.navigationHelper.popup(id, '', Unibase.Platform.Automation.Components.Rule.Instance(), null, Platform.Helpers.Size.DockLeft);
  257. }
  258. GetActions() {
  259. Unibase.Platform.Automation.Managers.RuleManager.Instance().getActions().then(function (response) {
  260. for (var i = 0; i <= response.length - 1; i++) {
  261. Unibase.Platform.Automation.Components.Rule.ActionsArray.push(response[i]);
  262. }
  263. });
  264. }
  265. OnChangeEventColumn(index) {
  266. let eventcolumnscount = new Array();
  267. eventcolumnscount = $("#select2_EventColumns_" + index + "").val();
  268. if (eventcolumnscount.length > 0) {
  269. $("#ELable_" + index + "").removeClass('hidden');
  270. $("#EAutocomplete_" + index + "").addClass('hidden');
  271. $("#EventColumnLable_" + index + "").text(Unibase.Platform.Automation.Components.Rule.Instance().GetEventColumns(index));
  272. $('.event_name_' + index + '').val('').val(Unibase.Platform.Automation.Components.Rule.Instance().GetEventColumns(index));
  273. }
  274. }
  275. OnChangeActions(index) {
  276. $("#ALable_" + index + "").removeClass('hidden');
  277. $("#AAutocomplete_" + index + "").addClass('hidden');
  278. $("#ActionLable_" + index + "").text($('#Action_Autocomplete_' + index + ' option:selected').text());
  279. $("#ActionLable_" + index + "").removeClass('form-group-required');
  280. var _fileCacheHelper = Platform.Helpers.FileCacheHelper.Instance();
  281. let id = Number($("#RuleActionId_" + index + "").text());
  282. let actionid = Number($('#Action_Autocomplete_' + index + ' option:selected').val());
  283. let ruleproviderid = Number($("#ddl_RuleProvider option:selected").val());
  284. var instance = this;
  285. if (!$("#ConditionDetailsDiv").hasClass("hidden")) {
  286. Unibase.Platform.Automation.Components.Rule.Instance().SaveQueryString();
  287. }
  288. else {
  289. let queryelmnt = $("#builder");
  290. queryelmnt.queryBuilder('destroy');
  291. $("#QueryBuilder").remove();
  292. }
  293. Unibase.Platform.Automation.Managers.RuleManager.Instance().getAction(actionid).then(function (response) {
  294. if (response != null) {
  295. _fileCacheHelper.loadJsFile(response.JsUrl, function () {
  296. var namespace = eval(response.JsVariableName);
  297. var action = new namespace();
  298. action.RuleProviderId = ruleproviderid;
  299. action.RowIndex = index;
  300. action.ActionId = response.ActionId;
  301. action.RuleActionData = Unibase.Platform.Automation.Components.Rule.RuleActionsData.filter(X => X.RowIndex == index);
  302. action.AutomationMode = Unibase.Platform.Automation.Components.Rule.AutomationMode;
  303. action.IsAutomationMode = true;
  304. action.ParentActionId = 0;
  305. instance.navigationHelper.popup(id, '', action, function () {
  306. }, Platform.Helpers.Size.Auto);
  307. });
  308. }
  309. });
  310. }
  311. default_event() {
  312. var html = `<div class="row eventrow" id="row_0">
  313. <lable class="hidden" id="EventGroupId_0">0</lable>
  314. <lable class="hidden" id="RuleActionId_0">0</lable>
  315. <div class="col-sm-2 mt-10"><label>When </label></div>
  316. <div class="col-sm-3 mt-10" id="ELable_0" onclick="Unibase.Platform.Automation.Components.Rule.Instance().ToggleEventColumnLable(0);">
  317. <u><b style="font-weight: bold;" id="EventColumnLable_0"></b></u>
  318. </div>
  319. <div class="col-sm-3 hidden" id="EAutocomplete_0">
  320. <div id="div_EventColumns" class="floating-label-form-group" style="border-bottom:0;"><input type="hidden" class="event_name_0">
  321. <select id="select2_EventColumns_0" class="select2_0_EventColumns required value-control form-control text-control" multiple="multiple" style="width:100%;" onchange="Unibase.Platform.Automation.Components.Rule.Instance().OnChangeEventColumn(0);"></select>
  322. <input type="hidden" id="hfSelect2Id_EventColumns_0" value="0" class="form-control text-control" data-isdynamic="true" />
  323. <input type="hidden" id="hfId_EventColumns" value=""><label for="Validation" id="lblValidation_EventColumns"></label>
  324. </div>
  325. </div>
  326. <div class="col-sm-1 mt-10"><label id="Event_0"></label></div>
  327. <div class="col-sm-1 mt-10"><label>Then </label></div>
  328. <div class="col-sm-3 mt-10" id="ALable_0" onclick="Unibase.Platform.Automation.Components.Rule.Instance().ToggleActions(0);"><u><b style="font-weight: bold;" class="" id="ActionLable_0"></b></u></div>
  329. <div class="col-sm-3 hidden" id="AAutocomplete_0">
  330. <div class="floating-label-form-group floating-label-form-group-with-value focus">
  331. <select id="Action_Autocomplete_0" onchange="Unibase.Platform.Automation.Components.Rule.Instance().OnChangeActions(0);" style="-webkit-appearance: none;" class="required form-control value-control" data-isdynamic="true">
  332. </select>
  333. <input type="hidden" value="0" id="hf_Action_0" />
  334. </div>
  335. </div>
  336. <div class="col-sm-1 mt-10"><a href="javascript:;" id="link_Configure"><i class="fa fa-cog"></i></a></div>
  337. <div class="col-sm-1 mt-10"><a id="delete_0" title="Delete" style="cursor:pointer" onclick="Unibase.Platform.Automation.Components.Rule.Instance().DeleteEventGroupRow(0,0);"><i class="fa fa-close"></i></a></div>
  338. </div>`;
  339. $('#AddNewEvents').append(html);
  340. }
  341. ToggleEventNames() {
  342. if ($("#btn_EventNames").text() == "Show More") {
  343. $("[id='EventCard']").show();
  344. $("#btn_EventNames").text("Show Less");
  345. }
  346. else {
  347. $("[id='EventCard']").hide();
  348. $("#btn_EventNames").text("Show More");
  349. }
  350. }
  351. ToggleGlobalConditions() {
  352. $("#ConditionDetailsDiv").toggle(function () {
  353. $("#btn_Conditions").addClass("hidden");
  354. $("#ConditionDetailsDiv").removeClass("hidden");
  355. Unibase.Platform.Automation.Components.Rule.Instance().loadQueryBuilder(Number($("#ddl_RuleProvider option:selected").val()), null);
  356. });
  357. }
  358. loadEventColomns() {
  359. return __awaiter(this, void 0, void 0, function* () {
  360. var instance = this;
  361. let ruleproviderid = Number($("#ddl_RuleProvider option:selected").val());
  362. if (ruleproviderid != 0) {
  363. return yield Unibase.Platform.Automation.Managers.RuleManager.Instance().getRuleProvider(ruleproviderid).then(function (response) {
  364. Unibase.Platform.Automation.Components.Rule.EventColumnData.push({ id: response.DoctypeName + " Created", text: response.DoctypeName + " Created" });
  365. Unibase.Platform.Automation.Components.Rule.EventColumnData.push({ id: response.DoctypeName + " Deleted", text: response.DoctypeName + " Deleted" });
  366. return Unibase.Platform.DataSources.Managers.DocTypeManager.Instance().getDocProperties(response.DoctypeId).then(function (response) {
  367. let result = response.result;
  368. for (let i = 0; i < result.length; i++) {
  369. var EventColumn = result[i];
  370. Unibase.Platform.Automation.Components.Rule.EventColumnData.push({ id: result[i].PropColumnName + " Changed", text: result[i].PropColumnName + " Changed" });
  371. }
  372. Unibase.Platform.Automation.Components.Rule.Instance().BindEventColumns(0);
  373. });
  374. });
  375. }
  376. });
  377. }
  378. BindEventColumns(index) {
  379. return __awaiter(this, void 0, void 0, function* () {
  380. $("#EventColumnLable_" + index + "").text(Unibase.Platform.Automation.Components.Rule.EventColumnData[0].id);
  381. $('.event_name_' + index + '').val('').val(Unibase.Platform.Automation.Components.Rule.EventColumnData[0].id);
  382. $("#select2_EventColumns_" + index + "").select2({
  383. placeholder: 'Select',
  384. data: Unibase.Platform.Automation.Components.Rule.EventColumnData,
  385. });
  386. });
  387. }
  388. loadActions(index) {
  389. return __awaiter(this, void 0, void 0, function* () {
  390. return yield Unibase.Platform.Automation.Managers.RuleManager.Instance().getActions().then(function (response) {
  391. let cmbActions = document.getElementById('Action_Autocomplete_' + index + '');
  392. $('#Action_Autocomplete_' + index + '').empty();
  393. var defaultOpt1 = document.createElement("option");
  394. defaultOpt1.text = "Select";
  395. defaultOpt1.value = "0";
  396. cmbActions.appendChild(defaultOpt1);
  397. for (let i = 0; i <= response.length - 1; i++) {
  398. var opt = document.createElement("option");
  399. opt.text = response[i].ActionName;
  400. opt.value = response[i].ActionId.toString();
  401. cmbActions.appendChild(opt);
  402. }
  403. $("#Action_Autocomplete_" + index + "").val(Number($("#hf_Action_" + index + "").val()));
  404. $("#ActionLable_" + index + "").text($("#Action_Autocomplete_" + index + " option:selected").text());
  405. });
  406. });
  407. }
  408. ToggleEventColumnLable(index) {
  409. $("#ELable_" + index + "").addClass('hidden');
  410. $("#EAutocomplete_" + index + "").removeClass('hidden');
  411. $("#EventColumnLable_" + index + "").removeClass('form-group-required');
  412. }
  413. ToggleActions(index) {
  414. var instance = this;
  415. instance.CurrentEventIndex = index;
  416. $("#ALable_" + index + "").addClass('hidden');
  417. $("#AAutocomplete_" + index + "").removeClass('hidden');
  418. if ($("#ActionLable_" + index + "").text() != "Select" && $("#ActionLable_" + index + "").text() != "") {
  419. Unibase.Platform.Automation.Components.Rule.Instance().OnChangeActions(index);
  420. }
  421. }
  422. SaveRule(id, containerid) {
  423. let ruleid = Number(id);
  424. let eventgroupdata = [];
  425. if (!$("#ConditionDetailsDiv").hasClass("hidden")) {
  426. Unibase.Platform.Automation.Components.Rule.Instance().SaveQueryString();
  427. }
  428. let eventsarr = Rule.Instance().EventArray();
  429. for (let i = 0; i < eventsarr.length; i++) {
  430. eventgroupdata.push({
  431. EventGroupId: eventsarr[i].EventGroupId,
  432. RuleId: eventsarr[i].RuleId,
  433. RuleEventData: eventsarr[i].RuleEventData,
  434. RuleActionData: eventsarr[i].RuleActionData,
  435. RuleConditionData: eventsarr[i].RuleConditionData,
  436. RuleData: eventsarr[i].RuleData,
  437. RuleType: eventsarr[i].RuleType
  438. });
  439. }
  440. let model = new Unibase.Platform.Automation.Requests.Rule();
  441. model.RuleId = ruleid;
  442. model.RuleName = $("#txt_Rule").val().toString();
  443. model.RuleProviderId = Number($("#ddl_RuleProvider option:selected").val());
  444. if (Unibase.Platform.Automation.Components.Rule.QueryString != null) {
  445. model.SqlWhere = Unibase.Platform.Automation.Components.Rule.QueryString;
  446. model.SqlWhereJson = JSON.stringify(Unibase.Platform.Automation.Components.Rule.QueryString);
  447. }
  448. else {
  449. model.SqlWhere = '';
  450. model.SqlWhereJson = '';
  451. }
  452. model.EventGroupData = eventgroupdata;
  453. model.RuleType = Unibase.Platform.Automation.Enums.RuleType.Event;
  454. model.AutomationModeId = Number(Unibase.Platform.Automation.Components.Rule.AutomationMode);
  455. Automation.Managers.RuleManager.Instance().saveRule(model).then(function (response) {
  456. if (response.status == Unibase.Data.Status.Error) {
  457. MessageHelper.Instance().showError(response.message, "Validate_Rule");
  458. }
  459. else {
  460. MessageHelper.Instance().showSuccess(response.message, "Validate_Rule");
  461. Unibase.Platform.Automation.Components.Rule.ActionsArray = [];
  462. Unibase.Platform.Automation.Components.Rule.keysindex = 0;
  463. Unibase.Platform.Automation.Components.Rule.keyscount = 0;
  464. Unibase.Platform.Automation.Components.Rule.RuleId = 0;
  465. Unibase.Platform.Automation.Components.Rule.keysflag = 0;
  466. Unibase.Platform.Automation.Components.Rule.EventColumnData = [];
  467. Unibase.Platform.Automation.Components.Rule.RuleActionsData = [];
  468. Unibase.Platform.Automation.Components.RuleCondition.ruleConditionArray = [];
  469. $('#' + containerid).modal('hide');
  470. $('#' + containerid).remove();
  471. Unibase.Platform.Helpers.NavigationHelper.Instance().loadDetail(response.result.RuleId, Unibase.Platform.Automation.Components.Rule.installedappid, null);
  472. }
  473. });
  474. }
  475. EditRule(id, containerid) {
  476. $('#txt_search').attr("disabled", "true");
  477. $('#ddl_RuleProvider').attr("disabled", "true");
  478. $('#txt_Rule').attr("disabled", "true");
  479. let ruleid = Number(id);
  480. $("#Form_Rule").text("Edit Rule");
  481. Unibase.Platform.Automation.Managers.RuleManager.Instance().getRule(ruleid).then(function (response) {
  482. if (response.AutomationModeId == Number(Unibase.Platform.Automation.Enums.AutomationMode.NormalMode)) {
  483. let ruleid = response.RuleId;
  484. $("#hf_RuleProvider").val(response.RuleProviderId);
  485. $("#txt_Rule").val(response.RuleName);
  486. Unibase.Platform.Automation.Managers.RuleManager.Instance().getRuleProvider(response.RuleProviderId).then(function (response) {
  487. Unibase.Platform.Automation.Components.Rule.Instance().SelectedApp(response.InstalledAppId).then(function () {
  488. Unibase.Platform.Automation.Components.Rule.Instance().LoadEvents(ruleid);
  489. Unibase.Platform.Automation.Components.Rule.Instance().RuleInstalledAppId = Number(response.InstalledAppId);
  490. });
  491. });
  492. if (response.SqlWhere != "" && response.SqlWhere != null) {
  493. $("#btn_Conditions").addClass("hidden");
  494. $("#ConditionDetailsDiv").removeClass("hidden");
  495. }
  496. Unibase.Platform.Automation.Components.Rule.Instance().loadQueryBuilder(response.RuleProviderId, response.SqlWhere);
  497. }
  498. else {
  499. Unibase.Platform.Automation.Components.Rule.Instance().AdvancedMode(response.RuleId, containerid);
  500. }
  501. eval('_floatingLabelHelper.init();');
  502. });
  503. }
  504. LoadInstalledApps() {
  505. Unibase.Platform.Automation.Managers.RuleManager.Instance().getInstalledApps().then(function (response) {
  506. for (let i = 0; i <= response.length - 1; i++) {
  507. let html = '<div class="AppRow bg-white card" onclick="Unibase.Platform.Automation.Components.Rule.Instance().SelectedApp(' + response[i].InstalledAppId + ');" id ="div_' + response[i].InstalledAppId + '">' +
  508. '<div class="card-body">' +
  509. '<div class="row">' +
  510. '<div class="col-sm-12">' +
  511. '<span>' + response[i].AppTitle + '</span>' +
  512. '</div></div></div></div>';
  513. $("#InstalledAppsList").append(html);
  514. html = "";
  515. }
  516. });
  517. }
  518. LoadAppStages() {
  519. return __awaiter(this, void 0, void 0, function* () {
  520. var html = '';
  521. var installeappid = Unibase.Platform.Automation.Components.Rule.Instance().RuleInstalledAppId;
  522. yield Unibase.Platform.Apps.Managers.StageManager.Instance().getStages(installeappid).then(function (response) {
  523. if (response.result != null) {
  524. for (let i = 0; i < response.result.length; i++) {
  525. var data = response.result[i];
  526. html += '<option value=' + data.StageId + '>' + data.StageName + '<option>';
  527. }
  528. }
  529. });
  530. return html;
  531. });
  532. }
  533. IsStageChangeEvent() {
  534. var eventname = null;
  535. if (Unibase.Platform.Automation.Components.Rule.AutomationMode == Unibase.Platform.Automation.Enums.AutomationMode.AdvancedMode) {
  536. var ischildaction = eval('bizgaze_automation_flow_main.IsChildAction()');
  537. if (ischildaction) {
  538. return false;
  539. }
  540. eventname = $('.event_name').val() == undefined ? null : $('.event_name').val().toString();
  541. return (eventname == null) ? false : eventname.includes("stageid Changed");
  542. }
  543. else {
  544. var index = Unibase.Platform.Automation.Components.Rule.Instance().CurrentEventIndex;
  545. eventname = $('.event_name_' + index + '').val() == undefined ? null : $('.event_name_' + index + '').val().toString();
  546. return (eventname == null) ? false : eventname.includes("stageid Changed");
  547. }
  548. }
  549. SelectedApp(id) {
  550. return __awaiter(this, void 0, void 0, function* () {
  551. $(".AppRow").removeAttr("style");
  552. $("#div_" + id + "").css("border", " 2px solid blue");
  553. let InstalledappId = Number(id);
  554. Unibase.Platform.Automation.Components.Rule.Instance().RuleInstalledAppId = Number(InstalledappId);
  555. var url = _appsettings.server_url() + '/apis/v4/unibase/notificationrule/platform/ruleprovidersautocomplete/InstalledAppId/' + InstalledappId;
  556. yield Unibase.Platform.Automation.Managers.RuleManager.Instance().loadRuleProviders(id).then(function (response) {
  557. if (response.length != 0) {
  558. $("#RuleSection").removeClass("hidden");
  559. let cmbRuleProviders = document.getElementById('ddl_RuleProvider');
  560. $('#ddl_RuleProvider').empty();
  561. var defaultOpt1 = document.createElement("option");
  562. defaultOpt1.text = "Select";
  563. defaultOpt1.value = "";
  564. cmbRuleProviders.appendChild(defaultOpt1);
  565. for (let i = 0; i <= response.length - 1; i++) {
  566. var opt = document.createElement("option");
  567. opt.text = response[i].RuleProviderName;
  568. opt.value = (response[i].RuleProviderId).toString();
  569. cmbRuleProviders.appendChild(opt);
  570. }
  571. if ($("#hf_RuleProvider").val() == "") {
  572. $("#ddl_RuleProvider").val(null);
  573. }
  574. else {
  575. $("#ddl_RuleProvider").val(Number($("#hf_RuleProvider").val()));
  576. }
  577. return Unibase.Platform.Automation.Components.Rule.Instance().loadEventColomns();
  578. }
  579. else {
  580. MessageHelper.Instance().showError("No RuleProvider Configured For The Selected App.", "Validate_Rule");
  581. }
  582. });
  583. });
  584. }
  585. DeleteEventGroupRow(index, EventGroupId) {
  586. var text = confirm("Are you sure! You want to delete?");
  587. if (text) {
  588. if (EventGroupId != 0) {
  589. Unibase.Platform.Automation.Managers.RuleManager.Instance().deleteEventGroup(EventGroupId).then(function (response) {
  590. if (response.status == Unibase.Data.Status.Error) {
  591. MessageHelper.Instance().showError(response.message, "Validate_Rule");
  592. }
  593. else {
  594. $("#row_" + index).remove();
  595. }
  596. });
  597. }
  598. else {
  599. $("#row_" + index).remove();
  600. }
  601. }
  602. }
  603. AddEvent() {
  604. let PrevActionIndex = Unibase.Platform.Automation.Components.Rule.keysindex - 0;
  605. if ($("#ActionLable_" + PrevActionIndex).text() != "Select") {
  606. Unibase.Platform.Automation.Components.Rule.keysflag = 0;
  607. let html = "";
  608. let RuleEventId = 0;
  609. let RuleActionId = 0;
  610. let EventGroupId = 0;
  611. if (!Unibase.Platform.Automation.Components.Rule.keyscount) {
  612. Unibase.Platform.Automation.Components.Rule.keysindex = Unibase.Platform.Automation.Components.Rule.keysindex + 1;
  613. }
  614. else {
  615. Unibase.Platform.Automation.Components.Rule.keysindex = Unibase.Platform.Automation.Components.Rule.keyscount;
  616. }
  617. html += '<div class="row eventrow" id="row_' + Unibase.Platform.Automation.Components.Rule.keysindex + '">' +
  618. '<lable class="hidden" id="EventGroupId_' + Unibase.Platform.Automation.Components.Rule.keysindex + '">' + RuleEventId + '</lable>' +
  619. '<lable class="hidden" id="RuleActionId_' + Unibase.Platform.Automation.Components.Rule.keysindex + '">' + RuleActionId + '</lable>' +
  620. '<div class="col-sm-2 mt-10"><label>When </label></div>' +
  621. '<div class="col-sm-3 mt-10" id="ELable_' + Unibase.Platform.Automation.Components.Rule.keysindex + '" onclick="Unibase.Platform.Automation.Components.Rule.Instance().ToggleEventColumnLable(' + Unibase.Platform.Automation.Components.Rule.keysindex + ');"><u><b style="font-weight: bold;" id="EventColumnLable_' + Unibase.Platform.Automation.Components.Rule.keysindex + '"></b></u></div>' +
  622. '<div class="col-sm-3 hidden" id="EAutocomplete_' + Unibase.Platform.Automation.Components.Rule.keysindex + '">' +
  623. '<div id="div_EventColumns" class="floating-label-form-group" style="border-bottom:0;"><input type="hidden" class="event_name_' + Unibase.Platform.Automation.Components.Rule.keysindex + '"><select id="select2_EventColumns_' + Unibase.Platform.Automation.Components.Rule.keysindex + '" class="select2_0_EventColumns required value-control form-control text-control" multiple="multiple" style="width:100%;" onchange="Unibase.Platform.Automation.Components.Rule.Instance().OnChangeEventColumn(' + Unibase.Platform.Automation.Components.Rule.keysindex + ');"></select><input type="hidden" id="hfSelect2Id_EventColumns_' + Unibase.Platform.Automation.Components.Rule.keysindex + '" value="0" class="form-control text-control" data-isdynamic="true" /><input type="hidden" id="hfId_EventColumns" value=""><label for="Validation" id="lblValidation_EventColumns"></label></div></div>' +
  624. '<div class="col-sm-1 mt-10"><label id="Event_' + Unibase.Platform.Automation.Components.Rule.keysindex + '"></label></div>' +
  625. '<div class="col-sm-1 mt-10"><label>Then </label></div>' +
  626. '<div class="col-sm-3 mt-10" id="ALable_' + Unibase.Platform.Automation.Components.Rule.keysindex + '" onclick="Unibase.Platform.Automation.Components.Rule.Instance().ToggleActions(' + Unibase.Platform.Automation.Components.Rule.keysindex + ');"><u><b style="font-weight: bold;" id="ActionLable_' + Unibase.Platform.Automation.Components.Rule.keysindex + '"></b></u></div>' +
  627. '<div class="col-sm-3 hidden" id="AAutocomplete_' + Unibase.Platform.Automation.Components.Rule.keysindex + '">' +
  628. '<div class="floating-label-form-group floating-label-form-group-with-value focus">' +
  629. '<select id="Action_Autocomplete_' + Unibase.Platform.Automation.Components.Rule.keysindex + '" onchange="Unibase.Platform.Automation.Components.Rule.Instance().OnChangeActions(' + Unibase.Platform.Automation.Components.Rule.keysindex + ');" style="-webkit-appearance: none;" class="required form-control value-control" data-isdynamic="true">' +
  630. '</select>' +
  631. '<input type="hidden" id="hf_Action_' + Unibase.Platform.Automation.Components.Rule.keysindex + '" />' +
  632. '</div>' +
  633. '</div>' +
  634. '<div class="col-sm-1 mt-10"><a href="javascript:;" id="link_Configure"><i class="fa fa-cog"></i></a></div>' +
  635. '<div class="col-sm-1 mt-10" > <a id="delete_' + Unibase.Platform.Automation.Components.Rule.keysindex + '" title = "Delete" style="cursor:pointer" onclick = "Unibase.Platform.Automation.Components.Rule.Instance().DeleteEventGroupRow(' + Unibase.Platform.Automation.Components.Rule.keysindex + ',' + EventGroupId + ');" ><i class="fa fa-close"> </i></a></div >' +
  636. '</div>';
  637. if (Unibase.Platform.Automation.Components.Rule.keysflag == 0) {
  638. $("#AddNewEvents").append(html);
  639. $("#ActionLable_" + Unibase.Platform.Automation.Components.Rule.keysindex + "").text('Select');
  640. this.BindEventColumns(Unibase.Platform.Automation.Components.Rule.keysindex);
  641. this.loadActions(Unibase.Platform.Automation.Components.Rule.keysindex);
  642. Unibase.Platform.Automation.Components.Rule.keyscount = 0;
  643. Unibase.Platform.Automation.Components.Rule.keysflag = 0;
  644. }
  645. else {
  646. Unibase.Platform.Automation.Components.Rule.keysindex = Unibase.Platform.Automation.Components.Rule.keysindex - 1;
  647. }
  648. }
  649. else {
  650. $("#ActionLable_" + Unibase.Platform.Automation.Components.Rule.keysindex + "").addClass('form-group-required');
  651. MessageHelper.Instance().showError("Please Select Action.", "Validate_Rule");
  652. }
  653. }
  654. EventArray() {
  655. var instance = this;
  656. let eventgrouparray = [];
  657. $(".eventrow").each(function () {
  658. let eventarray = [];
  659. let eventgroupobj = {};
  660. let id = $(this).find(".eventrow");
  661. let index = (id.prevObject[0].id).split('_');
  662. index = index[1];
  663. let eventcolumns = Unibase.Platform.Automation.Components.Rule.Instance().GetEventColumns(index).split(",");
  664. for (var i = 0; i < eventcolumns.length; i++) {
  665. let eventobj = {};
  666. let eventtype;
  667. let etype = eventcolumns[i].split(" ")[1];
  668. let eventcolumn = "";
  669. if (etype.toLowerCase() == "created") {
  670. eventtype = Unibase.Platform.Automation.Enums.EventType.Created;
  671. }
  672. else if (etype.toLowerCase() == "deleted") {
  673. eventtype = Unibase.Platform.Automation.Enums.EventType.Deleted;
  674. }
  675. else if (eventcolumns[i].toLowerCase() == "stageid changed") {
  676. eventtype = Unibase.Platform.Automation.Enums.EventType.StageEvent;
  677. eventcolumn = eventcolumns[i].split(" ")[0];
  678. }
  679. else {
  680. eventtype = Unibase.Platform.Automation.Enums.EventType.Updated;
  681. eventcolumn = eventcolumns[i].split(" ")[0];
  682. }
  683. eventobj.RuleEventId = 0;
  684. eventobj.EventColumnName = eventcolumn;
  685. eventobj.EventType = eventtype;
  686. eventarray.push(eventobj);
  687. }
  688. eventgroupobj.EventGroupId = Number($(this).find("#EventGroupId_" + index + "").text());
  689. eventgroupobj.RuleEventData = eventarray;
  690. eventgroupobj.RuleActionData = Unibase.Platform.Automation.Components.Rule.RuleActionsData.filter(X => X.RowIndex == index);
  691. eventgrouparray.push(eventgroupobj);
  692. });
  693. return eventgrouparray;
  694. }
  695. LoadEvents(RuleId) {
  696. return __awaiter(this, void 0, void 0, function* () {
  697. var groupBy = function (xs, key) {
  698. return xs.reduce(function (rv, x) {
  699. (rv[x[key]] = rv[x[key]] || []).push(x);
  700. return rv;
  701. }, {});
  702. };
  703. Unibase.Platform.Automation.Components.Rule.keysindex = 0;
  704. $("#row_0").remove();
  705. yield Unibase.Platform.Automation.Managers.RuleManager.Instance().getRuleEvents(RuleId).then(function (response) {
  706. var result = groupBy(response, "EventGroupId");
  707. var keys = Object.keys(result);
  708. for (var i = 0; i <= keys.length - 1; i++) {
  709. let EventGroupId = Number(keys[i]);
  710. var reinfo = result[EventGroupId];
  711. Unibase.Platform.Automation.Components.Rule.keysindex = i + 1;
  712. Unibase.Platform.Automation.Components.Rule.Instance().LoadEventsHtml(Unibase.Platform.Automation.Components.Rule.keysindex, EventGroupId, reinfo);
  713. }
  714. });
  715. });
  716. }
  717. LoadEventsHtml(Index, EventGroupId, reinfo) {
  718. return __awaiter(this, void 0, void 0, function* () {
  719. var instance = this;
  720. instance.CurrentEventIndex = Index;
  721. Unibase.Platform.Automation.Managers.RuleManager.Instance().getRuleActionByEventGroupId(EventGroupId).then(function (response) {
  722. var html = "";
  723. html += '<div class="row eventrow" id="row_' + Index + '">' +
  724. '<lable class="hidden" id="EventGroupId_' + Index + '">' + EventGroupId + '</lable>' +
  725. '<lable class="hidden" id="RuleActionId_' + Index + '">' + response.RuleActionId + '</lable>' +
  726. '<div class="col-sm-2 mt-10"><label>When </label></div>' +
  727. '<div class="col-sm-3 mt-10" id="ELable_' + Index + '" onclick="Unibase.Platform.Automation.Components.Rule.Instance().ToggleEventColumnLable(' + Index + ');"><u><b style="font-weight: bold;" id="EventColumnLable_' + Index + '"></b></u></div>' +
  728. '<div class="col-sm-3 hidden" id="EAutocomplete_' + Index + '">' +
  729. '<div id="div_EventColumns" class="floating-label-form-group" style="border-bottom:0;"><input type="hidden" class="event_name_' + Index + '"><select id="select2_EventColumns_' + Index + '" class="select2_0_EventColumns required value - control form - control text - control" multiple="multiple" style="width: 100 %; " onchange="Unibase.Platform.Automation.Components.Rule.Instance().OnChangeEventColumn(' + Index + '); "><option>Select</option></select><input type="hidden" id="hfSelect2Id_EventColumns_' + Index + '" value="0" class="form - control text - control" data-isdynamic="true" /><input type="hidden" id="hfId_EventColumns" value=""><label for="Validation" id="lblValidation_EventColumns"></label></div></div>' +
  730. '<div class="col-sm-1 mt-10"><label id="Event_' + Index + '"></label></div>' +
  731. '<div class="col-sm-1 mt-10"><label>Then </label></div>' +
  732. '<div class="col-sm-3 mt-10" id="ALable_' + Index + '" onclick="Unibase.Platform.Automation.Components.Rule.Instance().ToggleActions(' + Index + ');"><u><b style="font-weight: bold;" id="ActionLable_' + Index + '"></b></u></div>' +
  733. '<div class="col-sm-3 hidden" id="AAutocomplete_' + Index + '">' +
  734. '<div class="floating-label-form-group floating-label-form-group-with-value focus">' +
  735. '<select id="Action_Autocomplete_' + Index + '" onchange="Unibase.Platform.Automation.Components.Rule.Instance().OnChangeActions(' + Index + ');" style="-webkit-appearance: none;" class="required form-control value-control" data-isdynamic="true">' +
  736. '</select>' +
  737. '<input type="hidden" id ="hf_Action_' + Index + '" />' +
  738. '</div>' +
  739. '</div>' +
  740. '<div class="col-sm-1 mt-10"><a href="javascript:;" id="link_Configure"><i class="fa fa-cog"></i></a></div>' +
  741. '<div class="col-sm-1 mt-10"><a id="delete_' + Unibase.Platform.Automation.Components.Rule.keysindex + '" title = "Delete" style="cursor:pointer" onclick = "Unibase.Platform.Automation.Components.Rule.Instance().DeleteEventGroupRow(' + Unibase.Platform.Automation.Components.Rule.keysindex + ',' + EventGroupId + ');" ><i class="fa fa-close"> </i></a></div >' +
  742. '</div>';
  743. $("#NormalModeEvent").removeClass("hidden");
  744. $("#AddNewEvents").append(html);
  745. $("#hf_Action_" + Index + "").val(response.ActionId);
  746. let EventColArr = [];
  747. for (var j = 0; j <= reinfo.length - 1; j++) {
  748. let eventname = reinfo[j].EventName;
  749. if (reinfo[j].EventColumnName != null && reinfo[j].EventColumnName != "") {
  750. eventname = eventname.split("_")[2];
  751. EventColArr.push("" + eventname + " Changed");
  752. }
  753. else {
  754. let eventtype = eventname.split("_")[2];
  755. if (eventtype.toLowerCase() == "created") {
  756. eventname = eventname.split("_created")[0];
  757. EventColArr.push("" + eventname + " Created");
  758. }
  759. else {
  760. eventname = eventname.split("_deleted")[0];
  761. EventColArr.push("" + eventname + " Deleted");
  762. }
  763. }
  764. }
  765. Unibase.Platform.Automation.Components.Rule.Instance().BindEventColumns(Index);
  766. $("#select2_EventColumns_" + Index + "").val(EventColArr).trigger('change');
  767. let eventcolumns = Unibase.Platform.Automation.Components.Rule.Instance().GetEventColumns(Index);
  768. $("#EventColumnLable_" + Index + "").text(eventcolumns);
  769. $('.event_name_' + Index + '').val('').val(eventcolumns);
  770. Unibase.Platform.Automation.Components.Rule.Instance().loadActions(Index);
  771. });
  772. });
  773. }
  774. GetEventColumns(index) {
  775. let eventcolumnscount = new Array();
  776. eventcolumnscount = $("#select2_EventColumns_" + index + "").val();
  777. var eventcolumn = "";
  778. for (var i = 0; i < eventcolumnscount.length; i++) {
  779. eventcolumn += eventcolumnscount[i] + ",";
  780. }
  781. return eventcolumn.slice(0, -1);
  782. }
  783. RuleActionsArray(obj) {
  784. let ruleactionobj = {};
  785. ruleactionobj.RuleActionId = obj.RuleActionId;
  786. ruleactionobj.ActionId = obj.ActionId;
  787. ruleactionobj.RuleId = obj.RuleId;
  788. ruleactionobj.RuleActionName = obj.RuleActionName;
  789. ruleactionobj.String1 = obj.String1;
  790. ruleactionobj.String2 = obj.String2;
  791. ruleactionobj.String3 = obj.String3;
  792. ruleactionobj.String4 = obj.String4;
  793. ruleactionobj.String5 = obj.String5;
  794. ruleactionobj.String6 = obj.String6;
  795. ruleactionobj.String7 = obj.String7;
  796. ruleactionobj.BString1 = obj.BString1;
  797. ruleactionobj.BString2 = obj.BString2;
  798. ruleactionobj.BString3 = obj.BString3;
  799. ruleactionobj.BString4 = obj.BString4;
  800. ruleactionobj.BString5 = obj.BString5;
  801. ruleactionobj.BString6 = obj.BString6;
  802. ruleactionobj.BString7 = obj.BString7;
  803. ruleactionobj.BString8 = obj.BString8;
  804. ruleactionobj.BString9 = obj.BString9;
  805. ruleactionobj.BString10 = obj.BString10;
  806. ruleactionobj.BString11 = obj.BString11;
  807. ruleactionobj.BString12 = obj.BString12;
  808. ruleactionobj.BString13 = obj.BString13;
  809. ruleactionobj.Users = obj.Users;
  810. ruleactionobj.SecondaryUsers = obj.SecondaryUsers;
  811. ruleactionobj.ParentActionId = obj.ParentActionId;
  812. ruleactionobj.ResultActionName = obj.ResultActionName;
  813. ruleactionobj.ResultActionId = obj.ResultActionId;
  814. ruleactionobj.DelayTime = obj.DelayTime;
  815. ruleactionobj.ActionConditionData = obj.ActionConditionData;
  816. ruleactionobj.RowIndex = obj.RowIndex;
  817. ruleactionobj.AutoApproved = obj.AutoApproved;
  818. ruleactionobj.RecipientsData = obj.RecipientsData;
  819. ruleactionobj.SqlWhere = obj.SqlWhere;
  820. ruleactionobj.SqlWhereJson = obj.SqlWhere;
  821. ruleactionobj.ExternalReportId = obj.ExternalReportId;
  822. ruleactionobj.ExternalReportColumnId = obj.ExternalReportColumnId;
  823. ruleactionobj.ProviderColumnId = obj.ProviderColumnId;
  824. ruleactionobj.ApproveStageId = obj.ApproveStageId;
  825. ruleactionobj.IsParent = obj.IsParent;
  826. ruleactionobj.FromStage = obj.FromStage;
  827. ruleactionobj.ToStage = obj.ToStage;
  828. ruleactionobj.NotificationGroupId = obj.NotificationGroupId;
  829. var Array = Unibase.Platform.Automation.Components.Rule.RuleActionsData.find(x => x.RowIndex == obj.RowIndex);
  830. if (Array != undefined) {
  831. Unibase.Platform.Automation.Components.Rule.RuleActionsData[obj.RowIndex] = ruleactionobj;
  832. }
  833. else {
  834. Unibase.Platform.Automation.Components.Rule.RuleActionsData.push(ruleactionobj);
  835. }
  836. Unibase.Platform.Automation.Components.Rule.Instance().loadQueryBuilder(Number($("#ddl_RuleProvider option:selected").val()), Unibase.Platform.Automation.Components.Rule.QueryString);
  837. }
  838. ChangeAction(index, Id) {
  839. if (Id == 0) {
  840. $("#Action_Autocomplete_" + index + "").val($("#hf_Action_" + index + "").val());
  841. $("#ActionLable_" + index + "").text('Select');
  842. Unibase.Platform.Automation.Components.Rule.RuleActionsData = Unibase.Platform.Automation.Components.Rule.RuleActionsData.filter(X => X.RowIndex != index);
  843. }
  844. Unibase.Platform.Automation.Components.Rule.Instance().loadQueryBuilder(Number($("#ddl_RuleProvider option:selected").val()), Unibase.Platform.Automation.Components.Rule.QueryString);
  845. }
  846. AdvancedMode(id, containerid) {
  847. var _fileCacheHelper = this.fileCacheHelper;
  848. var instance = this;
  849. $('#' + containerid).modal('hide');
  850. $('#' + containerid).remove();
  851. Unibase.Platform.Automation.Components.Rule.AutomationMode = Unibase.Platform.Automation.Enums.AutomationMode.AdvancedMode;
  852. var rulebuilder = new Unibase.Platform.Automation.Components.RuleBuilder();
  853. instance.navigationHelper.popup(id, '', rulebuilder, null, Platform.Helpers.Size.ExtraLarge);
  854. }
  855. loadQueryBuilder(ruleproviderid, querystring) {
  856. return __awaiter(this, void 0, void 0, function* () {
  857. return yield Unibase.Platform.Automation.Managers.RuleManager.Instance().getRuleProvider(ruleproviderid).then(function (response) {
  858. let ruleconditionhtml = Unibase.Platform.DataSources.Components.QueryBuilder.Instance().html(null, null);
  859. jQuery(".ConditionDetails").html(ruleconditionhtml);
  860. var qinstance = Unibase.Platform.DataSources.Components.QueryBuilder.Instance();
  861. qinstance.QueryBuilder_Columns = [];
  862. qinstance.QueryBuilder_Filters = [];
  863. qinstance.queryBuilderString = "";
  864. if (response.ReportId != 0) {
  865. qinstance.ReportId = response.ReportId;
  866. qinstance.loadQueryBuilderDiv(querystring);
  867. }
  868. else {
  869. qinstance.DoctypeId = response.DoctypeId;
  870. qinstance.loadQueryBuilderDivByDoctypeId(querystring);
  871. }
  872. $("#QueryBuilder").removeClass("hidden");
  873. });
  874. });
  875. }
  876. SaveQueryString() {
  877. let queryelmnt = $("#builder");
  878. let query = queryelmnt.queryBuilder('getSQL', false, true);
  879. if (query != null) {
  880. Unibase.Platform.Automation.Components.Rule.QueryString = queryelmnt.queryBuilder('getSQL', false, true).sql.replace(/\n/g, " ").replace(/LIKE/g, "ILIKE");
  881. }
  882. else {
  883. Unibase.Platform.Automation.Components.Rule.QueryString = null;
  884. }
  885. queryelmnt.queryBuilder('destroy');
  886. $("#QueryBuilder").remove();
  887. }
  888. SearchBlocks() {
  889. var input, filter, div, subdiv, a, i, count;
  890. input = document.getElementById("txt_Search");
  891. filter = input.value.toUpperCase();
  892. div = document.getElementById("InstalledAppsList");
  893. subdiv = div.getElementsByClassName("AppRow");
  894. count = 0;
  895. for (i = 0; i < subdiv.length; i++) {
  896. if (subdiv[i].textContent.toUpperCase() == filter) {
  897. a = subdiv[i];
  898. if (a.innerHTML.indexOf(filter) > -1) {
  899. subdiv[i].style.display = "";
  900. }
  901. }
  902. else {
  903. a = subdiv[i];
  904. if (a.textContent.toUpperCase().indexOf(filter) > -1) {
  905. subdiv[i].style.display = "";
  906. }
  907. else {
  908. subdiv[i].style.display = "none";
  909. count = count + 1;
  910. }
  911. }
  912. if (subdiv.length == count) {
  913. $("#txt_noresults").removeClass("hidden");
  914. }
  915. else if (subdiv.length != count) {
  916. $("#txt_noresults").addClass("hidden");
  917. }
  918. else { }
  919. }
  920. }
  921. EmptyEventColumns() {
  922. return __awaiter(this, void 0, void 0, function* () {
  923. Unibase.Platform.Automation.Components.Rule.EventColumnData = [];
  924. return yield $(".eventrow").each(function () {
  925. let id = $(this).find(".eventrow");
  926. let index = (id.prevObject[0].id).split('_');
  927. index = index[1];
  928. $("#select2_EventColumns_" + index + "").empty();
  929. });
  930. });
  931. }
  932. static Instance() {
  933. if (this.instance === undefined) {
  934. this.instance = new Rule();
  935. }
  936. return this.instance;
  937. }
  938. }
  939. Rule.keysindex = 0;
  940. Rule.keysflag = 0;
  941. Rule.AutomationMode = 0;
  942. Rule.EventColumnData = [];
  943. Rule.RuleActionsData = [];
  944. Rule.ActionsArray = [];
  945. Components.Rule = Rule;
  946. })(Components = Automation.Components || (Automation.Components = {}));
  947. })(Automation = Platform.Automation || (Platform.Automation = {}));
  948. })(Platform = Unibase.Platform || (Unibase.Platform = {}));
  949. })(Unibase || (Unibase = {}));