searchcustomer.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. var $selectedItem;
  2. var selectItem = function(item)
  3. {
  4. $selectedItem = $(item).first();
  5. var modal = $('#ajaxModal');
  6. var params = params + 'customers=' + $('input[type=hidden][name*=customers]').val() + ',' + $selectedItem.data('key')
  7. var link = createLink(module, method, params);
  8. modal.load(link, function(){$(this).find('.modal-dialog').css('width', $(this).data('width')); $.zui.ajustModalPosition()})
  9. };
  10. $(document).ready(function()
  11. {
  12. var showSearchModal = function()
  13. {
  14. var key = $('#customers_chosen .chosen-results > li.no-results > span').text();
  15. var customers = $('[name*=customer]').val().join(',').replace(',showmore', '');
  16. var link = createLink('customer', 'ajaxSearchCustomer', 'key=' + key + '&relation=&customers=' + customers);
  17. $('#ajaxModal').load(link);
  18. };
  19. $(document).on('change', '#customers', function()
  20. {
  21. if($.inArray('showmore', $(this).val()) > 0)
  22. {
  23. showSearchModal();
  24. }
  25. });
  26. $(document).on('click', '#customers_chosen .chosen-results > li.no-results', showSearchModal);
  27. $(document).on('hide.zui.modal', '#triggerModal', function()
  28. {
  29. var key = '';
  30. var $customer = $('#customers');
  31. if($selectedItem && $selectedItem.length)
  32. {
  33. key = $selectedItem.data('key');
  34. if(!$customer.children('option[value="' + key + '"]').length)
  35. {
  36. $customer.prepend('<option value="' + key + '">' + $selectedItem.text() + '</option>');
  37. }
  38. }
  39. $customer.val(key).trigger("chosen:updated");
  40. $selectedItem = null;
  41. });
  42. })