123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
-
- $(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);
- },
- };
- }
- };
- });
|