$(function() { "use strict"; BWA.Popup = BWA.Popup || {}; BWA.Popup.SearchView = { create: function(options) { var handleSearch = options.handleSearch, handleInitializeUpdate = options.handleInitializeUpdate, parentPopupId = options.parentPopupId, parentPopupVisible = options.parentPopupVisible, promiseDataForSearch = options.promiseDataForSearch, searchItems = $SearchView.getSearchItems(options.searchItems, promiseDataForSearch); var popupVisible = ko.observable(false), position = ko.observable(), height = ko.observable(), initialized = false, timer = null ; function handleButtonSearch() { if (handleSearch) { var filter = $SearchView.getFilter(searchItems); handleSearch(filter, searchItems); } } popupVisible.subscribe(function(value) { if (value) { if (timer !== null) { clearInterval(timer); } var top, left; var element = $(['#', parentPopupId].join('')).offsetParent(); position({ my: 'left top', at: 'right top', of: element }); height(element.height() + 4); timer = setInterval(function() { element = $(['#', parentPopupId].join('')).offsetParent(); var offset = element.offset(); if (offset) { if (top !== offset.top || left !== offset.left) { top = offset.top; left = offset.left; position({ my: 'left top', at: 'right top', of: element }); } } }, 100); } else { if (timer !== null) { clearInterval(timer); timer = null; } } }); parentPopupVisible.subscribe(function(value) { if (value === false) { popupVisible(false); } }); return { toolbarItems: [ { location: 'before', text: $G('searchCondition') }, { location: 'after', widget: 'button', options: { text: $G('search'), icon: 'search', clickAction: handleButtonSearch } } ], searchItems: searchItems, popupOptions: { visible: popupVisible, width: '315px', height: height, position: position, dragEnabled: false, shownAction: function() { if (initialized === false) { if (handleInitializeUpdate) { handleInitializeUpdate(); } initialized = true; } }, closeOnOutsideClick: false, shading: false, animation: { show: { type: "fade", duration: 350, from: 0, to: 1 }, hide: { type: "fade", duration: 200, from: 1, to: 0 } } }, show: function() { popupVisible(true); }, hide: function() { popupVisible(false); }, }; } }; });