bab547d663ff5fbdd53ed5b1d3aed92a6270bc49.svn-base 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. 
  2. $(function() {
  3. "use strict";
  4. BWA.Popup = BWA.Popup || {};
  5. BWA.Popup.SearchView = {
  6. create: function(options) {
  7. var handleSearch = options.handleSearch,
  8. handleInitializeUpdate = options.handleInitializeUpdate,
  9. parentPopupId = options.parentPopupId,
  10. parentPopupVisible = options.parentPopupVisible,
  11. promiseDataForSearch = options.promiseDataForSearch,
  12. searchItems = $SearchView.getSearchItems(options.searchItems, promiseDataForSearch);
  13. var popupVisible = ko.observable(false),
  14. position = ko.observable(),
  15. height = ko.observable(),
  16. initialized = false,
  17. timer = null
  18. ;
  19. function handleButtonSearch() {
  20. if (handleSearch) {
  21. var filter = $SearchView.getFilter(searchItems);
  22. handleSearch(filter, searchItems);
  23. }
  24. }
  25. popupVisible.subscribe(function(value) {
  26. if (value) {
  27. if (timer !== null) {
  28. clearInterval(timer);
  29. }
  30. var top, left;
  31. var element = $(['#', parentPopupId].join('')).offsetParent();
  32. position({ my: 'left top', at: 'right top', of: element });
  33. height(element.height() + 4);
  34. timer = setInterval(function() {
  35. element = $(['#', parentPopupId].join('')).offsetParent();
  36. var offset = element.offset();
  37. if (offset) {
  38. if (top !== offset.top || left !== offset.left) {
  39. top = offset.top;
  40. left = offset.left;
  41. position({ my: 'left top', at: 'right top', of: element });
  42. }
  43. }
  44. }, 100);
  45. }
  46. else {
  47. if (timer !== null) {
  48. clearInterval(timer);
  49. timer = null;
  50. }
  51. }
  52. });
  53. parentPopupVisible.subscribe(function(value) {
  54. if (value === false) {
  55. popupVisible(false);
  56. }
  57. });
  58. return {
  59. toolbarItems: [
  60. { location: 'before', text: $G('searchCondition') },
  61. { location: 'after', widget: 'button', options: { text: $G('search'), icon: 'search', clickAction: handleButtonSearch } }
  62. ],
  63. searchItems: searchItems,
  64. popupOptions: {
  65. visible: popupVisible,
  66. width: '315px',
  67. height: height,
  68. position: position,
  69. dragEnabled: false,
  70. shownAction: function() {
  71. if (initialized === false) {
  72. if (handleInitializeUpdate) {
  73. handleInitializeUpdate();
  74. }
  75. initialized = true;
  76. }
  77. },
  78. closeOnOutsideClick: false,
  79. shading: false,
  80. animation: {
  81. show: { type: "fade", duration: 350, from: 0, to: 1 },
  82. hide: { type: "fade", duration: 200, from: 1, to: 0 }
  83. }
  84. },
  85. show: function() {
  86. popupVisible(true);
  87. },
  88. hide: function() {
  89. popupVisible(false);
  90. },
  91. };
  92. }
  93. };
  94. });