|
|
|
@ -25,11 +25,16 @@ |
|
|
|
opts.filterForm = $(opts.filterForm); |
|
|
|
} |
|
|
|
|
|
|
|
var getFilters = function ($widgetWrapperDiv) { |
|
|
|
var publicApi = { |
|
|
|
init: init, |
|
|
|
refresh: refresh |
|
|
|
}; |
|
|
|
|
|
|
|
function getFilters($widget) { |
|
|
|
var filters = {}; |
|
|
|
|
|
|
|
if (opts.filterForm) { |
|
|
|
opts.filterForm.each(function() { |
|
|
|
opts.filterForm.each(function () { |
|
|
|
filters = $.extend(filters, opts.filterForm.serializeFormToObject()); |
|
|
|
}); |
|
|
|
} |
|
|
|
@ -38,55 +43,66 @@ |
|
|
|
filters = $.extend(filters, opts.filterCallback()); |
|
|
|
} |
|
|
|
|
|
|
|
var widgetApi = $widgetWrapperDiv.data('abp-widget-api'); |
|
|
|
var widgetApi = $widget.data('abp-widget-api'); |
|
|
|
if (widgetApi && widgetApi.getFilters) { |
|
|
|
filters = $.extend(filters, widgetApi.getFilters()); |
|
|
|
} |
|
|
|
|
|
|
|
return filters; |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
var init = function () { |
|
|
|
opts.wrapper.findWithSelf('.abp-widget-wrapper').each(function () { |
|
|
|
var $widgetWrapperDiv = $(this); |
|
|
|
var widgetName = $widgetWrapperDiv.attr('data-widget-name'); |
|
|
|
function init($widgets) { |
|
|
|
if(!$widgets){ |
|
|
|
$widgets = opts.wrapper.findWithSelf('.abp-widget-wrapper'); |
|
|
|
} |
|
|
|
|
|
|
|
$widgets.each(function () { |
|
|
|
var $widget = $(this); |
|
|
|
$widget.data('abp-widget-manager', publicApi); |
|
|
|
var widgetName = $widget.attr('data-widget-name'); |
|
|
|
var widgetApiClass = abp.widgets[widgetName]; |
|
|
|
if (widgetApiClass) { |
|
|
|
var widgetApi = new widgetApiClass($widgetWrapperDiv); |
|
|
|
$widgetWrapperDiv.data('abp-widget-api', widgetApi); |
|
|
|
var widgetApi = new widgetApiClass($widget); |
|
|
|
$widget.data('abp-widget-api', widgetApi); |
|
|
|
if (widgetApi.init) { |
|
|
|
widgetApi.init(getFilters($widgetWrapperDiv)); |
|
|
|
widgetApi.init(getFilters($widget)); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
function refresh($widgets) { |
|
|
|
if(!$widgets){ |
|
|
|
$widgets = opts.wrapper.findWithSelf('.abp-widget-wrapper'); |
|
|
|
} |
|
|
|
|
|
|
|
var refresh = function () { |
|
|
|
opts.wrapper.findWithSelf('.abp-widget-wrapper').each(function () { |
|
|
|
var $widgetWrapperDiv = $(this); |
|
|
|
$widgets.each(function () { |
|
|
|
var $widget = $(this); |
|
|
|
|
|
|
|
var refreshUrl = $widgetWrapperDiv.attr('data-refresh-url'); |
|
|
|
var refreshUrl = $widget.attr('data-refresh-url'); |
|
|
|
if (refreshUrl) { |
|
|
|
abp.ajax({ |
|
|
|
url: refreshUrl, |
|
|
|
type: 'GET', |
|
|
|
dataType: 'html', |
|
|
|
contentType: 'application/x-www-form-urlencoded; charset=UTF-8', |
|
|
|
data: getFilters($widgetWrapperDiv) |
|
|
|
data: getFilters($widget) |
|
|
|
}).then(function (result) { |
|
|
|
$widgetWrapperDiv.replaceWith($(result)); |
|
|
|
var $result = $(result); |
|
|
|
$widget.replaceWith($result); |
|
|
|
init($result); |
|
|
|
}); |
|
|
|
} else { |
|
|
|
var widgetApi = $widgetWrapperDiv.data('abp-widget-api'); |
|
|
|
var widgetApi = $widget.data('abp-widget-api'); |
|
|
|
if (widgetApi && widgetApi.refresh) { |
|
|
|
widgetApi.refresh(getFilters($widgetWrapperDiv)); |
|
|
|
widgetApi.refresh(getFilters($widget)); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
if (opts.filterForm) { |
|
|
|
opts.filterForm.each(function() { |
|
|
|
opts.filterForm.each(function () { |
|
|
|
$(this).submit(function (e) { |
|
|
|
e.preventDefault(); |
|
|
|
refresh(); |
|
|
|
@ -94,11 +110,6 @@ |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
var publicApi = { |
|
|
|
init: init, |
|
|
|
refresh: refresh |
|
|
|
}; |
|
|
|
|
|
|
|
opts.wrapper.data('abp-widget-manager', publicApi); |
|
|
|
|
|
|
|
return publicApi; |
|
|
|
|