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.

cartdetails.component.js 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. var Bizgaze;
  2. (function (Bizgaze) {
  3. let Apps;
  4. (function (Apps) {
  5. let Transact;
  6. (function (Transact) {
  7. let Controls;
  8. (function (Controls) {
  9. class CartDetails extends Unibase.Platform.Core.BaseComponent {
  10. constructor() {
  11. super(...arguments);
  12. this.g_Categories = [];
  13. }
  14. init(formpropertyid, prop, callback) {
  15. var instance = this;
  16. instance.loadControlSettings(prop.ControlJsonText, prop.FormPropertyId);
  17. instance.loadPropertySettings(prop.PropertySettings, prop.FormPropertyId);
  18. }
  19. loadControl(containerid, prop) {
  20. var html = `<div class="col-sm-12 cart-categories-wrap">
  21. <div id="categoryInputCard" class="card d-none">
  22. <div class="card-body pa-10 text-center">
  23. <input type="text" class="form-control category-input" id="addCategoryInput" placeholder="Enter Category"/>
  24. <a href="javascript:;" class="btn btn-sm btn-primary mt-15" id="addCategoryBtn" data-uniqueid='0'>Add</a>
  25. </div>
  26. </div>
  27. <a href="javascript:;" class="btn btn-sm btn-primary pull-right mb-15 hidden" id="cartCategoryAddBtn">Add Category
  28. </a>
  29. <div id="addedCategoriesList" class="added-categories-list d-none"></div>
  30. </div>
  31. <div class="row col-sm-12">
  32. <div class="col-sm-12">
  33. <div class="col-sm-8 divOrderCart pull-left">
  34. <a id="totalOrderItems_link" style="cursor:pointer"><u class="text-info" style="color:deepskyblue;font-size:15px">Total Items : (<b class="netpacks" id="totalOrderItems"></b>) </u></a>
  35. </div>
  36. <div class="col-sm-4 pull-right">
  37. <span class="font-bold pull-right"> Total Quantity : (<b id="OverallOrderQuantity"></b>)</span>
  38. </div>
  39. </div>
  40. </div>
  41. <br/>` +
  42. `<div class="col-sm-12 m-t-xs leverage-Warning hidden">
  43. <div class="alert alert-success alert-block">
  44. <h4>Warning..!</h4>
  45. <p id="lblSpocNotes">Leverage percent exceeded, Some item have the discount of more than your approved leverage of <span class="empLeverage"></span> %.
  46. </p>
  47. </div>
  48. </div>
  49. <div class="order-cart-list" id="CartItemsList" style="min-height:150px;">` +
  50. `<div class="floating-label-form-group CartItemFindTxt hidden">
  51. <label for="CartItemSearch" id="">Search Items </label>
  52. <input type="search" id="cartItemsSearch" class="form-control floating-label-control" data-isdynamic="false" placeholder="Search Items" data-placeholder="Item Name" data-label="Search Items" autocomplete="on"/>
  53. </div>` +
  54. `<ul class="list-group no-radius clear cartItemsSortable col-sm-12" id="ulOrder_Cart"></ul>
  55. <ul class="list-group no-radius clear col-sm-12" id="ulOpportunityTag_Cart"></ul>
  56. <div id="ContinueShopping_Div" class="row mt-10">
  57. <div class="col-md-8 col-sm-6">
  58. <a href="javascript:;" id="btn_ContinueShopping" class="btn btn-primary ContinueShopping mr-auto btn-sm">Continue Shopping</a>
  59. </div>
  60. <div class="col-md-4 col-sm-6 biz-select2-wrap d-none" id="categoriesSelectWrap">
  61. <select id="cartCategoriesSelect"></select>
  62. </div>
  63. </div>
  64. </div>`;
  65. $("#" + containerid).html(html);
  66. }
  67. loadControlSettings(controlsettingjson, formpropertyid) {
  68. const instance = this;
  69. $("#totalOrderItems_link").click(function () {
  70. $("#ulOrder_Cart").toggleClass("hidden");
  71. });
  72. $("#cartItemsSearch").on("keyup", function () {
  73. let value = $(this).val().toString().toLowerCase();
  74. $("#ulOrder_Cart li:not(:first-child)").filter(function () {
  75. $(this).toggle($(this).text().toLowerCase().indexOf(value) > -1);
  76. });
  77. });
  78. $('#cartCategoriesSelect').select2({
  79. placeholder: 'Select Category',
  80. data: instance.g_Categories,
  81. allowClear: true,
  82. }).on('select2:select', function () {
  83. const catId = +$(this).val();
  84. $(this).val("").trigger("change");
  85. $('#ulOrder_Cart .cart-item-chk').each(function (i, e) {
  86. if ($(e).is(':checked')) {
  87. const catSortableEl = $(`#catItemsSortable_${catId}`);
  88. $(e).parents('.cartitem').detach().appendTo(catSortableEl);
  89. catSortableEl.find('.cart-item-remove').removeClass('d-none').click(function () {
  90. const cartItemEl = $(this).parents('.cartitem');
  91. cartItemEl.find('.cart-item-remove').addClass('d-none');
  92. cartItemEl.find('.cart-item-chk').removeClass('d-none');
  93. cartItemEl.detach().appendTo($("#ulOrder_Cart"));
  94. });
  95. catSortableEl.find('.cart-item-chk').addClass('d-none').prop('checked', false);
  96. }
  97. });
  98. });
  99. $('#cartCategoryAddBtn').click(function () {
  100. $(this).addClass('d-none');
  101. $('#categoryInputCard').removeClass('d-none');
  102. });
  103. $('#addCategoryBtn').click(function () {
  104. const inputVal = $('#addCategoryInput').val();
  105. const key = +$(this).attr('data-uniqueid');
  106. if (inputVal.trim().length) {
  107. $('#addCategoryInput').val('');
  108. $('#addedCategoriesList').append(`<div class="card cart-cat-card" id="catergoryCard_${key}" data-catid="${key}"><div class="card-header d-flex justify-content-between align-items-center pa-10" id="catCardHeader_${key}"><div class="cat-title-wrap"><span class="cat-title-span" id="catTitleSpan_${key}">${inputVal}</span><input type="text" value="${inputVal}" class="cat-title-input form-control font-14 h-30p py-0 px-1 d-none" id="catTitleInput_${key}"></div><div class="flex-shrink-0 ml-15"><a href="javascript:;" class="btn btn-icon btn-flush-biz-theme btn-rounded flush-soft-hover d-30" id="catTitleEditBtn_${key}" data-tooltip="true" title="Edit title"><span class="btn-icon-wrap"><i class="fa fa-pencil font-16"></i></span></a><a href="javascript:;" class="btn btn-icon btn-flush-biz-theme btn-rounded flush-soft-hover d-30 d-none" id="catTitleSaveBtn_${key}" data-tooltip="true" title="Save title"><span class="btn-icon-wrap"><i class="fa fa-check font-16 text-success"></i></span></a></div></div><div class="card-body pa-10" id="catergoryCardBody_${key}"><ul id="catItemsSortable_${key}" class="cartItemsSortable d-flex flex-column"><li class="alert alert-warning text-center border border-2 border-dotted flex-center h-10p my-10 order-1 drag-placeholder">Drag Items Here</li></ul></div></div>`).removeClass('d-none');
  109. $(this).attr('data-uniqueid', key + 1);
  110. const newCatObj = { id: key, text: inputVal };
  111. instance.g_Categories.push(newCatObj);
  112. const newOption = new Option(newCatObj.text, newCatObj.id.toString(), false, false);
  113. $('#categoriesSelectWrap,#ulOrder_Cart .cart-item-chk').removeClass('d-none');
  114. $('#cartCategoriesSelect').append(newOption);
  115. $('#cartCategoriesSelect').val(null).trigger('change');
  116. const orderCartEl = $('#ulOrder_Cart');
  117. orderCartEl.sortable();
  118. orderCartEl.sortable('destroy');
  119. orderCartEl.sortable({
  120. connectWith: '.cartItemsSortable',
  121. receive: function () {
  122. orderCartEl.find('.drag-placeholder').remove();
  123. },
  124. remove: function () {
  125. if (!orderCartEl.find('.cartitem:visible').length) {
  126. orderCartEl.append('<li class="alert alert-warning text-center border border-2 border-dotted flex-center mb-10 order-1 drag-placeholder h-10p mt-30">Drag Items Here</li>');
  127. }
  128. else {
  129. orderCartEl.find('.drag-placeholder').remove();
  130. }
  131. }
  132. }).disableSelection();
  133. $(`#catItemsSortable_${key}`).sortable({
  134. connectWith: ".cartItemsSortable",
  135. items: '.cartitem',
  136. cancel: ".drag-placeholder",
  137. receive: function (event, ui) {
  138. $(ui.item).find('.cart-item-chk').addClass('d-none');
  139. $(ui.item).find('.cart-item-remove').removeClass('d-none').click(function () {
  140. $(this).addClass('d-none');
  141. $(ui.item).find('.cart-item-chk').removeClass('d-none');
  142. $(this).parents('.cartitem').detach().appendTo(orderCartEl);
  143. });
  144. },
  145. remove: function (event, ui) {
  146. $(ui.item).find('.cart-item-remove').addClass('d-none');
  147. $(ui.item).find('.cart-item-chk').removeClass('d-none');
  148. }
  149. }).disableSelection();
  150. $(`#catTitleEditBtn_${key}`).click(function () {
  151. $(`#catTitleEditBtn_${key},#catTitleSpan_${key}`).addClass('d-none');
  152. $(`#catTitleInput_${key},#catTitleSaveBtn_${key}`).removeClass('d-none');
  153. $(`#catTitleInput_${key}`).trigger('focus');
  154. });
  155. $(`#catTitleSaveBtn_${key}`).click(function () {
  156. const inputVal = $(`#catTitleInput_${key}`).val().toString();
  157. $(`#catTitleInput_${key},#catTitleSaveBtn_${key}`).addClass('d-none');
  158. $(`#catTitleEditBtn_${key},#catTitleSpan_${key}`).removeClass('d-none');
  159. $(`#catTitleSpan_${key}`).text(inputVal);
  160. $(`#cartCategoriesSelect option[value="${key}"]`).remove();
  161. const newCatObj = { id: key, text: inputVal };
  162. const newOption = new Option(newCatObj.text, newCatObj.id.toString(), false, false);
  163. $('#cartCategoriesSelect').append(newOption);
  164. $('#cartCategoriesSelect').val(null).trigger('change');
  165. });
  166. }
  167. });
  168. }
  169. loadPropertySettings(propertysettings, formpropertyid) {
  170. return null;
  171. }
  172. bindEditFormDetails(formpropertyid, propval, DocPropertyName) {
  173. return null;
  174. }
  175. getCategoryIndex(CategoryName) {
  176. let instance = this;
  177. let CatgryIndex = instance.g_Categories.findIndex(x => x.CategoryName == CategoryName);
  178. return CatgryIndex;
  179. }
  180. getNewRowId() {
  181. let text = "";
  182. let possible = "0123456789";
  183. for (let i = 0; i < 5; i++)
  184. text += possible.charAt(Math.floor(Math.random() * possible.length));
  185. return Number(text);
  186. }
  187. isCategoryExists(CategoryName) {
  188. let instance = this;
  189. let CatgryIndex = instance.getCategoryIndex(CategoryName);
  190. if (CatgryIndex == -1) {
  191. return false;
  192. }
  193. else {
  194. return true;
  195. }
  196. }
  197. pushCategoryIfNotExists(CategoryName) {
  198. let instance = this;
  199. let isCatgryExists = instance.isCategoryExists(CategoryName);
  200. if (!isCatgryExists) {
  201. let CatgryRowId = instance.getNewRowId();
  202. let CatgryIndex = instance.getCategoryIndex(CategoryName);
  203. if (CatgryIndex != -1) {
  204. CatgryRowId = instance.getNewRowId();
  205. }
  206. instance.g_Categories.push({
  207. CategoryName: CategoryName,
  208. CatgryRowId: CatgryRowId
  209. });
  210. }
  211. }
  212. getCategoryDesign(CatgryRowId, CategoryName) {
  213. let html = `<div class="card cart-cat-card" id="catergoryCard_` + CatgryRowId + `" data-catid="` + CatgryRowId + `">
  214. <div class="card-header d-flex justify-content-between align-items-center pa-10" id="catCardHeader_` + CatgryRowId + `">
  215. <div class="cat-title-wrap">
  216. <span class="cat-title-span" id="catTitleSpan_` + CatgryRowId + `">` + CategoryName + `</span>
  217. <input type="text" value="` + CategoryName + `" class="cat-title-input form-control font-14 h-30p py-0 px-1 d-none" id="catTitleInput_` + CatgryRowId + `">
  218. </div>
  219. <div class="flex-shrink-0 ml-15">
  220. <a href="javascript:;" class="btn btn-icon btn-flush-biz-theme btn-rounded flush-soft-hover d-30" id="catTitleEditBtn_` + CatgryRowId + `" data-tooltip="true" title="Edit Category">
  221. <span class="btn-icon-wrap">
  222. <i class="fa fa-pencil font-16"></i>
  223. </span>
  224. </a>
  225. <a href="javascript:;" class="btn btn-icon btn-flush-biz-theme btn-rounded flush-soft-hover d-30 d-none" id="catTitleSaveBtn_` + CatgryRowId + `" data-tooltip="true" title="Save Category">
  226. <span class="btn-icon-wrap">
  227. <i class="fa fa-check font-16 text-success"></i>
  228. </span>
  229. </a>
  230. </div>
  231. </div>
  232. <div class="card-body pa-10" id="catergoryCardBody_` + CatgryRowId + `">
  233. <ul id="catItemsSortable_` + CatgryRowId + `" class="cartItemsSortable d-flex flex-column">
  234. <input type="hidden" id="hf_categoryrowid" value=` + CatgryRowId + `>
  235. <input type="hidden" id="hf_categoryname" value=` + CategoryName + `>
  236. <li class="alert alert-warning text-center border border-2 border-dotted flex-center h-10p my-10 order-1 drag-placeholder">Drag Items Here</li>
  237. </ul>
  238. </div>
  239. </div>`;
  240. return html;
  241. }
  242. bindCategoryEvents(CatgryRowId, CategoryName) {
  243. let key = CatgryRowId;
  244. $('#addCategoryInput').val('');
  245. $('#addedCategoriesList').removeClass('d-none');
  246. let optionLength = $("#cartCategoriesSelect option[value='" + CatgryRowId + "']").length;
  247. if (optionLength == 0) {
  248. const newOption = new Option(CategoryName, CatgryRowId.toString(), false, false);
  249. $('#cartCategoriesSelect').append(newOption);
  250. $('#cartCategoriesSelect').val(null).trigger('change');
  251. }
  252. $('#categoriesSelectWrap,#ulOrder_Cart .cart-item-chk').removeClass('d-none');
  253. const orderCartEl = $('#ulOrder_Cart');
  254. orderCartEl.sortable();
  255. orderCartEl.sortable('destroy');
  256. orderCartEl.sortable({
  257. connectWith: '.cartItemsSortable',
  258. receive: function () {
  259. orderCartEl.find('.drag-placeholder').remove();
  260. },
  261. remove: function () {
  262. if (!orderCartEl.find('.cartitem:visible').length) {
  263. orderCartEl.append('<li class="alert alert-warning text-center border border-2 border-dotted flex-center mb-10 order-1 drag-placeholder h-10p mt-30">Drag Items Here</li>');
  264. }
  265. else {
  266. orderCartEl.find('.drag-placeholder').remove();
  267. }
  268. }
  269. }).disableSelection();
  270. $(`#catItemsSortable_` + key).sortable({
  271. connectWith: ".cartItemsSortable",
  272. items: '.cartitem',
  273. cancel: ".drag-placeholder",
  274. receive: function (event, ui) {
  275. $(ui.item).find('.cart-item-chk').addClass('d-none');
  276. $(ui.item).find('.cart-item-remove').removeClass('d-none').click(function () {
  277. $(this).addClass('d-none');
  278. $(ui.item).find('.cart-item-chk').removeClass('d-none');
  279. $(this).parents('.cartitem').detach().appendTo(orderCartEl);
  280. });
  281. },
  282. remove: function (event, ui) {
  283. $(ui.item).find('.cart-item-remove').addClass('d-none');
  284. $(ui.item).find('.cart-item-chk').removeClass('d-none');
  285. }
  286. }).disableSelection();
  287. $(`#catTitleEditBtn_` + key).click(function () {
  288. $(`#catTitleEditBtn_` + key + `,#catTitleSpan_` + key).addClass('d-none');
  289. $(`#catTitleInput_` + key + `,#catTitleSaveBtn_` + key).removeClass('d-none');
  290. $(`#catTitleInput_` + key).trigger('focus');
  291. });
  292. $(`#catTitleSaveBtn_` + key).click(function () {
  293. const inputVal = $(`#catTitleInput_` + key).val().toString();
  294. $(`#catTitleInput_` + key + `,#catTitleSaveBtn_` + key).addClass('d-none');
  295. $(`#catTitleEditBtn_` + key + `,#catTitleSpan_` + key).removeClass('d-none');
  296. $(`#catTitleSpan_` + key).text(inputVal);
  297. $(`#cartCategoriesSelect option[value="` + key + `"]`).remove();
  298. const newCatObj = { id: key, text: inputVal };
  299. const newOption = new Option(newCatObj.text, newCatObj.id.toString(), false, false);
  300. $('#cartCategoriesSelect').append(newOption);
  301. $('#cartCategoriesSelect').val(null).trigger('change');
  302. });
  303. }
  304. bindElementToCategory(html, CategoryName) {
  305. let instance = this;
  306. let CatgryRowId = 0;
  307. $('#cartCategoryAddBtn').addClass('d-none');
  308. $('#categoryInputCard').removeClass('d-none');
  309. let isCatgryExists = instance.isCategoryExists(CategoryName);
  310. let CatgryIndex = instance.getCategoryIndex(CategoryName);
  311. if (!isCatgryExists) {
  312. instance.pushCategoryIfNotExists(CategoryName);
  313. CatgryIndex = instance.getCategoryIndex(CategoryName);
  314. CatgryRowId = instance.g_Categories[CatgryIndex].CatgryRowId;
  315. let CatgryDesign = instance.getCategoryDesign(CatgryRowId, CategoryName);
  316. $("#addedCategoriesList").append(CatgryDesign).removeClass("d-none");
  317. }
  318. if (CatgryIndex != -1) {
  319. CatgryRowId = instance.g_Categories[CatgryIndex].CatgryRowId;
  320. $("#catItemsSortable_" + CatgryRowId).append(html);
  321. instance.bindCategoryEvents(CatgryRowId, CategoryName);
  322. instance.hideUnUsedCategories();
  323. }
  324. }
  325. hideUnUsedCategories() {
  326. let instance = this;
  327. $(".cartItemsSortable").each(function () {
  328. let li_length = $(this).find(".cartitem").length;
  329. if (li_length == 0) {
  330. let CatgryRowId = $(this).find("#hf_categoryrowid").val();
  331. $("#catergoryCard_" + CatgryRowId).remove();
  332. let CatgryIndex = instance.g_Categories.findIndex(x => x.CatgryRowId == CatgryRowId);
  333. if (CatgryIndex != -1) {
  334. instance.g_Categories.splice(CatgryIndex, 1);
  335. $("#cartCategoriesSelect option[value='" + CatgryRowId + "']").remove();
  336. }
  337. }
  338. });
  339. }
  340. static Instance() {
  341. if (this.instance === undefined) {
  342. this.instance = new CartDetails();
  343. }
  344. return this.instance;
  345. }
  346. }
  347. Controls.CartDetails = CartDetails;
  348. })(Controls = Transact.Controls || (Transact.Controls = {}));
  349. })(Transact = Apps.Transact || (Apps.Transact = {}));
  350. })(Apps = Bizgaze.Apps || (Bizgaze.Apps = {}));
  351. })(Bizgaze || (Bizgaze = {}));