/*
 |--------------------------------------------------------------------------
 | SkyCaiji (蓝天采集器)
 |--------------------------------------------------------------------------
 | Copyright (c) 2018 https://www.skycaiji.com All rights reserved.
 |--------------------------------------------------------------------------
 | 使用协议  https://www.skycaiji.com/licenses
 |--------------------------------------------------------------------------
 */
'use strict';function SettingClass(){this.caijiForm='#form_set';this.downImgForm='#form_set';this.downFileForm='#form_set';this.pageRenderForm='#form_set';this.transForm='#form_set';this.siteForm='#form_set';this.emailForm='#form_set';this.storeForm='#form_set'}
SettingClass.prototype={constructor:SettingClass,caiji_init:function(caijiConfig){var $_o=this;caijiConfig=caijiConfig?caijiConfig:{};$($_o.caijiForm+' [name="auto"]').bind('click',function(){if($(this).val()>0){$('#set_caiji_run').show()}else{$('#set_caiji_run').hide()}});$($_o.caijiForm+' [name="run"]').bind('change',function(){$('#set_caiji_run .help-block').hide();$('#set_caiji_run .run-'+$(this).val()).show()});$($_o.caijiForm+' [name="api"]').bind('click',function(){if($(this).val()>0){$('#set_caiji_api').show()}else{$('#set_caiji_api').hide()}});$($_o.caijiForm+' [name="server"]').bind('change',function(){var srvVal=$(this).val();srvVal=srvVal?srvVal:'';$('#set_caiji_server [data-server]').hide();$('#set_caiji_server [data-server="'+srvVal+'"]').show()});$('#btn_test_php').bind('click',function(){ajax_check_userpwd({type:'POST',dataType:'json',url:ulink('setting/test_php'),data:{php:$($_o.caijiForm+' [name="server_php"]').val()},beforeSend:function(){$('#btn_test_php').text('测试中...').attr('disabled',!0)},success:function(data){if(data.code==1){toastr.success(data.msg)}else{toastr.error(data.msg)}},complete:function(){$('#btn_test_php').text('测试').removeAttr('disabled')}})});$('#btn_test_swoole_php').bind('click',function(){ajax_check_userpwd({type:'POST',dataType:'json',url:ulink('setting/test_swoole_php'),data:{php:$($_o.caijiForm+' [name="swoole_php"]').val()},beforeSend:function(){$('#btn_test_swoole_php').text('测试中...').attr('disabled',!0)},success:function(data){if(data.code==1){toastr.success(data.msg)}else{toastr.error(data.msg)}},complete:function(){$('#btn_test_swoole_php').text('测试').removeAttr('disabled')}})});$('#test_swoole_restart button').bind('click',function(){ajax_check_userpwd({type:'POST',dataType:'json',url:ulink('setting/restart_swoole'),beforeSend:function(){$('#test_swoole_restart button').text('重启中...').attr('disabled',!0)},success:function(data){ajaxDataMsg(data)},complete:function(){$('#test_swoole_restart button').text('重启').removeAttr('disabled')}})});$($_o.caijiForm).bind('submit',function(){var formObj=$(this);var settings=getFormAjaxSettings(formObj);settings.complete=function(){formObj.find('button[type="submit"]').removeAttr('disabled')};ajax_check_userpwd(settings);return!1});for(var i in caijiConfig){var obj=$($_o.caijiForm+' [name="'+i+'"]');if(!obj.is('input:radio')){obj.val(caijiConfig[i])}}
$($_o.caijiForm+' [name="robots"][value="'+toInt(caijiConfig.robots)+'"]').prop('checked',!0);$($_o.caijiForm+' [name="auto"][value="'+toInt(caijiConfig.auto)+'"]').trigger("click");$($_o.caijiForm+' [name="run"]').val(caijiConfig.run?caijiConfig.run:'backstage').trigger("change");$($_o.caijiForm+' [name="api"][value="'+toInt(caijiConfig.api)+'"]').trigger("click");$($_o.caijiForm+' [name="server"]').trigger("change");$($_o.caijiForm+' [name="same_url"][value="'+toInt(caijiConfig.same_url)+'"]').prop('checked',!0);$($_o.caijiForm+' [name="same_title"][value="'+toInt(caijiConfig.same_title)+'"]').prop('checked',!0);$($_o.caijiForm+' [name="same_content"][value="'+toInt(caijiConfig.same_content)+'"]').prop('checked',!0);$($_o.caijiForm+' [name="real_time"][value="'+toInt(caijiConfig.real_time)+'"]').prop('checked',!0);if(caijiConfig.server=='swoole'){$('#test_swoole_restart').show()}
ajaxOpen({dataType:'json',url:ulink('setting/caiji_check'),async:!0,success:function(data){data=data.data?data.data:{};if(data.error){if(data.server=='cli'){$('#error_server_php').html(data.error).show()}else if(data.server=='swoole'){$('#error_server_swoole').html(data.error).show()}}}})},down_img_init:function(imgConfig){var $_o=this;imgConfig=imgConfig?imgConfig:{};$($_o.downImgForm+' [name="download_img"]').bind('click',function(){if($(this).val()==1){$('.content-wrapper').removeClass('wrapper-not-enable')}else{$('.content-wrapper').addClass('wrapper-not-enable')}});$($_o.downImgForm+' [name="img_name"]').bind('change',function(){if($(this).val()=='custom'){$('#img_name_custom').show()}else{$('#img_name_custom').hide()}});globalOp.inputSelectCustom($_o.downImgForm+' [name="charset"]','charset_custom');$($_o.downImgForm).on('click','.name-custom-path a[data-val]',function(){globalOp.insertAtCaret($('[name="name_custom_path"]'),$(this).attr('data-val'))});$($_o.downImgForm+' #add_img_func').bind('click',function(){$_o.add_img_func(null)});pluginFuncOp.initHtml($_o.downImgForm+' #img_funcs');for(var i in imgConfig){var ele=$($_o.downImgForm).find('[name="'+i+'"]').eq(0);if(ele.length>0&&!ele.is('input:radio')){ele.val(imgConfig[i])}}
if(imgConfig.img_funcs){for(var i in imgConfig.img_funcs){$_o.add_img_func(imgConfig.img_funcs[i])}}
$($_o.downImgForm+' [name="download_img"][value="'+toInt(imgConfig.download_img)+'"]').trigger("click");$($_o.downImgForm+' [name="data_image"][value="'+toInt(imgConfig.data_image)+'"]').trigger("click");$($_o.downImgForm+' [name="url_real"][value="'+toInt(imgConfig.url_real)+'"]').trigger("click");$($_o.downImgForm+' [name="img_name"]').trigger("change");$($_o.downImgForm+' [name="charset"]').trigger("change");$($_o.downImgForm+' [name="img_watermark"][value="'+toInt(imgConfig.img_watermark)+'"]').trigger("click");if(imgConfig.img_wm_logo){$('#img_wm_logo_show').attr('src',window.site_config.root+imgConfig.img_wm_logo+'?'+(new Date().getTime())).show()}},add_img_func:function(funcData){var $_o=this;pluginFuncOp.addHtml({funcData:funcData,funcName:'img_funcs[{id}][func]',funcParamName:'img_funcs[{id}][func_param]',tplId:'img_tpl_func',listId:'img_funcs',funcId:'img_func_{id}'},'downloadImg')},down_file_init:function(fileConfig){var $_o=this;fileConfig=fileConfig?fileConfig:{};$($_o.downFileForm+' [name="download_file"]').bind('click',function(){if($(this).val()==1){$('.content-wrapper').removeClass('wrapper-not-enable')}else{$('.content-wrapper').addClass('wrapper-not-enable')}});$($_o.downFileForm+' [name="file_name"]').bind('change',function(){if($(this).val()=='custom'){$('#file_name_custom').show()}else{$('#file_name_custom').hide()}});globalOp.inputSelectCustom($_o.downFileForm+' [name="charset"]','charset_custom');$($_o.downFileForm).on('click','.name-custom-path a[data-val]',function(){globalOp.insertAtCaret($('[name="name_custom_path"]'),$(this).attr('data-val'))});$($_o.downFileForm+' #add_file_func').bind('click',function(){$_o.add_file_func(null)});pluginFuncOp.initHtml($_o.downFileForm+' #file_funcs');for(var i in fileConfig){var ele=$($_o.downFileForm).find('[name="'+i+'"]').eq(0);if(ele.length>0&&!ele.is('input:radio')){ele.val(fileConfig[i])}}
if(fileConfig.file_funcs){for(var i in fileConfig.file_funcs){$_o.add_file_func(fileConfig.file_funcs[i])}}
$($_o.downFileForm+' [name="download_file"][value="'+toInt(fileConfig.download_file)+'"]').trigger("click");$($_o.downFileForm+' [name="url_real"][value="'+toInt(fileConfig.url_real)+'"]').trigger("click");$($_o.downFileForm+' [name="file_name"]').trigger("change");$($_o.downFileForm+' [name="charset"]').trigger("change")},add_file_func:function(funcData){var $_o=this;pluginFuncOp.addHtml({funcData:funcData,funcName:'file_funcs[{id}][func]',funcParamName:'file_funcs[{id}][func_param]',tplId:'file_tpl_func',listId:'file_funcs',funcId:'file_func_{id}'},'downloadFile')},page_render_init:function(renderConfig){var $_o=this;renderConfig=renderConfig?renderConfig:{};$($_o.pageRenderForm+' [name="tool"]').bind('change',function(){var tool=$(this).val();$($_o.pageRenderForm+' [id^="render_tool_"]').hide();if(tool){$($_o.pageRenderForm+' #render_tool_'+tool).show()}});$($_o.pageRenderForm+' [name="chrome[server]"]').bind('click',function(){var curVal=$(this).val();curVal=curVal?curVal:'';$($_o.pageRenderForm+' [data-chrome-server]').hide();$($_o.pageRenderForm+' [data-chrome-server="'+curVal+'"]').show()});$('#btn_chrome_test').bind('click',function(){ajax_check_userpwd({type:'POST',dataType:'json',url:ulink('setting/chrome_test'),data:$($_o.pageRenderForm).serialize(),beforeSend:function(){$('#btn_chrome_test').text('测试中...').attr('disabled',!0)},success:function(data){if(data.code==1){toastr.success(data.msg)}else{var warning=!1;if(data.msg.indexOf(':WARNING')>-1){warning=!0;if(data.msg.indexOf(':ERROR')>-1){warning=!1}}
if(warning){toastr.warning(data.msg)}else{toastr.error(data.msg)}}},complete:function(){$('#btn_chrome_test').text('测试').removeAttr('disabled')}})});$($_o.pageRenderForm).bind('submit',function(){var formObj=$(this);var settings=getFormAjaxSettings(formObj);settings.complete=function(){formObj.find('button[type="submit"]').removeAttr('disabled')};ajax_check_userpwd(settings);return!1});$($_o.pageRenderForm+' [name="tool"]').val(renderConfig.tool).trigger('change');if(renderConfig.chrome){$($_o.pageRenderForm+' [name="chrome[server]"][value="'+renderConfig.chrome.server+'"]').prop('checked','checked').trigger('click')}
if(renderConfig.tool){ajaxOpen({type:'post',url:ulink("setting/page_render_status"),dataType:'html',success:function(html){$('#page_render_status').html(html);$('#btn_page_render_clear').bind('click',function(){confirmRight('该操作会导致正在渲染的页面丢失，确定清理？',function(){windowModal('正在清理...',ulink('setting/page_render_clear'))})});$('#btn_page_render_restart').bind('click',function(){confirmRight('该操作会导致正在渲染的页面丢失，确定重启？',function(){windowModal('正在重启...',ulink('setting/page_render_restart'))})});$('#btn_page_render_api').bind('click',function(){windowModal('API接口',ulink('setting/page_render_api'))})}})}},translate_init:function(transConfig){var $_o=this;transConfig=transConfig?transConfig:{};$($_o.transForm+' [name="open"]').bind('click',function(){if($(this).val()==1){$('.content-wrapper').removeClass('wrapper-not-enable')}else{$('.content-wrapper').addClass('wrapper-not-enable')}});$($_o.transForm+' [name="api"]').bind('change',function(){$('[id^="api_"]').hide();$('#api_'+$(this).val()).show()});$($_o.transForm+' [name="open"][value="'+toInt(transConfig.open)+'"]').trigger('click');$($_o.transForm+' [name="api"]').val(transConfig.api).trigger("change");$($_o.transForm+' [name="pass_html"][value="'+toInt(transConfig.pass_html)+'"]').trigger('click')},site_init:function(siteConfig){var $_o=this;siteConfig=siteConfig?siteConfig:{};siteConfig.login=siteConfig.login?siteConfig.login:{};$($_o.siteForm+' [name="verifycode"]').bind('click',function(){if($(this).val()==1){$('#verifycode_len').show()}else{$('#verifycode_len').hide()}});$($_o.siteForm+' [name="login[limit]"]').bind('click',function(){if($(this).val()==1){$('#login_limit').show()}else{$('#login_limit').hide()}});$($_o.siteForm+' #btn_timezone').bind('click',function(){var nowTime=new Date();var offset=nowTime.getTimezoneOffset()/60;ajaxOpen({type:'post',url:ulink("setting/site_timezone"),data:{time:nowTime.getTime(),offset:offset},dataType:'json',success:function(data){if(data.code==1){if(data.data&&data.data.timezone){if($($_o.siteForm+' [name="timezone"]').find('option[value="'+data.data.timezone+'"]').length>0){$($_o.siteForm+' [name="timezone"]').val(data.data.timezone)}else{toastr.error('自动调整失败，请手动选择！')}}}else{if(data.msg){toastr.error(data.msg)}}}})});$($_o.siteForm+' [name="verifycode"][value="'+toInt(siteConfig.verifycode)+'"]').prop('checked','checked').trigger('click');$($_o.siteForm+' [name="hidehome"][value="'+toInt(siteConfig.hidehome)+'"]').prop('checked','checked');$($_o.siteForm+' [name="closelog"][value="'+toInt(siteConfig.closelog)+'"]').prop('checked','checked');$($_o.siteForm+' [name="dblong"][value="'+toInt(siteConfig.dblong)+'"]').prop('checked','checked');$($_o.siteForm+' [name="login[limit]"][value="'+toInt(siteConfig.login.limit)+'"]').prop('checked','checked').trigger('click');$($_o.siteForm+' [name="closetrans"][value="'+toInt(siteConfig.closetrans)+'"]').prop('checked','checked');$($_o.siteForm+' [name="timezone"]').val(siteConfig.timezone)},email_init:function(emailConfig){var $_o=this;emailConfig=emailConfig?emailConfig:{};$('#btn_test').bind('click',function(){$($_o.emailForm+' [name="is_test"]').val(1);$($_o.emailForm).submit()});$($_o.emailForm+' button[type="submit"]').bind('click',function(){$($_o.emailForm+' [name="is_test"]').val(0)});$($_o.emailForm).bind('submit',function(){var settings=getFormAjaxSettings($(this));var isTest=$($_o.emailForm+' [name="is_test"]').val();if(isTest>0){$('#btn_test').html('正在测试...');$('#btn_test').attr('disabled',!0);settings.complete=function(){$('#btn_test').html('测试').attr('disabled',!1)}}
ajaxOpen(settings);return!1});$($_o.emailForm+' [name="caiji[open]"]').bind('click',function(){if($(this).val()==1){$('#caiji_open').show()}else{$('#caiji_open').hide()}});$($_o.emailForm+' [name="type"][value="'+emailConfig.type+'"]').prop('checked','checked');var caiji=emailConfig.caiji;if(caiji){$($_o.emailForm+' [name="caiji[open]"][value="'+toInt(caiji.open)+'"]').prop('checked',!0).trigger('click');$($_o.emailForm+' [name="caiji[is_auto]"][value="'+toInt(caiji.is_auto)+'"]').prop('checked',!0);$($_o.emailForm+' [name="caiji[failed_interval]"]').val(toInt(caiji.failed_interval));$($_o.emailForm+' [name="caiji[failed_num]"]').val(toInt(caiji.failed_num));$($_o.emailForm+' [name="caiji[report_interval]"]').val(toInt(caiji.report_interval));$($_o.emailForm+' [name="caiji[email]"]').val(caiji.email)}},store_init:function(storeConfig){var $_o=this;storeConfig=storeConfig?storeConfig:{};$($_o.storeForm).bind('submit',function(){var obj=$(this);ajaxOpen({type:'post',url:obj.attr('action'),dataType:'json',data:obj.serialize(),success:function(data){if(data.code==1){ajaxDataMsg(data)}else{if(data.msg){toastr.error(data.msg)}
var data=data.data;if(data&&data.same_as_pwd){confirmRight(data.same_as_pwd,function(){obj.find('[name="same_as_pwd"]').val(1);obj.trigger('submit')})}}}});return!1});$('#provider_authkeys_iframe').bind('load',function(){var mainheight=$(this).contents().find('body').height()+1;$(this).height(mainheight)})}}
var settingClass=new SettingClass()