/** * User: Karmaz * Date: 7/25/13 */ var PopupModule = { type: { error: "confirmErrorPopup", trash: "confirmDeletePopup", wait: "bgTaskWaitPopup" }, /** * params: * title - html for popup header (default value "Error" for 'error' type and 'Info' for others) * content - html for popup body * type: - popup icon type * 'simple' (without icon) - default, * 'error' (with error icon), * 'trash' (with trash icon), * 'wait' (with loader icon - for bg tasks) * buttonsType: 0 - alert, 1 - confirm * confirmButtonText - default value "Ok" * cancelButtonText - default value "Cancel" * confirmCallback * cancelCallback * notCloseOthers - not close other popups * useHtml - for not simple type **/ popupWithButtons:function (params) { var content = $($('#confirmPopup').clone()) var contentBody = $('.jsPopupBody', content) var type = params.type || "simple"; if (!PopupModule.type.hasOwnProperty(type)) type = "simple"; type = type.toLowerCase() if (type == "simple") { $('.jsConfirmMsg', contentBody).remove(); contentBody.append(params.content); } else { contentBody.addClass(PopupModule.type[type]); var msg = contentBody.find('.jsConfirmMsg'); params.useHtml ? msg.html(params.content) : msg.text(params.content); } params.confirmButtonText && content.find('.jsConfirmOk').text(params.confirmButtonText); if (!params.buttonsType) content.find('.jsClose').hide() //alert else params.cancelButtonText && content.find('.jsClose').text(params.cancelButtonText) //confirm var onKeyDown = function (event) { if (event.which == 13) { if (params.buttonsType) params.confirmCallback && params.confirmCallback() popup.closePopup() } } var closeCallback = function () { params.cancelCallback && params.cancelCallback() $('body').unbind('keydown', onKeyDown) } var title = params.title || (params.type == 'error' ? $('.jsErrorDefaultTitle').val() : $('.jsInfoDefaultTitle').val()) var popup = PopupModule.popup({title:title, element:content, afterClose:closeCallback, closeOnClickOnOutsideArea:true, notCloseOthers:params.notCloseOthers}) if (!params.buttonsType) { // alert $('.jsConfirmOk', popup).click(popup.closePopup) } else { //confirm $('.jsConfirmOk', popup).click(function() { params.confirmCallback && params.confirmCallback(); popup.closePopup() }); } $(window).resize(popup.calculatePosition) $('body').keydown(onKeyDown) return popup; }, popup:function (params) { if (!params.notCloseOthers) { $('.p_window').remove() $('.p_overlay').remove() } var closeText = params.closeButton !== false ? "" : "" var popup = $('