Odyssey
hcuProfileDesc.prg
1 <?php
2  /*
3  * File: hcuProfileDesc
4  *
5  * Purpose: Handle the client-side updating of the user's account descriptions.
6  *
7  */
8 
9  // ** SET SCRIPT LEVEL VARIABLES
10  $serviceShowInfo = true;
11  $serviceLoadMenu = true;
12  $serviceShowMenu = true;
13 
14  // ** INCLUDE MAIN GLOBAL SCRIPT -- Handles security / global variable values
15  require_once(dirname(__FILE__) . '/../library/hcuService.i');
16 
17  /*
18  * ** CHECK USER FEATURE PERMISSIONS **
19  * NOTE: DOES NOT RETURN ON FAILURE
20  */
21  PermCheckFeatureScreen($dbh, $HB_ENV, $MC, FEATURE_BASIC);
22 
23  // ** INSERT BUSINESS LOGIC FOR THIS FORM
24 
25 
26  // ** SET VARIABLES FOR WEBSITE FLAGS
27 
28  // ** INCLUDE PRE CONTENT SCRIPT
29  require_once(dirname(__FILE__) . '/../includes/hcuPreContent.i');
30 
31  /*
32  * ** START CONTENT
33  */
34 
35  $Cu = $HB_ENV["Cu"];
36  $Cn = $HB_ENV["Cn"];
37  $live = $HB_ENV["live"];
38 
39  # get the frag if there is one
40  // ** Check to make sure the Terms are returned.
41  // * if no frag returned, use default text from dictionary
42  $settingsText = "";
43  $noticesAry = Get_NoticeInfo($dbh, $HB_ENV, $MC, 'D', 'profileDescNotice');
44  if ( $noticesAry["status"]["code"] == "000" && HCU_array_key_exists('0', $noticesAry['notice'])) {
45  if ( $noticesAry['notice'][0]['notice_text'] ) {
46  $settingsText = $noticesAry['notice'][0]['notice_text'];
47  }
48  }
49 
50  if ($settingsText == "") {
51  $settingsText = $MC->msg('Account Names Change', HCU_DISPLAY_AS_HTML);
52  }
53  ?>
54 <script type="text/javascript">
55 
56  $(document).ready(function() {
57 
58  // FIRST LOAD OF PAGE
59  var FIRST_LOAD = true;
60 
61  // DATA SETS FOR EACH GRID
62  var data_dp = [];
63  var data_ln = [];
64  var data_cc = [];
65  var data_fl = [];
66 
67  // HELP WINDOW
68  var hcuWindow_help = null;
69 
70  // GRID OBJECTS FOR EACH GRID
71  var hcuGridDesktop_deposit = null;
72  var hcuGridMobile_deposit = null;
73 
74  var hcuGridDesktop_loan = null;
75  var hcuGridMobile_loan = null;
76 
77  var hcuGridDesktop_credit = null;
78  var hcuGridMobile_credit = null;
79 
80  var hcuShowReset = false;
81  var hcuResetConfirm = null;
82  var hcuWindowStack = [];
83 
84  // clear the account name on button click.
85  $(".hcuProfileDescDiv").on("click", ".accountClearBtn", function() {
86  $(this).closest(".input-group").find("[name='accountName']").val(null);
87  return false;
88  });
89 
90  // DATASOURCE FOR READING AND BUILDING GRIDS
91  var hcuDataSource_read = new kendo.data.DataSource({
92  autoSync: false,
93  batch: false,
94  transport: {
95  read: {
96  url: "hcuProfile.data?cu=<?php echo $HB_ENV["cu"] ?>",
97  dataType: "json",
98  contentType: "application/x-www-form-urlencoded",
99  type: "GET",
100  data: {
101  action: "acct_desc_read"
102  },
103  cache: false
104  },
105  update: {
106  url: "hcuProfile.data?cu=<?php echo $HB_ENV["cu"] ?>",
107  dataType: "json",
108  contentType: "application/x-www-form-urlencoded",
109  type: "POST",
110  data: {
111  action: "acct_desc_update"
112  },
113  cache: false
114  }
115  },
116  schema: {
117  model: { id: "displayorder" },
118  parse: function(response) {
119  var errors = [];
120  var success = [];
121 
122  // CHECK FOR ERROR
123  if (response.hasOwnProperty('homecuErrors')) {
124  error = response.homecuErrors;
125 
126  // DISPLAY ERROR
127  if (error && error.length > 0) {
128  $.homecuValidator.displayMessage(error, $.homecuValidator.settings.statusError);
129  }
130  // STATUS MESSAGE
131  } else if (response.hasOwnProperty("homecuInfo")) {
132  ShowStatus(response.homecuInfo[0]);
133 
134  // DATA READ
135  } else {
136  success = response.homecuData;
137 
138  // DATA ARRAY TO NEW ARRAY
139  data_fl = [];
140 
141  // DATA SETS FOR EACH GRID
142  data_dp = success.dp;
143  data_ln = success.ln;
144  data_cc = success.cc;
145 
146  // PREORDER GRIDS
147  /*preOrder(data_dp, "dp");
148  preOrder(data_ln, "ln");
149  preOrder(data_cc, "cc");*/
150 
151  // COMBINE FOR DATASOURCE (ONLY USED FOR SENDING UPDATE TO SQL)
152  data_fl = data_fl.concat(data_dp);
153  data_fl = data_fl.concat(data_ln);
154  data_fl = data_fl.concat(data_cc);
155 
156  // GET RESET ABILITY
157  hcuShowReset = canResetOrder(data_fl);
158 
159  if (!FIRST_LOAD) {
160  var template= kendo.template($("#sortableTemplate").html());
161  $("#hcuSortableMobileDeposit").html(template({theData: data_dp}));
162  $("#hcuSortableMobileLoan").html(template({theData: data_ln}));
163  $("#hcuSortableMobileCredit").html(template({theData: data_cc}));
164  } else {
165  // BUILD DESKTOP GRIDS
166  buildSortable("dp");
167  buildSortable("ln");
168  buildSortable("cc");
169 
170  // SET FIRST_LOAD FALSE TO NOT BUILD GRIDS MULTIPLE TIMES
171  FIRST_LOAD = false;
172  }
173 
174  if (hcuShowReset) {
175  $("#lnkCancel").show();
176  } else {
177  $("#lnkCancel").hide();
178  }
179  }
180 
181  // SET CHANGE LISTENER ON ALL GRID INPUT FIELDS. THIS WILL ENSURE DATA PERSISTS THROUGH RESIZING BETWEEN DESKTOP AND MOBILE GRIDS
182 
183  return data_fl;
184  }
185  }
186  });
187 
188  <?php
189  /**
190  * function buildSortable(key)
191  * This function adds the kendoSortable object to deposit, loan, and credit (depending on the key). Replaces buildGrid function.
192  *
193  * @param key -- "dp", "ln", "cc"
194  */
195  ?>
196  function buildSortable(key) {
197  var template= kendo.template($("#sortableTemplate").html());
198  switch(key)
199  {
200  case "dp":
201  var selector= $("#hcuSortableMobileDeposit");
202  var data= data_dp;
203  break;
204  case "ln":
205  var selector= $("#hcuSortableMobileLoan");
206  var data= data_ln;
207  break;
208  case "cc":
209  var selector= $("#hcuSortableMobileCredit");
210  var data= data_cc;
211  break;
212  default: return;
213  }
214  if (data.length == 0)
215  $(selector).closest(".hcu-container-margin").remove(); // Don't even show it.
216  else
217  {
218  $(selector).empty().html(template({theData: data}));
219 
220  if (data.length > 1) // Won't be able to rearrange with one item so don't give the functionality.
221  $(selector).addClass("sortableArea").kendoSortable({
222  hint: function(element) {
223  return $(element).clone().addClass("hintDiv").text($(element).find(".hint").text().trim());
224  },
225  placeholder: function(element) {
226  return $(element).clone().addClass("placeholderDiv k-info-colored").text('<?php echo $MC->msg("Drop Here", HCU_DISPLAY_AS_JS); ?>');
227  },
228  container: $(selector).closest(".hcu-container-margin"),
229  axis: "y",
230  cursor: "move",
231  handler: ".handler *,.handler",
232  ignore: "input",
233  change: function(e) {
234  hcuShowReset = true;
235  $("#lnkCancel").show();
236  }
237  }).data("kendoSortable");
238  }
239 
240  }
241 
242  function canResetOrder(data) {
243  for (var i = 0; i < data.length; i++) {
244  var cur_obj = data[i];
245  var cur_order = parseInt(cur_obj.displayorder);
246 
247  if (cur_order > 0) {
248  return true;
249  }
250  }
251 
252  return false;
253  }
254 
255  // FIX UP DISPLAY ORDER:
256  // MUST BE SEQUENTIAL, NO DUPLICATES, START AT 0
257  function preOrder(ary_data, ary_type) {
258 
259  // MUST ADD PROPERTY 'GRID' FOR TEMPLATE ID'S
260  for ( var i = 0; i < ary_data.length; i++) {
261  ary_data[i]['grid'] = ary_type;
262  }
263 
264  // PREORDER GRID DATA
265  for (var i = 0; i < ary_data.length; i++) {
266  // GET CURRENT OBJECT
267  var cur_obj = ary_data[i];
268  var cur_order = parseInt(cur_obj.displayorder);
269 
270  // show reset button if any records ahev display order
271  if (cur_order > 0) { hcuShowReset = true; }
272 
273  // VALUE AT CURRENT POSITION MUST = 'i'
274  if (cur_order != i) {
275  var find_order = preOrderFind(ary_data, i);
276 
277  if(find_order.length > 0) {
278  var find_index = find_order[0];
279  var find_obj = ary_data[find_index];
280 
281  // IF OBJECT WITH THIS DISPLAYORDER EXISTS, SWAP WITH THE FIRST OCCURRENCE INTO THE CURRENT POSITION.
282  ary_data[i] = find_obj;
283  ary_data[find_index] = cur_obj;
284  } else {
285  cur_obj.displayorder = i;
286  }
287  }
288  }
289  }
290 
291  function preOrderFind(ary_data, ary_order) {
292  var ary_find = [];
293 
294  for (var i = 0; i < ary_data.length; i++) {
295  var order = ary_data[i].displayorder;
296 
297  // SET ORDER TO INTEGER
298  ary_data[i].displayorder = parseInt(order);
299 
300  if (order == ary_order) {
301  ary_find.push(i);
302  }
303  }
304 
305  return ary_find;
306  }
307 
308  // SUCCESS AND ERROR DISPLAY FUNCTIONS
309  function ShowStatus( statusMessage ) {
310  $.homecuValidator.settings.formStatusField = "formStatus";
311  $.homecuValidator.settings.formInfoTitle = "";
312  $.homecuValidator.displayMessage(statusMessage);
313  }
314 
315  function ClearStatus( ) {
316  $.homecuValidator.settings.formStatusField = "formStatus";
317  $.homecuValidator.settings.formInfoTitle = "";
318  $.homecuValidator.displayMessage(null);
319  }
320 
321  function ResetDisplayOrder() {
322  var accountData = [];
323  for(var i=0; i!= data_dp.length; i++)
324  {
325  accountData.push({displayname: data_dp[i].displayname, displayorder: 0, encryption: data_dp[i].encryption});
326  }
327  for(var i=0; i!= data_ln.length; i++)
328  {
329  accountData.push({displayname: data_ln[i].displayname, displayorder: 0, encryption: data_ln[i].encryption});
330  }
331  for(var i=0; i!= data_cc.length; i++)
332  {
333  accountData.push({displayname: data_cc[i].displayname, displayorder: 0, encryption: data_cc[i].encryption});
334  }
335 
336  // SEND DATA TO DATASOURCE
337  ShowWaitWindow();
338  hcuDataSource_read.transport.options.update.data = {
339  action: "acct_desc_update",
340  account_data: accountData
341  };
342  hcuDataSource_read.data()[0].dirty = true;
343  hcuDataSource_read.sync();
344 
345  // REFRESH GRIDS
346  setTimeout(function() {
347  hcuDataSource_read.read();
348  CloseWaitWindow();
349  }, 1000);
350 
351  hcuShowReset = false;
352  }
353 
354  $("#hcuResetConfirm").kendoDialog({
355  modal: true,
356  visible: false,
357  resizeable: false,
358  show: function() {
359  hcuWindowStack.push(this);
360  },
361  close: function() {
362  hcuWindowStack.pop();
363  },
364  actions: [
365  { text: "<?php echo $MC->msg("Cancel", HCU_DISPLAY_AS_JS); ?>",
366  action: function(e) {}
367  },
368  {
369  text: "<?php echo $MC->msg("Continue", HCU_DISPLAY_AS_JS); ?>", primary: true,
370  action: ResetDisplayOrder
371  }
372  ]
373  });
374 
375  $("#btnUpdate").click(function() {
376  // resetting validator status
377  $.homecuValidator.homecuValidate = true;
378 
379  var newIndex= 1;
380  var accountData= [];
381  $("#hcuSortableMobileDeposit .sortable").each(function() {
382  var orgindex= Number($(this).data("orgindex"));
383  accountData.push({displayname: $(this).find("[name='accountName']").val().trim(), displayorder: (hcuShowReset ? newIndex++ : 0), encryption: data_dp[orgindex].encryption});
384  });
385 
386  $("#hcuSortableMobileLoan .sortable").each(function() {
387  var orgindex= Number($(this).data("orgindex"));
388  accountData.push({displayname: $(this).find("[name='accountName']").val().trim(), displayorder: (hcuShowReset ? newIndex++ : 0), encryption: data_ln[orgindex].encryption});
389  });
390 
391  $("#hcuSortableMobileCredit .sortable").each(function() {
392  var orgindex= Number($(this).data("orgindex"));
393  accountData.push({displayname: $(this).find("[name='accountName']").val().trim(), displayorder: (hcuShowReset ? newIndex++ : 0), encryption: data_cc[orgindex].encryption});
394  });
395 
396  // SEND DATA TO DATASOURCE
397  ShowWaitWindow();
398 
399  // CAPTURE ALL ACCOUNT USER DEFINED NAMES
400  accountDesc = Array();
401  for (var i = 0; i < accountData.length; i++) {
402  if (accountData[i].displayname !== ""){
403  accountDesc.push(accountData[i].displayname);
404  }
405  }
406 
407  if ($.homecuValidator.homecuValidate) {
408 
409  hcuDataSource_read.transport.options.update.data = {action: "acct_desc_update", account_data: accountData};
410  hcuDataSource_read.data()[0].dirty = true;
411  hcuDataSource_read.sync();
412 
413  // REFRESH GRIDS
414  setTimeout(function() {
415  hcuDataSource_read.read();
416  CloseWaitWindow();
417  }, 1000);
418 
419  return false;
420 
421  } else {
422  CloseWaitWindow();
423  }
424 
425  });
426 
427  $('#lnkCancel').click(function() {
428  $("#hcuResetConfirm").data("kendoDialog").open();
429  });
430 
431  $('#btnHelp').click(function(e) {
432  e.preventDefault();
433 
434  // BUILD WINDOW
435  hcuWindow_help = $('#hcuWindowHelp').data('kendoWindow');
436 
437  // CHECK WINDOW EXISTS
438  if (!hcuWindow_help) {
439  hcuWindow_help = $('#hcuWindowHelp').kendoWindow({
440  width: "95%",
441  modal: true,
442  visible: false,
443  actions: ['Close'],
444  close: function() {
445  hcuWindow_help = null;
446  hcuWindowStack.pop();
447  },
448  activate: function() {
449  hcuWindowStack.push(this);
450  }
451  }).data('kendoWindow');
452  }
453 
454  // GET CONTENT
455  var hcuContent_help = $('#hcuTemplateHelp').html();
456  var hcuContent_title = "<?php echo $MC->msg("Help", HCU_DISPLAY_AS_HTML); ?>";
457 
458  // SET WINDOW CONTENT AND OPEN
459  hcuWindow_help.title(hcuContent_title);
460  hcuWindow_help.content(hcuContent_help);
461  hcuWindow_help.center();
462  hcuWindow_help.open();
463  });
464 
465  // START PAGE
466  hcuDataSource_read.read();
467 
468  $(document).on('click', '.k-overlay', function() {
469  if (hcuWindowStack.length > 0) {
470  hcuWindowStack[0].close();
471  }
472  });
473 
474  });
475 
476 </script>
477 <!-- HTML STYLING -->
478 <style type="text/css">
479 .hcuProfileDescDiv {
480  min-width: 300px;
481  max-width: 700px;
482  margin-left: 0px;
483  margin-top: 15px;
484 }
485 
486 .k-block > .k-header {
487  white-space: normal;
488  height: 100%;
489 }
490 
491 html .k-grid tr:hover {
492  background: transparent;
493 }
494 
495 .k-grid td {
496  border-left: 0 !important;
497  border-right: 0 !important;
498 }
499 
500 .hcu-info-margin, .hcu-error-margin {
501  margin: 15px 0;
502 }
503 
504 .hcu-info-padding, .hcu-error-padding {
505  padding: 15px;
506 }
507 
508 .hcu-full-width {
509  width: 100%;
510 }
511 
512 /* top-bottom margin */
513 .hcu-container-margin {
514  margin: 15px 0;
515 }
516 
517 .hcu-no-padding {
518  padding: 0;
519 }
520 </style>
521 
522 <!-- HTML CONTENT -->
523 
524 <div class="container-fluid hcuProfileDescDiv">
525  <div class="well well-sm col-xs-12">
526 
527  <!-- HEADER -->
528  <div class="col-xs-11 col-sm-11 hcu-no-padding">
529  <h3><?php echo $MC->msg("Account Names", HCU_DISPLAY_AS_HTML); ?></h3>
530 
531  </div>
532 
533  <div class="col-xs-1 col-sm-1 hcu-no-padding text-center">
534  <a href="#" id="btnHelp" class="hcu-full-width">
535  <span><?php echo $MC->msg("Help", HCU_DISPLAY_AS_HTML); ?></span>
536  </a>
537  </div>
538 
539  <!-- CONTENT -->
540 
541  <div class="col-sm-12 hcu-container-margin">
542  <div><h4><?php echo $MC->msg("Deposit Accounts", HCU_DISPLAY_AS_HTML); ?></h4></div>
543  <div id="hcuSortableMobileDeposit"></div>
544  </div>
545 
546  <div class="col-sm-12 hcu-container-margin">
547  <div><h4><?php echo $MC->msg("Loan Accounts", HCU_DISPLAY_AS_HTML); ?></h4></div>
548  <div id="hcuSortableMobileLoan"></div>
549  </div>
550 
551  <div class="col-sm-12 hcu-container-margin">
552  <div><h4><?php echo $MC->msg("Credit Accounts", HCU_DISPLAY_AS_HTML); ?></h4></div>
553  <div id="hcuSortableMobileCredit"></div>
554  </div>
555  </div>
556 
557  <div class="hcu-template">
558  <div class="hcu-edit-buttons k-state-default">
559  <a href="##" id="lnkCancel"><?php echo $MC->msg("Reset Display Order", HCU_DISPLAY_AS_HTML); ?></a>
560  &emsp;
561  <a href="##" id="btnUpdate" class="k-button k-primary">
562  <i class="fa fa-check fa-lg"></i><?php echo $MC->msg("Update", HCU_DISPLAY_AS_HTML); ?>
563  </a>
564  </div>
565  </div>
566 </div>
567 
568 <!-- HELP WINDOW -->
569 <div id="hcuWindowHelp"></div>
570 
571 <div id="hcuResetConfirm">
572  <p><strong><?php echo $MC->msg("Reset Confirm", HCU_DISPLAY_AS_HTML); ?></strong></p>
573  <p><?php echo $MC->msg("wish to continue", HCU_DISPLAY_AS_HTML); ?></p>
574 </div>
575 
576 <!-- MOBILE TEMPLATES -->
577 <script type="text/x-kendo-template" id="sortableTemplate">
578  # var length= theData.length; for(var i=0; i!= length; i++) { var row= theData[i]; #
579  <div class="col-xs-12 sortable" data-orgindex="#: i #">
580  <div style="padding-top: 5px;"><span style='font-size: 10pt;' class="hint">#= row.title #</span></div>
581  <div class="input-group">
582  # if (length > 1) { #
583  <div class="input-group-addon handler"><span class='fa fa-arrows-v'></span></div>
584  # } #
585  <input type='text' name='accountName' class='k-textbox hcu-full-width form-control' style='font-size: 9pt;' value='#: row.displayname #' maxlength="255"
586  placeholder="#= row.placeholder #">
587  <div class="accountClearBtn input-group-addon">
588  <span class='fa fa-times' aria-hidden='true'></span>
589  </div>
590  </div>
591  </div>
592  # } #
593 </script>
594 
595 <!-- TEMPLATE: HELP WINDOW -->
596 <script type="text/x-kendo-template" id="hcuTemplateHelp">
597  <div>
598  <div class="well k-info-colored">
599  <span><strong><?php echo $MC->msg("Account Names", HCU_DISPLAY_AS_HTML); ?>:</strong></span>
600  <br><br>
601  <span><?php echo $settingsText; ?></span>
602  <br><br>
603  <span><?php echo $MC->msg("Account Names Reset", HCU_DISPLAY_AS_HTML); ?></span>
604  <br><br>
605  <span><strong><?php echo $MC->msg("Display Order", HCU_DISPLAY_AS_HTML); ?>:</strong></span>
606  <br><br>
607  <span><?php echo $MC->msg("Display Order Change", HCU_DISPLAY_AS_HTML); ?></span>
608  <br>
609  <br>
610  <span><?php echo $MC->msg("Display Order Reset", HCU_DISPLAY_AS_HTML); ?></span>
611  </div>
612  </div>
613 </script>
614 <?php
615  /*
616  * ** END CONTENT
617  */
618 
619 // ** INCLUDE POST CONTENT SCRIPT
620 require_once(dirname(__FILE__) . '/../includes/hcuPostContent.i');
621 
622 ?>