/*
 |--------------------------------------------------------------------------
 | SkyCaiji (蓝天采集器)
 |--------------------------------------------------------------------------
 | Copyright (c) 2018 https://www.skycaiji.com All rights reserved.
 |--------------------------------------------------------------------------
 | 使用协议  https://www.skycaiji.com/licenses
 |--------------------------------------------------------------------------
 */
'use strict';function CollectorPattern(){this.formid='#form_coll';this.cpFrontUrl=null;this.cpLevelUrl=null;this.cpRelationUrl=null;this.cpUrlWeb=null;this.cpRenderer=null;this.cpContentSign=null;this.cpPagination=null;this.cpField=null;this.cpProcess=null}
CollectorPattern.prototype={constructor:CollectorPattern,init:function(){var $_o=this;$($_o.formid).bind('submit',function(){$('#coll_tab_content').find('.tab-pane[id^="coll_pattern_"]').each(function(){if($(this).hasClass('active')){$($_o.formid+' [name="tab_link"]').val($(this).attr('id'));return}});var settings=getFormAjaxSettings($(this));settings.data={'_post_data_':settings.data};ajaxOpen(settings);return!1});$_o.cpFrontUrl=new CpFrontUrl($_o);$_o.cpLevelUrl=new CpLevelUrl($_o);$_o.cpRelationUrl=new CpRelationUrl($_o);$_o.cpUrlWeb=new CpUrlWeb($_o);$_o.cpRenderer=new CpRenderer($_o);$_o.cpContentSign=new CpContentSign($_o);$_o.cpPagination=new CpPagination($_o);$_o.cpField=new CpField($_o);$_o.cpProcess=new CpProcess($_o);globalOp.inputSelectCustom($_o.formid+' select[name="config[charset]"]','config[charset_custom]',null,null,function(){$_o.cpUrlWeb.def_config_charset('')});globalOp.inputSelectCustom($_o.formid+' select[name="config[encode]"]','config[encode_custom]',null,null,function(){$_o.cpUrlWeb.def_config_encode('')});$($_o.formid+' [name="config[page_render]"]').bind('click',function(){$_o.cpRenderer.def_config_renderer_open('')});$($_o.formid+' [name="config[request_headers][open]"]').bind('click',function(){$_o.cpUrlWeb.def_config_header_global('')});$($_o.formid+' #coll_pattern_request_headers .dm-useragent li a').bind('click',function(){$($_o.formid+' [name="config[request_headers][useragent]"]').val($(this).attr('data-useragent'))});$($_o.formid+' #coll_pattern_request_headers .add-request-header').bind('click',function(){$_o.add_request_header('','')});$($_o.formid+' #coll_pattern_request_headers .add-request-header-img').bind('click',function(){$_o.add_request_header_img('','')});$($_o.formid+' #coll_pattern_request_headers .add-request-header-file').bind('click',function(){$_o.add_request_header_file('','')});$($_o.formid+' .c-p-request-headers').on('click','.delete-request-header',function(){var curObj=$(this);confirmRight('确定删除？',function(){curObj.parents('tr').eq(0).remove()})});$($_o.formid+' .c-p-request-headers-img').on('click','.delete-request-header-img',function(){var curObj=$(this);confirmRight('确定删除？',function(){curObj.parents('tr').eq(0).remove()})});$($_o.formid+' .c-p-request-headers-file').on('click','.delete-request-header-file',function(){var curObj=$(this);confirmRight('确定删除？',function(){curObj.parents('tr').eq(0).remove()})});$_o.init_page_list_op('front_url');$(this.formid+' #coll_pattern_source_url .add-source-url').bind('click',function(){windowModal('添加起始网址',ulink("cpattern/source"),{lg:1})});$(this.formid+' #coll_pattern_source_url .clear-source-url').bind('click',function(){$_o.source_op('clear_all')});$(this.formid+' #coll_pattern_source_url').on('click','.edit-source-url',function(){var parent=$(this).parents('[id^="source_url_"]').eq(0);var objid=parent.attr('id');var sourceUrl=parent.find('[name="config[source_url][]"]').val();sourceUrl=sourceUrl?sourceUrl:'';var url=ulink("cpattern/source");var options={lg:1};if(objid||sourceUrl){options.ajax={type:'post',data:{'source_url':sourceUrl,'objid':objid}}}
windowModal('添加起始网址',url,options)});$(this.formid+' #coll_pattern_source_url').on('click','.delete-source-url',function(){var obj=$(this);confirmRight(window.tpl_lang.confirm_delete,function(){obj.parents('[id^="source_url_"]').eq(0).remove()})});globalOp.eleExchange(this.formid+' #coll_pattern_source_url','.icon-drag-move','[id^="source_url_"]');$(this.formid+' [name="config[source_is_url]"]').bind('click',function(){if($_o.source_is_url()){$('#coll_pattern_source_url').css('margin-bottom','0px');$('#alert_coll_pattern_link').show();$('#panel_coll_pattern_source_url_web').hide();$('#panel_coll_pattern_source_url_renderer').hide();$('#panel_coll_pattern_source_url_content_sign').hide();$('#panel_coll_pattern_source_url_pagination').hide();$('#panel_coll_pattern_level_url').hide();$('#panel_coll_pattern_url_content_sign').siblings('.panel').hide();$('#panel_coll_pattern_url_web').show();$('#panel_coll_pattern_url_renderer').show()}else{$('#coll_pattern_source_url').css('margin-bottom','15px');$('#alert_coll_pattern_link').hide();$('#panel_coll_pattern_source_url_web').show();$('#panel_coll_pattern_source_url_renderer').show();$('#panel_coll_pattern_source_url_content_sign').show();$('#panel_coll_pattern_source_url_pagination').show();$('#panel_coll_pattern_level_url').show();$('#panel_coll_pattern_url_content_sign').siblings('.panel').show()}});$_o.init_page('source_url');$_o.init_page('url');$($_o.formid).on('click','.c-p-url-page-signs .btn-page-signs',function(){$_o.parent_page_signs(this)});$_o.init_page_list_op('level_url');$_o.init_page_list_op('relation_url');$(this.formid+' #coll_pattern_field').on('click','.add-field',function(){$_o.field_editor(null,null)});$(this.formid+' #coll_pattern_field').on('click','.field-name',function(){$_o.field_editor($(this),null)});$(this.formid+' #coll_pattern_field').on('click','.add-field-default',function(){$_o.cpField.add_default()});$(this.formid+' #coll_pattern_field').on('click','.sort-field',function(){var fieldNames=$_o.get_field_names(!0);for(var i in fieldNames){var fieldTr=$($_o.formid+' #coll_pattern_field').find('.field-name[data-val="'+fieldNames[i]+'"]').parents('tr[id^="field_"]').eq(0);if(fieldTr.length>0){$($_o.formid+' #coll_pattern_field .c-p-field-list tbody').append(fieldTr)}}
toastr.success('调整完成')});$(this.formid+' #coll_pattern_field').on('click','.field-del',function(){var obj=$(this);confirmRight(window.tpl_lang.confirm_delete,function(){$_o.field_delete_tr(obj)})});$(this.formid+' #coll_pattern_field').on('click','.field-clone',function(){var tr=$(this).parents('tr[id^="field_"]').eq(0);var field=tr.find('[name="config[field_list][]"]').val();var process=tr.find('[name="config[field_process][]"]').val();confirmRight('确定复制字段？',function(){ajaxOpen({type:'POST',dataType:'json',url:ulink("cpattern/clone_field"),data:{field:field,process:process},success:function(data){if(data.code==1){data=data.data;var hasField=!1;do{data.field.name+='_1';hasField=$('#coll_pattern_field .c-p-field-list').find('.field-name[data-val="'+data.field.name+'"]');if(hasField&&hasField.length>0){hasField=!0}else{hasField=!1}}while(hasField);$_o.cpField.add(null,data.field,data.process);toastr.success('字段复制成功：'+data.field.name)}else{toastr.error(data.msg)}}})})});$(this.formid+' #coll_pattern_field').on('click','.field-process',function(){var process=$(this).parent().find('input[name="config[field_process][]"]').val();var prt=$(this).parents('tr[id^="field_"]').eq(0);var objid=prt.attr('id');var field=prt.find('.field-name').attr('data-val');var url=ulink("cpattern/process?task_id=_tid_&field=_field_",{'_tid_':$_o.get_task_id(),'_field_':field});windowModal('数据处理：'+field+'<small><a href="javascript:;" id="window_process_paste" title="粘贴" class="glyphicon glyphicon-paste" style="margin-left:7px;color:#888;"></a></small>',url,{lg:1,ajax:{type:'post',data:{objid:objid,process:process}}});$_o.process_paste()});$(this.formid+' #coll_pattern_process').on('click','.add-process',function(){var url=ulink("cpattern/process?task_id=_tid_&type=common",{'_tid_':$_o.get_task_id()});windowModal('数据处理（通用）<small><a href="javascript:;" id="window_process_paste" title="粘贴" class="glyphicon glyphicon-paste" style="color:#888;"></a></small>',url,{lg:1});$_o.process_paste()});globalOp.eleExchange(this.formid+' #coll_pattern_field','.icon-drag-move','tr[id^="field_"]');$(this.formid+' [name="effective"]').val(1)},init_test:function(){var $_o=this;$_o.formid='#win_form_cache';$_o.cpUrlWeb=new CpUrlWeb($_o);$_o.cpRenderer=new CpRenderer($_o);$_o.cpUrlWeb.page_init('test');$_o.cpRenderer.page_init('test')},init_echo_url_msg:function(dataUrlWeb,dataRenderer){this.init_test();if(!isObject(dataUrlWeb)){dataUrlWeb={}}
if(!isObject(dataRenderer)){dataRenderer={}}
var hasUrlWeb=!1;for(var i in dataUrlWeb){hasUrlWeb=!0}
var hasRenderer=!1;for(var i in dataRenderer){hasRenderer=!0}
this.cpUrlWeb.page_load('test',dataUrlWeb);this.cpRenderer.page_load('test',dataRenderer);var urlWebForm=$('.c-p-url-web-form').parents('.form-group').eq(0);var urlWebBox=urlWebForm.parents('.panel[id]').eq(0);if(hasUrlWeb){urlWebBox=urlWebBox.find('.panel-body').eq(0);urlWebBox.html(urlWebForm)}else{urlWebBox.hide()}
var rendererList=$('.c-p-url-renderer-list').parents('.form-group').eq(0);var rendererBox=rendererList.parents('.panel[id]').eq(0);if(hasRenderer){rendererBox=rendererBox.find('.panel-body').eq(0);rendererBox.html(rendererList)}else{rendererBox.hide()}},load:function(config){var $_o=this;if(config){$(this.formid+' [name="config[charset_custom]"]').val(config.charset_custom);$(this.formid+' [name="config[charset]"]').val(config.charset).trigger('change');$(this.formid+' [name="config[encode_custom]"]').val(config.encode_custom);$(this.formid+' [name="config[encode]"]').val(config.encode).trigger('change');$(this.formid+' [name="config[url_complete]"][value="'+toInt(config.url_complete)+'"]').prop('checked',!0);$(this.formid+' [name="config[url_order]"][value="'+config.url_order+'"]').prop('checked',!0);$(this.formid+' [name="config[page_render]"][value="'+toInt(config.page_render)+'"]').prop('checked',!0).trigger('click');$(this.formid+' [name="config[url_repeat]"][value="'+toInt(config.url_repeat)+'"]').prop('checked',!0);$(this.formid+' [name="config[url_no_name]"][value="'+toInt(config.url_no_name)+'"]').prop('checked',!0);$(this.formid+' [name="config[url_encode]"][value="'+toInt(config.url_encode)+'"]').prop('checked',!0);if(config.regexp_flags){for(var i in config.regexp_flags){$(this.formid).find('[name="config[regexp_flags][]"][value="'+config.regexp_flags[i]+'"]').prop('checked',!0)}}
if(isObject(config.front_urls)){for(var i in config.front_urls){$_o.cpFrontUrl.add(null,config.front_urls[i])}
globalOp.showPanelCollapse('#coll_pattern_front_url')}
if(config.source_url){var source_url_html_list='';var sourceParams={get:1};for(var i in config.source_url){sourceParams.source_url=config.source_url[i];source_url_html_list+=this.source_op('add',sourceParams)}
if(source_url_html_list){this.source_op('add',{html:source_url_html_list})}}
if(config.source_is_url){$($_o.formid+' [name="config[source_is_url]"]').prop('checked',!1).trigger('click')}
if(config.source_config){$_o.load_page('source_url',config.source_config)}
$_o.load_page('url',config);if(isObject(config.level_urls)){for(var i in config.level_urls){$_o.cpLevelUrl.add(null,config.level_urls[i])}
globalOp.showPanelCollapse('#coll_pattern_level_url')}
if(isObject(config.relation_urls)){for(var i in config.relation_urls){$_o.cpRelationUrl.add(null,config.relation_urls[i])}
globalOp.showPanelCollapse('#coll_pattern_relation_url')}
if(config.field_list&&config.field_list.length>0){this.cpField.clearall();for(var i in config.field_list){var fieldProcess=null;if(config.field_process){fieldProcess=config.field_process[i]}
this.cpField.add(null,config.field_list[i],fieldProcess)}}
if(config.field_title){$(this.formid+' [name="config[field_title]"]').each(function(){if($(this).val()==config.field_title){$(this).prop('checked',!0)}})}
if(config.field_content&&isObject(config.field_content)){for(var i in config.field_content){$(this.formid+' [name="config[field_content][]"][value="'+config.field_content[i]+'"]').prop('checked',!0)}}
if(config.common_process&&config.common_process.length>0){globalOp.showPanelCollapse('#coll_pattern_process');ajaxOpen({type:'post',url:ulink("cpattern/process?task_id=_tid_&type=common&op=load",{'_tid_':$_o.get_task_id()}),data:{process:config.common_process},dataType:'html',beforeSend:function(){$($_o.cpProcess.processForm+' .c-p-process-accordion').append('<div class="loading" style="margin:5px 0 0 -5px;"></div>')},success:function(data){$('body').append(data)},complete:function(){$($_o.cpProcess.processForm+' .c-p-process-accordion').find('.loading').remove()}})}
if(config.request_headers){$(this.formid+' [name="config[request_headers][useragent]"]').val(config.request_headers.useragent);$(this.formid+' [name="config[request_headers][cookie]"]').val(config.request_headers.cookie);$(this.formid+' [name="config[request_headers][referer]"]').val(config.request_headers.referer);if(config.request_headers.custom_names){var r_h_vals=config.request_headers.custom_vals?config.request_headers.custom_vals:{};for(var i in config.request_headers.custom_names){$_o.add_request_header(config.request_headers.custom_names[i],r_h_vals[i])}}
config.request_headers.open=toInt(config.request_headers.open);config.request_headers.img=toInt(config.request_headers.img);config.request_headers.file=toInt(config.request_headers.file);$(this.formid+' [name="config[request_headers][open]"][value="'+config.request_headers.open+'"]').prop('checked',!0).trigger('click');$(this.formid+' [name="config[request_headers][img]"][value="'+config.request_headers.img+'"]').prop('checked',!0);$(this.formid+' [name="config[request_headers][img_use_page]"][value="'+config.request_headers.img_use_page+'"]').prop('checked',!0);$(this.formid+' [name="config[request_headers][file]"][value="'+config.request_headers.file+'"]').prop('checked',!0);$(this.formid+' [name="config[request_headers][file_use_page]"][value="'+config.request_headers.file_use_page+'"]').prop('checked',!0);if(config.request_headers.open>0){globalOp.showPanelCollapse('#coll_pattern_request_headers');globalOp.showPanelCollapse('#c_p_request_headers_open')}
if(config.request_headers.img>0){globalOp.showPanelCollapse('#coll_pattern_request_headers');globalOp.showPanelCollapse('#c_p_request_headers_img')}
if(config.request_headers.img_names){var r_h_img_vals=config.request_headers.img_vals?config.request_headers.img_vals:{};for(var i in config.request_headers.img_names){$_o.add_request_header_img(config.request_headers.img_names[i],r_h_img_vals[i])}}
if(config.request_headers.file>0){globalOp.showPanelCollapse('#coll_pattern_request_headers');globalOp.showPanelCollapse('#c_p_request_headers_file')}
if(config.request_headers.file_names){var r_h_file_vals=config.request_headers.file_vals?config.request_headers.file_vals:{};for(var i in config.request_headers.file_names){$_o.add_request_header_file(config.request_headers.file_names[i],r_h_file_vals[i])}}}}
$(this.formid+' [name="effective_edit"]').val(1)},get_page_vars:function(pageType,returnKey,isPagination){var title='';var boxId='';var namePre='';var formId='';if('front_url'==pageType){title='前置页';boxId='#c_p_front_url';namePre='front_url';formId=this.cpFrontUrl.formObj}else if('source_url'==pageType){title='起始页';boxId='#coll_pattern_source_url';namePre='config[source_config]';formId=this.formid}else if('level_url'==pageType){title='多级页';boxId='#c_p_level_url';namePre='level_url';formId=this.cpLevelUrl.formObj}else if('relation_url'==pageType){title='关联页';boxId='#c_p_relation_url';namePre='relation_url';formId=this.cpRelationUrl.formObj}else if('url'==pageType){title='内容页';boxId='#coll_pattern_url';namePre='config';formId=this.formid}else if('test'==pageType){title='';boxId='#win_coll_pattern_test';namePre='config';formId='#win_form_test'}
if(isPagination){boxId+='_pagination';namePre+='[pagination]'}
var data={title:title,boxId:boxId,namePre:namePre,formId:formId};if(returnKey){return data[returnKey]}else{return data}},page_is_list:function(pageType){if(pageType=='front_url'||pageType=='level_url'||pageType=='relation_url'){return!0}else{return!1}},init_page_list_op:function(pageType){var $_o=this;if(!$_o.page_is_list(pageType)){return}
var pageVars=$_o.get_page_vars(pageType);var listObj='#c_p_'+pageType+'s';var parentObj='[id^="'+pageType+'_"]';$($_o.formid+' #coll_pattern_'+pageType+' .add-'+pageType.replace('_','-')).bind('click',function(){var url=ulink('cpattern/'+pageType);windowModal('添加'+pageVars.title+'规则',url,{lg:1})});$($_o.formid+' '+listObj).on('click','.name',function(){var parent=$(this).parents(parentObj).eq(0);var options={lg:1,ajax:{type:'post',data:{}}};options.ajax.data.objid=parent.attr('id');options.ajax.data[pageType]=parent.find('[name="config['+pageType+'s][]"]').val();windowModal('编辑'+pageVars.title+'规则',ulink('cpattern/'+pageType),options)});$($_o.formid+' '+listObj).on('click','.clone',function(){var parent=$(this).parents(parentObj).eq(0);var pageConfig=parent.find('[name="config['+pageType+'s][]"]').val();var postData={};postData[pageType]=pageConfig;confirmRight('确定复制'+pageVars.title+'？',function(){ajaxOpen({type:'POST',dataType:'json',url:ulink('cpattern/clone_'+pageType),data:postData,success:function(data){if(data.code==1){data=data.data;var hasName=!1;do{data[pageType].name+='_1';hasName=$($_o.formid+' '+listObj).find('.name[data-val="'+data[pageType].name+'"]');if(hasName&&hasName.length>0){hasName=!0}else{hasName=!1}}while(hasName);if(pageType=='front_url'){$_o.cpFrontUrl.add(null,data[pageType])}else if(pageType=='level_url'){$_o.cpLevelUrl.add(null,data[pageType])}else if(pageType=='relation_url'){$_o.cpRelationUrl.add(null,data[pageType])}
toastr.success(pageVars.title+'复制成功：'+data[pageType].name)}else{toastr.error(data.msg)}}})})});$($_o.formid+' '+listObj).on('click','.delete',function(){var curObj=$(this);confirmRight('确定删除？',function(){curObj.parents(parentObj).eq(0).remove()})});globalOp.eleExchange($_o.formid+' '+listObj,'.icon-drag-move','tbody tr')},init_page:function(pageType){var $_o=this;var pageVars=$_o.get_page_vars(pageType);var formId=pageVars.formId;var boxId=pageVars.boxId;var namePre=pageVars.namePre;if(!formId||!boxId||!namePre){return}
$(formId+' select[name="'+namePre+'[area_module]"],select[name="'+namePre+'[url_rule_module]"]').bind('click',function(){$_o.rule_module_slt(this)});$_o.cpUrlWeb.page_init(pageType);$_o.cpRenderer.page_init(pageType);$_o.cpContentSign.page_init(pageType);$_o.cpPagination.page_init(pageType)},load_page_rule:function(pageType,config,isPagination){var $_o=this;var pageVars=$_o.get_page_vars(pageType);var formId=pageVars.formId;var boxId=pageVars.boxId;var namePre=pageVars.namePre;if(!config||!formId||!boxId||!namePre){return}
if(isPagination){boxId+='_pagination';namePre+='[pagination]';var configNum=config.number;if(isObject(configNum)){for(var i in configNum){configNum[i]=toInt(configNum[i]);var configNumObj=formId+' [name="'+namePre+'[number]['+i+']"]';if(i=='open'){$(configNumObj+'[value="'+configNum[i]+'"]').prop('checked',!0);if(configNum[i]>0){globalOp.showPanelCollapse(boxId+'_no')}}else if(i=='desc'){$(configNumObj).prop('checked',configNum[i]?true:!1)}else{$(configNumObj).val(configNum[i]?configNum[i]:'')}}}}
if(config.area||config.area_merge){$(formId+' [name="'+namePre+'[area]"]').val(config.area);$(formId+' [name="'+namePre+'[area_merge]"]').val(config.area_merge);globalOp.showPanelCollapse(boxId+'_area')}
if(config.area_module){$(formId+' select[name="'+namePre+'[area_module]"]').val(config.area_module).trigger('click').trigger('change')}
if(config.url_rule||config.url_merge){$(formId+' [name="'+namePre+'[url_rule]"]').val(config.url_rule);$(formId+' [name="'+namePre+'[url_merge]"]').val(config.url_merge);globalOp.showPanelCollapse(boxId+'_url')}
if(config.url_rule_module){$(formId+' select[name="'+namePre+'[url_rule_module]"]').val(config.url_rule_module).trigger('click').trigger('change')}
if(config.url_must||config.url_ban){$(formId+' [name="'+namePre+'[url_must]"]').val(config.url_must);$(formId+' [name="'+namePre+'[url_ban]"]').val(config.url_ban);globalOp.showPanelCollapse(boxId+'_filter')}},load_page:function(pageType,config){var $_o=this;var pageVars=$_o.get_page_vars(pageType);var formId=pageVars.formId;var boxId=pageVars.boxId;var namePre=pageVars.namePre;if(!config||!formId||!boxId||!namePre){return}
if(pageType=='level_url'||pageType=='url'||pageType=='relation_url'){$_o.load_page_rule(pageType,config,!1)}
$_o.cpUrlWeb.page_load(pageType,config.url_web);$_o.cpRenderer.page_load(pageType,config.renderer);$_o.cpContentSign.page_load(pageType,config.content_signs);$_o.cpPagination.page_load(pageType,config.pagination)},source_is_url:function(){var isUrl=$(this.formid+' [name="config[source_is_url]"]').is(':checked');isUrl=isUrl?1:'';return isUrl},source_op:function(op,params){var $_o=this;params=params?params:{};var formObj=params.formObj?params.formObj:'#form_source';if(op=='init'){$(formObj+' #source_url_sign').bind('click',function(){var sign=window.tpl_lang.sign_match.replace('{:id}','');var ipt=$('#source_url');if(ipt.val().indexOf(sign)<0){globalOp.insertAtCaret(ipt,sign)}else{toastr.error('存在'+sign)}});$(formObj).find('.nav-tabs li a').bind('click',function(){$(formObj).find('input[name="source[type]"]').val($(this).attr('source-type'))});$(formObj).find('div[source-param]').find('input,textarea').bind('change',function(){if($(this).attr("type")=='radio'){return!1}
$(this).parents('div[source-param]').find('input[name="source[param]"]').prop('checked',!0)});if(params.source){$(formObj+' .nav-tabs').find('a[source-type="'+params.source.type+'"]').click();if(params.source.type=='custom'){$(formObj+' textarea[name="source[urls]"]').val(params.source.urls)}else if(params.source.type=='batch'){$(formObj+' input[name="source[url]"]').val(params.source.url);var param_type=params.source.param;if(param_type=='num'){$(formObj+' input[name="source[param_num_start]"]').val(params.source.param_num_start);$(formObj+' input[name="source[param_num_end]"]').val(params.source.param_num_end);$(formObj+' input[name="source[param_num_inc]"]').val(params.source.param_num_inc);if(params.source.param_num_desc){$(formObj+' input[name="source[param_num_desc]"]').prop('checked',!0)}
if(params.source.param_num_len){$(formObj+' input[name="source[param_num_len]"]').val(params.source.param_num_len)}}else if(param_type=='letter'){$(formObj+' input[name="source[param_letter_start]"]').val(params.source.param_letter_start);$(formObj+' input[name="source[param_letter_end]"]').val(params.source.param_letter_end);if(params.source.param_letter_desc){$(formObj+' input[name="source[param_letter_desc]"]').prop('checked',!0)}}else if(param_type=='custom'){$(formObj+' textarea[name="source[param_custom]"]').val(params.source.param_custom)}
$(formObj+' input[name="source[param]"][value="'+param_type+'"]').prop('checked',!0)}else if(params.source.type=='large'){$(formObj+' textarea[name="source[large_urls]"]').val(params.source.large_urls)}else if(params.source.type=='api'){$(formObj+' input[name="source[api]"]').val(params.source.api);$(formObj+' input[name="source[api_json]"]').val(params.source.api_json)}}}else if(op=='add'){var html='';if(params.html){html=params.html}else{var htmlObj=$_o.clone_tpl('#coll_tpl_source_url');htmlObj.find('[data-id="source_url_"]').attr('id','source_url_'+generateUUID()).removeAttr('data-id');var regLarge=/[\r\n]/;if(regLarge.test(params.source_url)){htmlObj.find('input[name="config[source_url][]"]').remove()}else{htmlObj.find('textarea[name="config[source_url][]"]').remove()}
html=htmlObj.html();html=html?html:'';html=html.replace('[_source_url_]',htmlspecialchars(params.source_url))}
if(params.get){return html}else{this.source_op('clear_null');$($_o.formid+' #coll_pattern_source_url .c-p-source-urls').append(html)}}else if(op=='add_sub'){ajaxOpen({type:'POST',dataType:'json',url:$(formObj).attr('action'),data:$(formObj).serialize(),success:function(data){var dataList=data.data?data.data:{};var objid=dataList.objid?dataList.objid:'';var addParams={};if(data.code==1){var source_type=$(formObj).find('input[name="source[type]"]').val();if(source_type=='custom'&&isObject(dataList.urls)&&dataList.urls.length>20){source_type='large'}
if(source_type=='custom'){$('#myModal').modal('hide');var urls=dataList.urls;var ix=0;var url_html_list='';for(var i in urls){addParams.get=1;addParams.source_url=urls[i];ix++;if(ix==1){if(objid){var newSource=$_o.source_op('add',addParams);$('#'+objid).replaceWith(newSource);continue}}
url_html_list+=$_o.source_op('add',addParams)}
if(url_html_list){$_o.source_op('add',{html:url_html_list})}}else if(source_type=='batch'){if(params.preview==1){var urls=dataList.urls;var txt='';for(var i in urls){txt+=urls[i]+"\r\n"}
$(formObj).find('#source_preview').val(txt)}else{if(objid){addParams.get=1;addParams.source_url=dataList.url;var newSource=$_o.source_op('add',addParams);$('#'+objid).replaceWith(newSource)}else{addParams.source_url=dataList.url;$_o.source_op('add',addParams)}
$('#myModal').modal('hide')}}else if(source_type=='large'){var large_urls=dataList.urls;large_urls=large_urls.join("\r\n");if(objid){addParams.get=1;addParams.source_url=large_urls;var newSource=$_o.source_op('add',addParams);$('#'+objid).replaceWith(newSource)}else{addParams.source_url=large_urls;$_o.source_op('add',addParams)}
$('#myModal').modal('hide')}else if(source_type=='api'){if(objid){addParams.get=1;addParams.source_url=dataList.url;var newSource=$_o.source_op('add',addParams);$('#'+objid).replaceWith(newSource)}else{addParams.source_url=dataList.url;$_o.source_op('add',addParams)}
$('#myModal').modal('hide')}}else{toastr.error(data.msg)}},error:function(data){toastr.error(data)}});return!1}else if(op=='clear_null'){$($_o.formid+' #coll_pattern_source_url').find('[name="config[source_url][]"]').each(function(){if(!$(this).val()){$(this).parents('[id^="source_url_"]').eq(0).remove()}})}else if(op=='clear_all'){confirmRight('是否清空网址？',function(){$($_o.formid+' #coll_pattern_source_url').find('[name="config[source_url][]"]').each(function(){$(this).parents('[id^="source_url_"]').eq(0).remove()})})}},page_source_options:function(setOptUrlVal){var $_o=this;var options='';var front_urls=new Array();$('#c_p_front_urls [id^="front_url_"]').each(function(){var frontName=$(this).find('.name').attr('data-val');front_urls.push('<option value="front_url:'+frontName+'">前置页：'+frontName+'</option>')});if(front_urls.length>0){options+=front_urls.join('')}
if(!$_o.source_is_url()){options+='<option value="source_url">起始页</option>';var level_urls=new Array();$('#c_p_level_urls [id^="level_url_"]').each(function(){var levelName=$(this).find('.name').attr('data-val');level_urls.push('<option value="level_url:'+levelName+'">多级页：'+levelName+'</option>')});if(level_urls.length>0){options+=level_urls.join('')}}
options+='<option value="'+(setOptUrlVal?'url':'')+'" selected="selected">内容页</option>';var relation_urls=new Array();$('#c_p_relation_urls [id^="relation_url_"]').each(function(){var relationName=$(this).find('.name').attr('data-val');relation_urls.push('<option value="relation_url:'+relationName+'">关联页：'+relationName+'</option>')});if(relation_urls.length>0){options+=relation_urls.join('')}
return options},field_delete_tr:function(subEle){$(subEle).parents('tr[id^="field_"]').eq(0).remove()},field_editor:function(subEle,hiddenFunc){var field=null;var objid=null;var title='添加字段';if(subEle){objid=$(subEle).parents('tr[id^="field_"]').eq(0).attr('id');if(objid){field=$('#'+objid).find('input[name="config[field_list][]"]').val();title='编辑字段'}}
var options={hidden_func:hiddenFunc};options.ajax={type:'post',data:{objid:objid,field:field}};windowModal(title,ulink('cpattern/field'),options)},process_paste:function(){var $_o=this;$('body').off('click','#window_process_paste').on('click','#window_process_paste',function(){ajaxOpen({type:'get',dataType:'json',url:ulink('cpattern/clone_process?op=paste'),success:function(data){if(data.code==1){$_o.cpProcess.add(data.data);toastr.success(data.msg)}else{toastr.error(data.msg)}}})})},add_request_header:function(name,val){var $_o=this;name=name?name:'';val=val?val:'';var tr=$_o.clone_tpl('#coll_tpl_request_headers');tr.find('[name="config[request_headers][custom_names][]"]').val(name);tr.find('[name="config[request_headers][custom_vals][]"]').val(val);$($_o.formid+' #coll_pattern_request_headers .c-p-request-headers tbody').append(tr)},add_request_header_img:function(name,val){var $_o=this;name=name?name:'';val=val?val:'';var tr=$_o.clone_tpl('#coll_tpl_request_headers_img');tr.find('[name="config[request_headers][img_names][]"]').val(name);tr.find('[name="config[request_headers][img_vals][]"]').val(val);$($_o.formid+' #coll_pattern_request_headers .c-p-request-headers-img tbody').append(tr)},add_request_header_file:function(name,val){var $_o=this;name=name?name:'';val=val?val:'';var tr=$_o.clone_tpl('#coll_tpl_request_headers_file');tr.find('[name="config[request_headers][file_names][]"]').val(name);tr.find('[name="config[request_headers][file_vals][]"]').val(val);$($_o.formid+' #coll_pattern_request_headers .c-p-request-headers-file tbody').append(tr)},get_field_names:function(sortField){var fields=new Array();var trs=$(this.formid+' #coll_pattern_field .c-p-field-list').find('tr[id^="field_"]');if(sortField){var fieldsNormal=new Array();var fieldsExtract=new Array();var fieldsMerge=new Array();trs.each(function(){var fmodule=$(this).find('.field-module').attr('data-val');var fname=$(this).find('.field-name').attr('data-val');if(fname){if(fmodule=='extract'){fieldsExtract.push(fname)}else if(fmodule=='merge'){fieldsMerge.push(fname)}else{fieldsNormal.push(fname)}}});for(var i in fieldsNormal){fields.push(fieldsNormal[i])}
for(var i in fieldsExtract){fields.push(fieldsExtract[i])}
for(var i in fieldsMerge){fields.push(fieldsMerge[i])}}else{trs.each(function(){var fname=$(this).find('.field-name').attr('data-val');if(fname){fields.push(fname)}})}
return fields},rule_module_slt:function(curObj){curObj=$(curObj);var module=curObj.val();if(curObj.attr('data-module-input')){var ipt=$('[name="'+curObj.attr('data-module-input')+'"]');ipt.attr('data-val-'+module,ipt.val())}
curObj.off('change').on('change',function(){var obj=$(this);var name=obj.attr('name');var changeModule=obj.val();$('[data-module-select="'+name+'"]').find('[data-module]').hide();$('[data-module-select="'+name+'"]').find('[data-module="'+changeModule+'"]').show();if(obj.attr('data-module-input')){var ipt=$('[name="'+obj.attr('data-module-input')+'"]');if(!ipt.attr('data-placeholder-')){ipt.attr('data-placeholder-',ipt.prop('placeholder')+' ')}
if(ipt.attr('data-placeholder-'+changeModule)){ipt.prop('placeholder',ipt.attr('data-placeholder-'+changeModule))}else{ipt.prop('placeholder','')}
if(ipt.attr('data-val-'+changeModule)){ipt.val(ipt.attr('data-val-'+changeModule))}else{ipt.val('')}}})},clone_tpl:function(tplId,namePre){namePre=namePre?namePre:'';var tpl=$(tplId).clone();tpl.removeAttr('id');tpl.find('[data-name]').each(function(){$(this).attr('name',namePre+$(this).attr('data-name'));$(this).removeAttr('data-name')});return tpl},get_content_signs:function(contentSignEle){var contentSigns=[];$(contentSignEle).each(function(){var csVal=$(this).val();csVal=decode_urlbase2json(csVal);contentSigns.push(csVal)});return contentSigns},page_signs:function(pageConfig,returnMergeSigns,noDefSign){var signs={area:[],url:[],content:[]};if(!isObject(pageConfig)){pageConfig={}}
var areaRule=pageConfig.area?pageConfig.area:'';var urlRule=pageConfig.url_rule?pageConfig.url_rule:'';var contentSigns=pageConfig.content_signs;var allowDefSign=noDefSign?0:!0;signs.area=ruleInsertSign.matchN(null,null,{rule:areaRule,def:allowDefSign});signs.url=ruleInsertSign.matchN(null,null,{rule:urlRule,def:allowDefSign});var signMatch=window.tpl_lang.sign_match;if(isObject(contentSigns)){for(var i in contentSigns){if(isObject(contentSigns[i])){if(contentSigns[i].identity){signs.content.push(signMatch.replace('{:id}',contentSigns[i].identity))}}}}
for(var i in signs){if(!isObject(signs[i])){signs[i]=[]}}
if(returnMergeSigns){var mergeSigns=[];for(var i in signs.area){var curSign=signs.area[i];if(mergeSigns.indexOf(curSign)<=-1&&signs.url.indexOf(curSign)<=-1&&signs.content.indexOf(curSign)<=-1){mergeSigns.push(curSign)}}
for(var i in signs.url){var curSign=signs.url[i];if(mergeSigns.indexOf(curSign)<=-1&&signs.content.indexOf(curSign)<=-1){mergeSigns.push(curSign)}}
for(var i in signs.content){var curSign=signs.content[i];if(mergeSigns.indexOf(curSign)<=-1){mergeSigns.push(curSign)}}
return mergeSigns}else{return signs}},parent_page_signs:function(dropdownBtn){var $_o=this;var boxObj=$(dropdownBtn).parents('.c-p-url-page-signs').eq(0);if(!boxObj||boxObj.length<=0){return}
var pageType=boxObj.attr('data-page-type');var inputName=boxObj.attr('data-input-name');var isPagination=boxObj.attr('data-is-pagination');var pageVars=$_o.get_page_vars(pageType);var formId=pageVars.formId;var namePre=pageVars.namePre;if(!pageType||!inputName||!formId){return}
var dropdownMenu=boxObj.find('.dropdown-menu');if(dropdownMenu.length>0){$(dropdownMenu).html('')}
var iptObj=boxObj.find('[name="'+inputName+'"]');if(!iptObj||iptObj.length<=0){iptObj=null}
var frontUrls=new Array();$('#c_p_front_urls [id^="front_url_"]').each(function(){var frontUrl=$(this).find('[name="config[front_urls][]"]').val();frontUrls.push(frontUrl)});var levelUrls=new Array();$('#c_p_level_urls [id^="level_url_"]').each(function(){var levelUrl=$(this).find('[name="config[level_urls][]"]').val();levelUrls.push(levelUrl)});var relationUrls=new Array();$('#c_p_relation_urls [id^="relation_url_"]').each(function(){var relationUrl=$(this).find('[name="config[relation_urls][]"]').val();relationUrls.push(relationUrl)});var sourceConfig={};sourceConfig.area='';sourceConfig.url_rule='';sourceConfig.content_signs=$_o.get_content_signs($_o.formid+' [name="config[source_config][content_signs][]"]');if(isPagination){sourceConfig.pagination={area:$($_o.formid).find('[name="config[source_config][pagination][area]"]').val(),url_rule:$($_o.formid).find('[name="config[source_config][pagination][url_rule]"]').val()}}
var urlConfig={};urlConfig.area=$($_o.formid+' [name="config[area]"]').val();urlConfig.url_rule=$($_o.formid+' [name="config[url_rule]"]').val();urlConfig.content_signs=$_o.get_content_signs($_o.formid+' [name="config[content_signs][]"]');if(isPagination){urlConfig.pagination={area:$($_o.formid).find('[name="config[pagination][area]"]').val(),url_rule:$($_o.formid).find('[name="config[pagination][url_rule]"]').val()}}
var pageConfig={name:'',area:'',url_rule:'',content_signs:''};var mergeType=iptObj?iptObj.attr('data-merge-type'):'';mergeType=mergeType?mergeType:'';if($_o.page_is_list(pageType)){var objid='';if(mergeType=='content_sign'){var csPageConfig=$_o.cpContentSign.curPageConfig;objid=csPageConfig.objid;if(pageType=='relation_url'){pageConfig.page=csPageConfig.relation_url.page}
pageConfig.area=csPageConfig[namePre].area;pageConfig.url_rule=csPageConfig[namePre].url_rule;pageConfig.content_signs=csPageConfig[namePre].content_signs}else{objid=$(formId).find('[name="objid"]').val();if(pageType=='relation_url'){pageConfig.page=$(formId).find('[name="relation_url[page]"]').val()}
pageConfig.area=$(formId).find('[name="'+namePre+'[area]"]').val();pageConfig.url_rule=$(formId).find('[name="'+namePre+'[url_rule]"]').val();pageConfig.content_signs=$_o.get_content_signs(formId+' [name="'+namePre+'[content_signs][]"]')}
if(objid){pageConfig.name=$('#'+objid).find('.name').attr('data-val')}
pageConfig.name=pageConfig.name?pageConfig.name:'';pageConfig.area=pageConfig.area?pageConfig.area:'';pageConfig.url_rule=pageConfig.url_rule?pageConfig.url_rule:'';if(isPagination){pageConfig.pagination={area:$(formId).find('[name="'+namePre+'[pagination][area]"]').val(),url_rule:$(formId).find('[name="'+namePre+'[pagination][url_rule]"]').val()}}}
if(mergeType=='content_sign'){mergeType+=':'+$($_o.cpContentSign.formObj+' [name="objid"]').attr('data-identity')}
var sourceIsUrl=$_o.source_is_url();ajaxOpen({type:'POST',dataType:'json',url:ulink("cpattern/page_signs"),data:{front_urls:frontUrls,source_config:sourceConfig,level_urls:levelUrls,relation_urls:relationUrls,url_config:urlConfig,page_config:pageConfig,page_type:pageType,merge_type:mergeType,source_is_url:sourceIsUrl,is_pagination:isPagination},success:function(data){if(data.code==1){data=data.data;var pageSort=data.sort;var allSigns=data.signs;var html='';var valSigns=null;if(iptObj){valSigns=ruleInsertSign.matchN(null,null,{rule:iptObj.val()})}
if(!valSigns||typeof(valSigns)!='object'){valSigns=new Array()}
var nullTips='';if(sourceIsUrl){nullTips='起始页已设为内容页'}
for(var asi in allSigns){var pageSigns=allSigns[asi]?allSigns[asi]:{};var pageName=pageSigns.name;var signs=pageSigns.signs;signs=signs?signs:{};html+='<tr><td>'+pageName+'</td>';var signKeys=['area','url','content'];for(var ski in signKeys){html+='<td>';var signKey=signKeys[ski];var keySigns=signs[signKey];if(keySigns&&keySigns.length>0){var keyGlobalSigns=signs[signKey+'_global'];for(var ksi in keySigns){var sign=keySigns[ksi];var signHtml=htmlspecialchars(sign);if(keyGlobalSigns&&keyGlobalSigns.indexOf(sign)>-1){var color=valSigns.indexOf(sign)>-1?'color:green;':'';html+='<a href="javascript:;" data-val="'+signHtml+'" style="'+color+'">'+signHtml+'</a>'}else{html+='<span style="color:#999;" title="被覆盖">'+signHtml+'</span>'}}}else{html+='<span style="color:#999;" title="'+nullTips+'">无</span>'}
html+='</td>'}
html+='</tr>'}
if(dropdownMenu.length>0){var signsObj=$_o.clone_tpl('#coll_tpl_page_signs');$(dropdownMenu).append(signsObj);$(dropdownMenu).find('table tbody').html(html);if(isPagination&&mergeType=='url'){$(dropdownMenu).find('table tfoot').html('');if($(formId).find('[name="'+namePre+'[pagination][number][open]"][value="1"]').is(':checked')){var htmlFoot='<tr><td colspan="4"><b>分页标签</b></td></tr><tr><td colspan="4"><a href="javascript:;" data-val="[分页序号]"';if(iptObj){if(iptObj.val().indexOf('[分页序号]')>-1){htmlFoot+=' style="color:green;"'}}
htmlFoot+='>[分页序号]</a></td></tr>';$(dropdownMenu).find('table tfoot').show().html(htmlFoot)}}
$(dropdownMenu).find('a[data-val]').bind('click',function(){if(iptObj){globalOp.insertAtCaret(iptObj,$(this).attr('data-val'))}});var sortObj=$(dropdownMenu).find('th.sorting');sortObj.removeClass('sorting');sortObj.addClass(pageSort=='asc'?'sorting_asc':'sorting_desc');sortObj.attr('title','页面'+(pageSort=='asc'?'升序':'降序')+'排列');sortObj.bind('click',function(){ajaxOpen({type:'get',dataType:'json',url:ulink("cpattern/page_signs_sort"),success:function(data){toastr.success(data.msg)}})})}}}})},field_is_loop:function(){var hasLoop=$(this.formid+' #coll_pattern_field .c-p-field-list').find('.field-module[data-is-loop]');if(hasLoop&&hasLoop.length>0){hasLoop=1}else{hasLoop=''}
return hasLoop},get_task_id:function(){var taskId=$(this.formid+' [name="task_id"]').val();taskId=taskId?taskId:'';return taskId}}
function CpFrontUrl(cpClass){this.$_cp=cpClass;this.formObj='#form_front_url'}
CpFrontUrl.prototype={constructor:CpFrontUrl,init:function(front_url){var $_o=this;$($_o.formObj).bind('submit',function(){$_o.add_sub();return!1});$_o.$_cp.init_page('front_url');$($_o.formObj).on('click','.c-p-url-page-signs .btn-page-signs',function(){$_o.$_cp.parent_page_signs(this)});if(front_url){var loadParams=['name','url'];for(var i in loadParams){if(front_url[loadParams[i]]){$($_o.formObj+' [name="front_url['+loadParams[i]+']"]').val(front_url[loadParams[i]])}}
if(front_url.use_cookie){$($_o.formObj+' [name="front_url[use_cookie]"][value="'+toInt(front_url.use_cookie)+'"]').prop('checked',!0)}
if(front_url.use_cookie_img){$($_o.formObj+' [name="front_url[use_cookie_img]"][value="'+toInt(front_url.use_cookie_img)+'"]').prop('checked',!0)}
if(front_url.use_cookie_file){$($_o.formObj+' [name="front_url[use_cookie_file]"][value="'+toInt(front_url.use_cookie_file)+'"]').prop('checked',!0)}
$_o.$_cp.load_page('front_url',front_url)}},add:function(objid,front_url){var $_o=this;var pageSigns=$_o.$_cp.page_signs(front_url,!0,!0);var objEle=null;if(objid){objEle=$($_o.$_cp.formid+' #'+objid)}else{objEle=$_o.$_cp.clone_tpl('#coll_tpl_front_url');objEle.attr('id','front_url_'+generateUUID());$($_o.$_cp.formid+' #c_p_front_urls').append(objEle)}
objEle.find('.name').attr('data-val',front_url.name).text(front_url.name);objEle.find('[name="config[front_urls][]"]').val(encode_json2urlbase(front_url));pageSigns=pageSigns.join(' ');pageSigns=pageSigns?pageSigns:'无';objEle.find('.signs').val(pageSigns)},add_sub:function(){var $_o=this;var objid=$($_o.formObj+' input[name="objid"]').val();var checkName=!0;if(objid){var name=$($_o.$_cp.formid+' #'+objid).find('.name').attr('data-val');if(name==$($_o.formObj+' [name="front_url[name]"]').val()){checkName=!1}}
if(checkName){var hasName=!1;$('#c_p_front_urls [id^="front_url_"] .name').each(function(){if($($_o.formObj+' [name="front_url[name]"]').val()==$(this).attr('data-val')){hasName=!0;return!1}});if(hasName){toastr.error('该名称已存在！');return!1}}
ajaxOpen({type:'POST',dataType:'json',url:$($_o.formObj).attr('action'),data:$($_o.formObj).serialize(),success:function(data){if(data.code==1){$('#myModal').modal('hide');data=data.data;if(data){$_o.add(data.objid,data.front_url)}}else{toastr.error(data.msg)}},error:function(data){toastr.error(data)}});return!1}}
function CpLevelUrl(cpClass){this.$_cp=cpClass;this.formObj='#form_level_url'}
CpLevelUrl.prototype={constructor:CpLevelUrl,init:function(level_url){var $_o=this;$($_o.formObj).bind('submit',function(){$_o.add_sub();return!1});$_o.$_cp.init_page('level_url');$($_o.formObj).on('click','.c-p-url-page-signs .btn-page-signs',function(){$_o.$_cp.parent_page_signs(this)});if(level_url){var loadParams=['name'];for(var i in loadParams){if(level_url[loadParams[i]]){$($_o.formObj+' [name="level_url['+loadParams[i]+']"]').val(level_url[loadParams[i]])}}
$_o.$_cp.load_page('level_url',level_url)}},add:function(objid,level_url){var $_o=this;var pageSigns=$_o.$_cp.page_signs(level_url,!0);var objEle=null;if(objid){objEle=$($_o.$_cp.formid+' #'+objid)}else{objEle=$_o.$_cp.clone_tpl('#coll_tpl_level_url');objEle.attr('id','level_url_'+generateUUID());$($_o.$_cp.formid+' #c_p_level_urls').append(objEle)}
objEle.find('.name').attr('data-val',level_url.name).text(level_url.name);objEle.find('[name="config[level_urls][]"]').val(encode_json2urlbase(level_url));objEle.find('.signs').val(pageSigns.join(' '))},add_sub:function(){var $_o=this;var objid=$($_o.formObj+' input[name="objid"]').val();var checkName=!0;if(objid){var name=$($_o.$_cp.formid+' #'+objid).find('.name').attr('data-val');if(name==$($_o.formObj+' [name="level_url[name]"]').val()){checkName=!1}}
if(checkName){var hasName=!1;$('#c_p_level_urls [id^="level_url_"] .name').each(function(){if($($_o.formObj+' [name="level_url[name]"]').val()==$(this).attr('data-val')){hasName=!0;return!1}});if(hasName){toastr.error('该名称已存在！');return!1}}
ajaxOpen({type:'POST',dataType:'json',url:$($_o.formObj).attr('action'),data:$($_o.formObj).serialize(),success:function(data){if(data.code==1){$('#myModal').modal('hide');data=data.data;if(data){$_o.add(data.objid,data.level_url)}}else{toastr.error(data.msg)}},error:function(data){toastr.error(data)}});return!1}}
function CpRelationUrl(cpClass){this.$_cp=cpClass;this.formObj='#form_relation_url'}
CpRelationUrl.prototype={constructor:CpRelationUrl,init:function(relation_url){var $_o=this;$($_o.formObj).bind('submit',function(){$_o.add_sub();return!1});$_o.$_cp.init_page('relation_url');$($_o.formObj).on('click','.c-p-url-page-signs .btn-page-signs',function(){$_o.$_cp.parent_page_signs(this)});var optRelations='';$('#c_p_relation_urls [id^="relation_url_"] .name').each(function(){if(relation_url&&$(this).attr('data-val')==relation_url.name){return!0}
optRelations+='<option value="'+$(this).attr('data-val')+'">关联页：'+$(this).attr('data-val')+'</option>'});$($_o.formObj+' [name="relation_url[page]"]').append(optRelations);if(relation_url){var loadParams=['name','page'];for(var i in loadParams){if(relation_url[loadParams[i]]){$($_o.formObj+' [name="relation_url['+loadParams[i]+']"]').val(relation_url[loadParams[i]])}}
$_o.$_cp.load_page('relation_url',relation_url)}},add:function(objid,relation_url){var $_o=this;var pageSigns=$_o.$_cp.page_signs(relation_url,!0);var objEle=null;var relationPage=relation_url.page;if(relationPage){relationPage='关联页：'+relationPage}else{relationPage='内容页'}
if(objid){objEle=$($_o.$_cp.formid+' #'+objid)}else{objEle=$_o.$_cp.clone_tpl('#coll_tpl_relation_url');objEle.attr('id','relation_url_'+generateUUID());$($_o.$_cp.formid+' #c_p_relation_urls').append(objEle)}
objEle.find('.name').attr('data-val',relation_url.name).text(relation_url.name);objEle.find('.page').text(relationPage);objEle.find('[name="config[relation_urls][]"]').val(encode_json2urlbase(relation_url));objEle.find('.signs').val(pageSigns.join(' '))},add_sub:function(){var $_o=this;var objid=$($_o.formObj+' input[name="objid"]').val();var checkName=!0;if(objid){var name=$($_o.$_cp.formid+' #'+objid).find('.name').attr('data-val');if(name==$($_o.formObj+' [name="relation_url[name]"]').val()){checkName=!1}}
if(checkName){var hasName=!1;$('#c_p_relation_urls [id^="relation_url_"] .name').each(function(){if($($_o.formObj+' [name="relation_url[name]"]').val()==$(this).attr('data-val')){hasName=!0;return!1}});if(hasName){toastr.error('该名称已存在！');return!1}}
ajaxOpen({type:'POST',dataType:'json',url:$($_o.formObj).attr('action'),data:$($_o.formObj).serialize(),success:function(data){if(data.code==1){$('#myModal').modal('hide');data=data.data;if(data){$_o.add(data.objid,data.relation_url)}}else{toastr.error(data.msg)}},error:function(data){toastr.error(data)}});return!1}}
function CpUrlWeb(cpClass){this.$_cp=cpClass}
CpUrlWeb.prototype={constructor:CpUrlWeb,page_init:function(pageType,isPagination){var $_o=this;var pageVars=$_o.$_cp.get_page_vars(pageType,null,isPagination);var boxId=pageVars.boxId;var namePre=pageVars.namePre;if(!boxId||!namePre){return}
var boxUrlWebId=boxId+'_web';$(boxUrlWebId+' [name="'+namePre+'[url_web][open]"]').bind('click',function(){if($(this).val()==1){$(boxUrlWebId+'_open').show()}else{$(boxUrlWebId+'_open').hide()}
$_o.def_config_use_url_web(pageType)});globalOp.inputSelectCustom(boxUrlWebId+' select[name="'+namePre+'[url_web][charset]"]',namePre+'[url_web][charset_custom]');globalOp.inputSelectCustom(boxUrlWebId+' select[name="'+namePre+'[url_web][encode]"]',namePre+'[url_web][encode_custom]');$_o.def_config_charset(pageType);$_o.def_config_encode(pageType);$(boxUrlWebId+' select[name="'+namePre+'[url_web][form_method]"]').bind('change',function(){var obj=$(boxUrlWebId+' .c-p-url-web-content-type');if($(this).val()=='post'){obj.show()}else{obj.hide()}});$_o.def_config_header_global(pageType);$(boxUrlWebId+' .add-url-web-form').bind('click',function(){$_o.add_page_url_web(pageType,isPagination,'form','','')});$(boxUrlWebId+' .c-p-url-web-form').on('click','.delete-url-web-form',function(){var curObj=$(this);confirmRight('确定删除？',function(){curObj.parents('tr').eq(0).remove()})});$(boxUrlWebId+' .add-url-web-header').bind('click',function(){$_o.add_page_url_web(pageType,isPagination,'header','','')});$(boxUrlWebId+' .c-p-url-web-header').on('click','.delete-url-web-header',function(){var curObj=$(this);confirmRight('确定删除？',function(){curObj.parents('tr').eq(0).remove()})})},page_load:function(pageType,urlWebConfig,isPagination){var $_o=this;var pageVars=$_o.$_cp.get_page_vars(pageType,null,isPagination);var formId=pageVars.formId;var boxId=pageVars.boxId;var namePre=pageVars.namePre;if(!formId||!boxId||!namePre){return}
if(!isObject(urlWebConfig)){urlWebConfig={}}
var urlWebNamePre=namePre+'[url_web]';urlWebConfig.open=toInt(urlWebConfig.open);$(formId+' [name="'+urlWebNamePre+'[open]"][value="'+urlWebConfig.open+'"]').trigger('click');if(urlWebConfig.open>0){globalOp.showPanelCollapse(boxId+'_web')}
if(urlWebConfig.charset){$(formId+' select[name="'+urlWebNamePre+'[charset]"]').val(urlWebConfig.charset).trigger('change')}
if(urlWebConfig.charset_custom){$(formId+' [name="'+urlWebNamePre+'[charset_custom]"]').val(urlWebConfig.charset_custom)}
if(urlWebConfig.encode){$(formId+' select[name="'+urlWebNamePre+'[encode]"]').val(urlWebConfig.encode).trigger('change')}
if(urlWebConfig.encode_custom){$(formId+' [name="'+urlWebNamePre+'[encode_custom]"]').val(urlWebConfig.encode_custom)}
if(urlWebConfig.form_method){$(formId+' [name="'+urlWebNamePre+'[form_method]"]').val(urlWebConfig.form_method).trigger('change')}
if(urlWebConfig.content_type){$(formId+' [name="'+urlWebNamePre+'[content_type]"]').val(urlWebConfig.content_type)}
if(urlWebConfig.form_names){var urlWebFormVals=urlWebConfig.form_vals?urlWebConfig.form_vals:{};for(var i in urlWebConfig.form_names){$_o.add_page_url_web(pageType,isPagination,'form',urlWebConfig.form_names[i],urlWebFormVals[i])}}
if(urlWebConfig.header_global){$(formId+' [name="'+urlWebNamePre+'[header_global]"][value="'+urlWebConfig.header_global+'"]').prop('checked',!0)}
if(urlWebConfig.header_names){var urlWebHeaderVals=urlWebConfig.header_vals?urlWebConfig.header_vals:{};for(var i in urlWebConfig.header_names){$_o.add_page_url_web(pageType,isPagination,'header',urlWebConfig.header_names[i],urlWebHeaderVals[i])}}},add_page_url_web:function(pageType,isPagination,type,name,val){var $_o=this;var pageVars=$_o.$_cp.get_page_vars(pageType,null,isPagination);var boxId=pageVars.boxId;var namePre=pageVars.namePre;if(!boxId||!namePre||!type){return}
boxId+='_web';name=name?name:'';val=val?val:'';var tr=$_o.$_cp.clone_tpl('#coll_tpl_url_web_'+type,namePre);tr.find('[name="'+namePre+'[url_web]['+type+'_names][]"]').val(name);tr.find('[name="'+namePre+'[url_web]['+type+'_vals][]"]').val(val);tr.find('.c-p-url-page-signs').each(function(){$(this).attr('data-page-type',pageType).attr('data-input-name',namePre+$(this).attr('data-input-name'));if(isPagination){$(this).attr('data-is-pagination',1)}});$(boxId).find('.c-p-url-web-'+type+' tbody').append(tr)},def_config_charset:function(pageType){var $_o=this;var val=$($_o.$_cp.formid+' [name="config[charset]"]').val();var formid=$_o.$_cp.formid;if(pageType){formid=$_o.$_cp.get_page_vars(pageType,'formId')}
if(!val||val=='auto'){val='自动检测'}else if(val=='custom'){if($_o.$_cp.page_is_list(pageType)){val=$($_o.$_cp.formid+' [name="config[charset_custom]"]').val();val=val?val:''}else{val=''}
val='自定义'+(val?('»'+htmlspecialchars(val)):'')}
$(formid).find('.def-config-charset').html('默认：'+val)},def_config_encode:function(pageType){var $_o=this;var val=$($_o.$_cp.formid+' [name="config[encode]"]').val();var formid=$_o.$_cp.formid;if(pageType){formid=$_o.$_cp.get_page_vars(pageType,'formId')}
if(!val){val='系统默认'}else if(val=='custom'){if($_o.$_cp.page_is_list(pageType)){val=$($_o.$_cp.formid+' [name="config[encode_custom]"]').val();val=val?val:''}else{val=''}
val='自定义'+(val?('»'+htmlspecialchars(val)):'')}
$(formid).find('.def-config-encode').html('默认：'+val)},def_config_header_global:function(pageType){var $_o=this;var val=$($_o.$_cp.formid+' [name="config[request_headers][open]"]:checked').val();val=toInt(val);var formid=$_o.$_cp.formid;if(pageType){formid=$_o.$_cp.get_page_vars(pageType,'formId')}
$(formid).find('.def-config-request-headers-open').html(val>0?'是':'否')},def_config_use_url_web:function(pageType){var $_o=this;var pageVars=$_o.$_cp.get_page_vars(pageType);var formId=pageVars.formId;var boxId=pageVars.boxId;var namePre=pageVars.namePre;if(!formId||!boxId||!namePre){return}
var urlWebOpen=$(formId).find('[name="'+namePre+'[url_web][open]"]:checked').val();urlWebOpen=toInt(urlWebOpen);$(boxId+'_pagination').find('.def-config-url-web-open').html(urlWebOpen>0?'是':'否')}}
function CpRenderer(cpClass){this.$_cp=cpClass}
CpRenderer.prototype={constructor:CpRenderer,page_init:function(pageType,isPagination){var $_o=this;var pageVars=$_o.$_cp.get_page_vars(pageType,null,isPagination);var boxId=pageVars.boxId;var namePre=pageVars.namePre;if(!boxId||!namePre){return}
$_o.def_config_renderer_open(pageType);var rdBoxId=boxId+'_renderer';$(rdBoxId+' .add-url-renderer').bind('click',function(){$_o.add(pageType,isPagination)});$(rdBoxId+' [name="'+namePre+'[renderer][open]"]').bind('click',function(){$_o.def_config_use_renderer(pageType)});if(isPagination){$(rdBoxId+' [name="'+namePre+'[renderer][open_pn]"]').bind('click',function(){if($(this).val()==1){$(rdBoxId+'_open_pn').show()}else{$(rdBoxId+'_open_pn').hide()}})}
$(rdBoxId+' .c-p-url-renderer-list').on('change','select[name="'+namePre+'[renderer][types][]"]',function(){var type=$(this).val();var tr=$(this).parents('tr').eq(0);var types={'wait_time':{content:1,content_tips:'输入数字'},'scroll_top':{content:1,content_tips:'输入数字'},'click':{element:1},'val':{element:1,content:1,content_tips:'输入值'}};var tdTypeCols=3;tr.find('.td-renderer-element,.td-renderer-content').hide();tr.find('input[name="'+namePre+'[renderer][contents][]"]').attr('placeholder','');var curType=types[type];if(isObject(curType)){if(curType.element){tr.find('.td-renderer-element').show();tdTypeCols-=1}
if(curType.content){tr.find('.td-renderer-content').show();tdTypeCols-=1;if(curType.content_tips){tr.find('input[name="'+namePre+'[renderer][contents][]"]').attr('placeholder',curType.content_tips)}}}
tr.find('.td-renderer-type').attr('colspan',tdTypeCols)});$(rdBoxId+' .c-p-url-renderer-list').on('click','.delete-url-renderer',function(){var curObj=$(this);confirmRight('确定删除？',function(){curObj.parents('tr').eq(0).remove()})});globalOp.eleExchange(rdBoxId+' .c-p-url-renderer-list','.icon-drag-move','tr')},page_load:function(pageType,rdConfig,isPagination){var $_o=this;var pageVars=$_o.$_cp.get_page_vars(pageType,null,isPagination);var boxId=pageVars.boxId;var namePre=pageVars.namePre;if(!boxId||!namePre){return}
var rdBoxId=boxId+'_renderer';if(isObject(rdConfig)){$(rdBoxId).find('[name="'+namePre+'[renderer][open]"][value="'+rdConfig.open+'"]').prop('checked',!0).trigger('click');var rdTypes=isObject(rdConfig.types)?rdConfig.types:[];var rdElements=isObject(rdConfig.elements)?rdConfig.elements:[];var rdContents=isObject(rdConfig.contents)?rdConfig.contents:[];var showPanel=!1;var openVal=rdConfig.open=='y'?true:!1;var openDef=$($_o.$_cp.formid+' [name="config[page_render]"]:checked').val();openDef=toInt(openDef);openDef=openDef>0?true:!1;if(rdTypes&&rdTypes.length>0){for(var i in rdTypes){$_o.add(pageType,isPagination,rdTypes[i],rdElements[i],rdContents[i])}
if((!rdConfig.open&&openDef)||openVal){showPanel=!0}}else{if(rdConfig.open){if(openVal!=openDef){showPanel=!0}}}
if(isPagination){$(rdBoxId+' [name="'+namePre+'[renderer][open_pn]"][value="'+rdConfig.open_pn+'"]').prop('checked',!0).trigger('click');if(rdConfig.open_pn){showPanel=!0}else{showPanel=!1}}
if(showPanel){globalOp.showPanelCollapse(rdBoxId)}}},add:function(pageType,isPagination,rdType,rdElement,rdContent){var $_o=this;var pageVars=$_o.$_cp.get_page_vars(pageType,null,isPagination);var boxId=pageVars.boxId;var namePre=pageVars.namePre;if(!boxId||!namePre){return}
var rdBoxId=boxId+'_renderer';var tr=$_o.$_cp.clone_tpl('#coll_tpl_url_renderer',namePre);if(rdType){tr.find('[name*="[renderer][types]"]').val(rdType);tr.find('[name*="[renderer][elements]"]').val(rdElement);tr.find('[name*="[renderer][contents]"]').val(rdContent)}
tr.find('.c-p-url-page-signs').each(function(){$(this).attr('data-page-type',pageType).attr('data-input-name',namePre+$(this).attr('data-input-name'));if(isPagination){$(this).attr('data-is-pagination',1)}});$(rdBoxId+' .c-p-url-renderer-list table').append(tr);if(rdType){$(rdBoxId+' .c-p-url-renderer-list').find('[name*="[renderer][types]"]:last-child').trigger('change')}},def_config_renderer_open:function(pageType){var $_o=this;var val=$($_o.$_cp.formid+' [name="config[page_render]"]:checked').val();val=toInt(val);var formid=$_o.$_cp.formid;if(pageType){formid=$_o.$_cp.get_page_vars(pageType,'formId')}
$(formid).find('.def-config-page-render').html(val>0?'是':'否')},def_config_use_renderer:function(pageType){var $_o=this;var pageVars=$_o.$_cp.get_page_vars(pageType);var formId=pageVars.formId;var boxId=pageVars.boxId;var namePre=pageVars.namePre;if(!formId||!boxId||!namePre){return}
var defConfigObj=$(boxId+'_pagination').find('.def-config-renderer-open');var rendererOpen=$(formId).find('[name="'+namePre+'[renderer][open]"]:checked').val();if(rendererOpen){defConfigObj.html(rendererOpen=='y'?'是':'否').show();defConfigObj.parent().find('.def-config-page-render').hide()}else{defConfigObj.parent().find('.def-config-page-render').show();defConfigObj.hide()}}}
function CpPagination(cpClass){this.$_cp=cpClass}
CpPagination.prototype={constructor:CpPagination,page_has_pn:function(pageType){if(pageType=='source_url'||pageType=='level_url'||pageType=='url'){return!0}else{return!1}},page_init:function(pageType){var $_o=this;if($_o.page_has_pn(pageType)){var pageVars=$_o.$_cp.get_page_vars(pageType);var formId=pageVars.formId;var boxId=pageVars.boxId;var namePre=pageVars.namePre;if(!formId||!boxId||!namePre){return}
var pnBoxId=boxId+'_pagination';var pnNamePre=namePre+'[pagination]';$(formId+' select[name="'+pnNamePre+'[area_module]"],select[name="'+pnNamePre+'[url_rule_module]"]').bind('click',function(){$_o.$_cp.rule_module_slt(this)});$(pnBoxId+' [name="'+pnNamePre+'[open]"]').bind('click',function(){if($(this).val()==1){$(pnBoxId+'_open').show()}else{$(pnBoxId+'_open').hide()}});if(pageType=='url'){$(pnBoxId).on('click','.add-url-pagination-field',function(){var url=ulink("cpattern/pagination_field?is_loop=_is_loop_",{'_is_loop_':$_o.$_cp.field_is_loop()});windowModal('分页字段',url)});$(pnBoxId+' .c-p-url-pagination-fields').on('click','.field',function(){var parent=$(this).parents('[id^="pagination_field_"]').eq(0);var objid=parent.attr('id');var pnField=parent.find('[name="'+pnNamePre+'[fields][]"]').val();var url=ulink("cpattern/pagination_field?objid=_objid_&pagination_field=_pnfield_&is_loop=_is_loop_",{'_objid_':objid,'_pnfield_':pnField,'_is_loop_':$_o.$_cp.field_is_loop()});windowModal('分页字段',url)});$(pnBoxId+' .c-p-url-pagination-fields').on('click','.delete',function(){var parent=$(this).parents('[id^="pagination_field_"]').eq(0);confirmRight('确定删除？',function(){parent.remove()})})}
$_o.$_cp.cpUrlWeb.page_init(pageType,!0);$_o.$_cp.cpRenderer.page_init(pageType,!0)}},page_load:function(pageType,pnConfig){var $_o=this;if($_o.page_has_pn(pageType)){var pageVars=$_o.$_cp.get_page_vars(pageType);if(!pageVars.boxId||!pageVars.namePre){return}
var pnBoxId=pageVars.boxId+'_pagination';var pnNamePre=pageVars.namePre+'[pagination]';if(isObject(pnConfig)){$_o.$_cp.load_page_rule(pageType,pnConfig,!0);$(pnBoxId+' [name="'+pnNamePre+'[max]"]').val(toInt(pnConfig.max));$(pnBoxId+' [name="'+pnNamePre+'[use_url_web]"][value="'+pnConfig.use_url_web+'"]').prop('checked',!0);$(pnBoxId+' [name="'+pnNamePre+'[use_renderer]"][value="'+pnConfig.use_renderer+'"]').prop('checked',!0);pnConfig.open=toInt(pnConfig.open);if(pnConfig.open){$(pnBoxId+' [name="'+pnNamePre+'[open]"][value="'+pnConfig.open+'"]').trigger('click');if(pnConfig.open>0){globalOp.showPanelCollapse(pnBoxId)}}
if(pageType=='url'){if(pnConfig.fields){for(var i in pnConfig.fields){$_o.field_op(pageType,'add',{pagination_field:pnConfig.fields[i]})}}}
$_o.$_cp.cpUrlWeb.page_load(pageType,pnConfig.url_web,!0);$_o.$_cp.cpRenderer.page_load(pageType,pnConfig.renderer,!0)}}},field_op:function(pageType,op,params){var $_o=this;if(pageType!='url'){return}
params=params?params:{};var formObj=params.formObj?params.formObj:'#form_pagination_field';var pageVars=$_o.$_cp.get_page_vars(pageType);if(!pageVars.boxId||!pageVars.namePre){return}
var pnBoxId=pageVars.boxId+'_pagination';var pnNamePre=pageVars.namePre+'[pagination]';if(op=='init'){var fieldNames=$_o.$_cp.get_field_names();var fieldOptions='<option value="">--请选择--</option><option value="::all">-全部字段-</option>';for(var i in fieldNames){fieldOptions+='<option value="'+fieldNames[i]+'">'+fieldNames[i]+'</option>'}
$(formObj+' select[name="pagination_field[field]"]').html(fieldOptions);$(formObj).bind('submit',function(){$_o.field_op(pageType,'add_sub');return!1});if(isObject(params.pagination_field)){$(formObj+' select[name="pagination_field[field]"]').val(params.pagination_field.field);$(formObj+' [name="pagination_field[delimiter]"]').val(params.pagination_field.delimiter)}}else if(op=='add'){params.pagination_field=isObject(params.pagination_field)?params.pagination_field:{};var tpl='<a href="javascript:;" class="field" data-field="__field__">__field_name__</a><em class="glyphicon glyphicon-remove-circle delete"></em><input type="hidden" name="'+pnNamePre+'[fields][]" value="__pn_field__" />';var fieldName=params.pagination_field.field=='::all'?'-全部字段-':params.pagination_field.field;tpl=tpl.replace(/__field__/ig,params.pagination_field.field).replace(/__field_name__/ig,htmlspecialchars(fieldName)).replace(/__pn_field__/ig,encode_json2urlbase(params.pagination_field));var objid=params.objid;if(!objid){objid='pagination_field_'+pageType+'_'+generateUUID();$(pnBoxId+' .c-p-url-pagination-fields').append('<div class="param-label" id="'+objid+'"></div>')}
$('#'+objid).html(tpl)}else if(op=='add_sub'){var objid=$(formObj+' input[name="objid"]').val();var checkField=!0;if(objid){var field=$(pnBoxId+' #'+objid).find('.field').attr('data-field');if(field==$(formObj+' select[name="pagination_field[field]"]').val()){checkField=!1}}
if(checkField){var hasField=!1;var fieldList=new Array();$(pnBoxId+' .c-p-url-pagination-fields [id^="pagination_field_"] .field').each(function(){fieldList.push($(this).attr('data-field'))});for(var i in fieldList){if($(formObj+' select[name="pagination_field[field]"]').val()==fieldList[i]){hasField=!0;break}}
if(hasField){toastr.error('该字段已存在！');return!1}}
ajaxOpen({type:'POST',dataType:'json',url:$(formObj).attr('action'),data:$(formObj).serialize(),success:function(data){if(data.code==1){$('#myModal').modal('hide');$_o.field_op(pageType,'add',data.data)}else{toastr.error(data.msg)}},error:function(data){toastr.error(data)}});return!1}}}
function CpField(cpClass){this.$_cp=cpClass;this.formObj='#form_field'}
CpField.prototype={constructor:CpField,init:function(fieldData){var $_o=this;var sourceOptions=$_o.$_cp.page_source_options(!1);if(sourceOptions){$($_o.formObj+' select[name="field[source]"]').html(sourceOptions)}
$($_o.formObj+' select[name="field[source]"]').bind('change',function(){var fsource=$(this).val();fsource=fsource?fsource.split(':'):[];var pageType=fsource[0]?fsource[0]:'url';var pageName=fsource[1]?fsource[1]:'';var pageVars=$_o.$_cp.get_page_vars(pageType);var boxId=pageVars.boxId;var namePre=pageVars.namePre;var formId=pageVars.formId;var pageSigns=[];if(pageType=='source_url'||pageType=='url'){var urlConfig={};var noDefSign=!1;if(pageType=='source_url'){urlConfig.area='';urlConfig.url_rule='';noDefSign=!0}else{urlConfig.area=$(formId+' [name="'+namePre+'[area]"]').val();urlConfig.url_rule=$(formId+' [name="'+namePre+'[url_rule]"]').val()}
urlConfig.content_signs=$_o.$_cp.get_content_signs(formId+' [name="'+namePre+'[content_signs][]"]');pageSigns=$_o.$_cp.page_signs(urlConfig,!1,noDefSign)}else if(pageName){var pageConfig=$('#c_p_'+pageType+'s .name[data-val="'+pageName+'"]').parents('tr[id^="'+pageType+'_"]').eq(0).find('[name="config['+pageType+'s][]"]').val();pageConfig=decode_urlbase2json(pageConfig);if(pageConfig){var noDefSign=pageType=='front_url'?true:!1;pageSigns=$_o.$_cp.page_signs(pageConfig,!1,noDefSign)}}
var signListId=$_o.formObj+' #c_p_field_sign_list';$(signListId).html('');var signKeys={area:'区域规则',url:'网址规则',content:'提取内容'};var signInKeys={area:['url','content'],url:['content'],content:null};for(var signKey in signKeys){var curPageSigns=pageSigns[signKey];if(isObject(curPageSigns)&&curPageSigns.length>0){var signHtml='<div style="margin-bottom:5px;">'+signKeys[signKey]+'：';var signInKey=signInKeys[signKey];for(var cpsi in curPageSigns){var curSign=curPageSigns[cpsi];var curSignExist=!1;if(isObject(signInKey)){for(var siki in signInKey){var pageInSigns=pageSigns[signInKey[siki]];if(isObject(pageInSigns)&&pageInSigns.indexOf(curSign)>-1){curSignExist=!0;break}}}
if(curSignExist){signHtml+='<span style="margin-right:7px;color:#999;" title="被覆盖">'+curSign+'</span>'}else{signHtml+='<a href="javascript:;" style="margin-right:7px;" data-val="'+curSign+'">'+curSign+'</a>'}}
signHtml+='</div>';$(signListId).append(signHtml)}}
$(signListId).off('click','a[data-val]').on('click','a[data-val]',function(){globalOp.insertAtCaret($($_o.formObj+' [name="field[sign]"]'),$(this).attr('data-val'))})});$($_o.formObj+' select[name="field[module]"]').bind('change',function(){$($_o.formObj+' .c-p-field-module').hide();$($_o.formObj+' .c-p-field-module[module="'+$(this).val()+'"]').show();var source_module=new Array('rule','xpath','json','auto','sign');var in_module=!1;for(var i in source_module){if($(this).val()==source_module[i]){in_module=!0;break}}
if(in_module){$($_o.formObj+' .c-p-field-source').show()}else{$($_o.formObj+' select[name="field[source]"]').val('');$($_o.formObj+' .c-p-field-source').hide()}});$($_o.formObj+' select[name="field[extract_module]"]').bind('change',function(){$('.c-p-field-extract-module').hide();$('.c-p-field-extract-module[extract-module="'+$(this).val()+'"]').show()});var fieldNames=$_o.$_cp.get_field_names();for(var i in fieldNames){if(fieldData&&fieldData.name==fieldNames[i]){continue}
$($_o.formObj+' #c_p_field_merge_list').append('<a href="javascript:;" style="margin-right:10px;" data-val="[字段:'+fieldNames[i]+']">[字段:'+fieldNames[i]+']</a>');$($_o.formObj+' [name="field[extract]"]').append('<option value="'+fieldNames[i]+'">'+fieldNames[i]+'</option>')}
$($_o.formObj+' #c_p_field_time_format_list').on('click','a[data-val]',function(){globalOp.insertAtCaret($($_o.formObj+' [name="field[time_format]"]'),$(this).attr('data-val'))});$($_o.formObj+' #c_p_field_merge_list').on('click','a[data-val]',function(){globalOp.insertAtCaret($($_o.formObj+' [name="field[merge]"]'),$(this).attr('data-val'))});$.datetimepicker.setLocale('zh');$($_o.formObj+' input[name="field[time_start]"],#form_field input[name="field[time_end]"]').datetimepicker();$($_o.formObj).bind('submit',function(){$_o.add_sub();return!1});ruleInsertSign.cpRuleModuleInit($_o.formObj,'field','');ruleInsertSign.cpRuleModuleInit($_o.formObj,'field','extract_');$($_o.formObj+' .c-p-field-no-reset').bind('click',function(){confirmRight('重置后将以起始数字开始，确定重置？',function(){ajaxOpen({type:'POST',dataType:'json',url:ulink('cpattern/reset_field_no'),data:{task_id:$_o.$_cp.get_task_id(),field_name:$($_o.formObj).find('[name="field[name]"]').val()},success:function(data){if(data.code==1){prompt_success(data.msg)}else{prompt_error(data.msg)}}})})});if(fieldData){for(var i in fieldData){var fieldEle=$($_o.formObj+' [name="field['+i+']"]');if(fieldEle.is('input:text')||fieldEle.is('textarea')){fieldEle.val(fieldData[i])}else if(fieldEle.is('select')){fieldEle.val(fieldData[i]).trigger("change")}}
if(!fieldData.hasOwnProperty('source')){$($_o.formObj+' [name="field[source]"]').trigger("change")}
$($_o.formObj+' [name="field[num_start]"]').val(toInt(fieldData.num_start));$($_o.formObj+' [name="field[num_end]"]').val(toInt(fieldData.num_end));fieldData.no_start=toInt(fieldData.no_start);fieldData.no_inc=toInt(fieldData.no_inc);fieldData.no_len=toInt(fieldData.no_len);$($_o.formObj+' [name="field[no_start]"]').val(fieldData.no_start==0?'':fieldData.no_start);$($_o.formObj+' [name="field[no_inc]"]').val(fieldData.no_inc==0?'':fieldData.no_inc);$($_o.formObj+' [name="field[no_len]"]').val(fieldData.no_len>0?fieldData.no_len:'');$($_o.formObj+' [name="field[auto]"][value="'+fieldData.auto+'"]').prop('checked',!0);if(fieldData.time_stamp){$($_o.formObj+' [name="field[time_stamp]"]').prop('checked',!0)}
ruleInsertSign.cpRuleModuleLoad($_o.formObj,'field','',fieldData);ruleInsertSign.cpRuleModuleLoad($_o.formObj,'field','extract_',fieldData)}},add:function(objid,fieldData,processData){var $_o=this;var fieldSource='内容页';if(fieldData.source){var fsource=fieldData.source.split(':');fieldSource=$_o.$_cp.get_page_vars(fsource[0],'title');if(fsource[1]){fieldSource+='：'+fsource[1]}}
var fieldModule=window.tpl_lang['field_module_'+fieldData.module];var isLoop=!1;if(fieldData.module=='rule'){if(fieldData.rule_multi&&fieldData.rule_multi_type=='loop'){isLoop=!0}}else if(fieldData.module=='xpath'){if(fieldData.xpath_multi&&fieldData.xpath_multi_type=='loop'){isLoop=!0}}else if(fieldData.module=='json'){if(fieldData.json_loop){isLoop=!0}}else if(fieldData.module=='extract'||fieldData.module=='merge'){$($_o.$_cp.formid+' #coll_pattern_field').find('.sort-field').show();if(fieldData.module=='extract'){if(fieldData.extract_module=='rule'){if(fieldData.extract_rule_multi&&fieldData.extract_rule_multi_type=='loop'){isLoop=!0}}else if(fieldData.extract_module=='xpath'){if(fieldData.extract_xpath_multi&&fieldData.extract_xpath_multi_type=='loop'){isLoop=!0}}else if(fieldData.extract_module=='json'){if(fieldData.extract_json_loop){isLoop=!0}}
fieldModule+=' » '+(fieldData.extract?fieldData.extract:'')}}
if(isLoop){$('#c_p_field_loop_tips').show();fieldModule+='（循环入库）'}
if(objid){var eleObj=$($_o.$_cp.formid+' #'+objid);eleObj.find('.field-name').attr('data-val',fieldData.name).text(fieldData.name).attr('title',fieldData.desc);eleObj.find('.field-source').attr('data-val',fieldData.source).text(fieldSource);eleObj.find('.field-module').attr('data-val',fieldData.module).text(fieldModule);if(isLoop){eleObj.find('.field-module').attr('data-is-loop',1)}else{eleObj.find('.field-module').removeAttr('data-is-loop')}
eleObj.find('input[name="config[field_list][]"]').val(encode_json2urlbase(fieldData))}else{var ptitle='';if(processData){ptitle=[];for(var i in processData){ptitle.push(window.tpl_lang['process_module_'+processData[i].module]+(processData[i].title?('：'+processData[i].title):''))}
ptitle=ptitle.join(' / ')}
var html=$_o.$_cp.clone_tpl('#coll_tpl_field');html.attr('id','field_'+generateUUID());html.find('.field-name').attr('data-val',fieldData.name).text(fieldData.name).attr('title',fieldData.desc);html.find('.field-source').attr('data-val',fieldData.source).text(fieldSource);html.find('.field-module').attr('data-val',fieldData.module).text(fieldModule);if(isLoop){html.find('.field-module').attr('data-is-loop',1)}else{html.find('.field-module').removeAttr('data-is-loop')}
html.find('[name="config[field_list][]"]').val(encode_json2urlbase(fieldData));html.find('[name="config[field_process][]"]').val(processData?encode_json2urlbase(processData):'');if(processData&&ptitle){html.find('.field-process').addClass('exist-process')}
html.find('.field-process').attr('title',ptitle);html.find('[name="config[field_title]"]').val(fieldData.name);html.find('[name="config[field_content][]"]').val(fieldData.name);$($_o.$_cp.formid+' #coll_pattern_field .c-p-field-list tbody').append(html)}},add_sub:function(){var $_o=this;var objid=$($_o.formObj+' input[name="objid"]').val();var checkName=!0;if(objid){var fname=$($_o.$_cp.formid+' #'+objid).find('.field-name').attr('data-val');if(fname==$($_o.formObj+' input[name="field[name]"]').val()){checkName=!1}}
if(checkName){var hasName=!1;var fieldNames=$_o.$_cp.get_field_names();for(var i in fieldNames){if($($_o.formObj+' input[name="field[name]"]').val()==fieldNames[i]){hasName=!0;break}}
if(hasName){toastr.error('字段名称已存在！');return!1}}
ajaxOpen({type:'POST',dataType:'json',url:$($_o.formObj).attr('action'),data:$($_o.formObj).serialize(),success:function(data){if(data.code==1){data=data.data;if(data){$_o.add(data.objid,data.field,data.process)}
$('#myModal').modal('hide')}else{toastr.error(data.msg)}},error:function(data){toastr.error(data)}});return!1},clearall:function(){var $_o=this;$($_o.$_cp.formid+' #coll_pattern_field .c-p-field-list tbody').html('')},add_default:function(){var $_o=this;confirmRight('添加默认字段会清除当前字段列表，是否继续？',function(){$_o.clearall();var defFields=new Array({"name":"标题","module":"auto","auto":"title"},{"name":"正文","module":"auto","auto":"content"},{"name":"keywords","module":"auto","auto":"keywords"},{"name":"description","module":"auto","auto":"description"});for(var i in defFields){$_o.add(null,defFields[i],null)}})}}
function CpProcess(cpClass){this.$_cp=cpClass;this.processForm='';this.processBox='';this.processFormField='#form_process';this.processFormCommon='#coll_pattern_process';this.processBoxField='#window_process';this.processBoxCommon='#c_p_process_load'}
CpProcess.prototype={constructor:CpProcess,init:function(processData,isCommon,isCommonLoad){var $_o=this;$_o.processForm=isCommon?$_o.processFormCommon:$_o.processFormField;if(isCommon&&isCommonLoad){$_o.processBox=$_o.processBoxCommon}else{$_o.processBox=$_o.processBoxField}
if($($_o.processForm).is('form')){$($_o.processForm).bind('submit',function(){$_o.add_sub();return!1})}
$($_o.processBox+' .process-add').bind('click',function(){var module=$($_o.processBox+' select[name="process[module]"]').val();$_o.add({'add_new':1,'module':module})});if($($_o.processForm).prop('inited')==1){return!0}
$($_o.processForm).on('click','.p-m-html-tags a[data-val]',function(){var tag=$(this).attr('data-val');var moduleHtml=$(this).parents('.p-m-html-tags').eq(0).attr('module-html');var tagsObj=$(this).parents('section').eq(0).find('input[data-process="html:'+moduleHtml+'"]');var tags=tagsObj.val()+','+tag;tags=tags.replace(/(^,+)|(,+$)/,'');tagsObj.val(tags)});$($_o.processForm).on('change','[data-process="insert:insert_loc"]',function(){var helpEle=$(this).siblings('.help-block');if($(this).val()=='rand'){helpEle.show()}else{helpEle.hide()}});$_o.txt_insert_field($_o.processForm,'.p-m-insert-field',function(sltObj){return $(sltObj).parents('section').eq(0).find('[data-process="insert:insert_txt"]')});globalOp.inputSelectCustom(null,null,{box:$_o.processForm,slt:'[data-process="translate:translate_from"]',ipt:'[data-process="translate:translate_from_custom"]'});globalOp.inputSelectCustom(null,null,{box:$_o.processForm,slt:'[data-process="translate:translate_to"]',ipt:'[data-process="translate:translate_to_custom"]'});$_o.txt_insert_field($_o.processForm,'.p-m-func-field',function(sltObj){return $(sltObj).parents('section').eq(0).find('[data-process="func:func_param"]')});$($_o.processForm).on('click','.p-m-if-add',function(){var ifTable=$(this).parents('section').eq(0).find('.p-m-if-table');ifTable.append('<tr>'+ifTable.attr('data-tpl')+'</tr>')});$($_o.processForm).on('click','.p-m-if-del',function(){var tr=$(this).parents('tr').eq(0);confirmRight('确定删除？',function(){tr.remove()})});$($_o.processForm).on('change','[data-process="if:if_cond:"]',function(){var ifCond=$(this).val();var ifTr=$(this).parents('tr').eq(0);var ifTd=ifTr.find('.p-m-if-val').eq(0);var ifVal=ifTd.find('[data-process="if:if_val:"]').eq(0);var ifValInfo={name:ifVal.attr('name'),val:ifVal.val(),process:ifVal.attr('data-process')};var ifValType='def';if(ifCond=='func'){ifValType='func'}else if(ifCond.indexOf('time_')>-1){ifValType='time'}
ifTd.find('.p-m-if-val-def,.p-m-if-val-time,.p-m-if-val-func').hide();ifTd.find('[data-process="if:if_val:"]').removeAttr('name').removeAttr('data-process');var ifValBox=ifTd.find('.p-m-if-val-'+ifValType);var ifValEle=ifValBox.find('.p-m-if-val-ele');ifValEle.attr('name',ifValInfo.name).attr('data-process',ifValInfo.process).val(ifValInfo.val);ifValBox.show();if(ifValType=='func'){$_o.load_if_func(ifTd,null)}});$($_o.processForm).on('change','.p-m-if-val-time-date select',function(){$(this).parents('tr').eq(0).find('[data-process="if:if_val:"]').val($(this).val())});$($_o.processForm).on('click','.p-m-if-val-func-info',function(){pluginFuncOp.tips('processIf')});$_o.txt_insert_field($_o.processForm,'.p-m-if-val-func-field select',function(sltObj){return $(sltObj).parents('td').eq(0).find('[data-process="if:if_val:"]')});$($_o.processForm).on('click','.p-m-if-info',function(){var tips='<p>执行顺序：从上至下判断，逻辑符“并且”的优先级高于“或者”</p>'+'<p>例如（字母表示条件）：</p>'+'<p>a &amp;&amp; b || c &amp;&amp; d &amp;&amp; e || f || g &amp;&amp; h &amp;&amp; i &amp;&amp; j 等同于</p>'+'<p>(a &amp;&amp; b) || (c &amp;&amp; d &amp;&amp; e) || f || (g &amp;&amp; h &amp;&amp; i &amp;&amp; j)</p>'+'<p>括号中的条件都为真时才是真否则为假，整条语句中任意一个括号的结果为真最终结果为真，都为假最终结果为假</p>';confirmRight({msg:tips,yes:'确定',width:500,textAlign:'left'})});$_o.txt_insert_field($_o.processForm,'.p-m-api-url-field select',function(sltObj){return $(sltObj).parents('section').eq(0).find('[data-process="api:api_url"]')});$($_o.processForm).on('click','.p-m-api-add',function(){var apiTable=$(this).parents('section').eq(0).find('.p-m-api-table table');apiTable.find('tbody').append('<tr>'+apiTable.attr('data-tpl')+'</tr>')});$($_o.processForm).on('click','.p-m-api-del',function(){var tr=$(this).parents('tr').eq(0);tr.remove()});globalOp.inputSelectCustom(null,null,{box:$_o.processForm,slt:'[data-process="api:api_charset"]',ipt:'[data-process="api:api_charset_custom"]'});globalOp.inputSelectCustom(null,null,{box:$_o.processForm,slt:'[data-process="api:api_encode"]',ipt:'[data-process="api:api_encode_custom"]'});$($_o.processForm).on('change','[data-process="api:api_params:val:"],[data-process="api:api_headers:val:"]',function(){var isHeader=!1;if($(this).attr('data-process')=='api:api_headers:val:'){isHeader=!0}
var val=$(this).val();var tdObj=$(this).parents('td').eq(0);var iptObj=tdObj.find('[data-process="api:'+(isHeader?'api_headers':'api_params')+':addon:"]');var sltObj=tdObj.find('.p-m-api-'+(isHeader?'header':'val')+'-field');iptObj.hide();sltObj.hide();if(val=='time'||val=='custom'){if(val=='time'){iptObj.attr('placeholder','默认格式：Y-m-d H:i:s')}else if(val=='custom'){iptObj.attr('placeholder','输入任何内容');sltObj.css('display','table-cell')}
iptObj.show()}});$_o.txt_insert_field($_o.processForm,'.p-m-api-val-field select',function(sltObj){return $(sltObj).parents('td').eq(0).find('[data-process="api:api_params:addon:"]')});$_o.txt_insert_field($_o.processForm,'.p-m-api-header-field select',function(sltObj){return $(sltObj).parents('td').eq(0).find('[data-process="api:api_headers:addon:"]')});$($_o.processForm).on('click','.p-m-api-header-add',function(){var apiHdTable=$(this).parents('section').eq(0).find('.p-m-api-header-table table');apiHdTable.find('tbody').append('<tr>'+apiHdTable.attr('data-tpl')+'</tr>')});$($_o.processForm).on('click','.p-m-api-header-del',function(){var tr=$(this).parents('tr').eq(0);tr.remove()});$($_o.processForm).on('change','[data-process="api:api_type"]',function(){var obj=$(this).parents('section').eq(0).find('.p-m-api-content-type');if($(this).val()=='post'){obj.show()}else{obj.hide()}});$($_o.processForm).on('change','[data-process="api:api_rule_module"]',function(){var ruleModule=$(this).val();ruleModule=ruleModule?ruleModule:'';var obj=$(this).parents('section').eq(0);obj.find('.process-extract-module').hide();obj.find('.process-extract-module[data-rule-module="'+ruleModule+'"]').show()});ruleInsertSign.cpRuleModuleInit($_o.processForm,'data-process','api:api_');$($_o.processForm).on('change','[data-process="extract:extract_module"]',function(){var extractModule=$(this).val();extractModule=extractModule?extractModule:'';var obj=$(this).parents('section').eq(0);obj.find('.process-extract-module').hide();obj.find('.process-extract-module[data-extract-module="'+extractModule+'"]').show()});ruleInsertSign.cpRuleModuleInit($_o.processForm,'data-process','extract:extract_');$($_o.processForm).on('change','[data-process="download:download_op"]',function(){var obj=$(this).parents('section').eq(0);var val=$(this).val();obj.find('.p-m-download-op').hide();obj.find('.p-m-download-op[data-op="'+val+'"]').show()});$($_o.processForm).on('click','.p-m-download-file-tag .dropdown-menu a[data-val]',function(){var prt=$(this).parents('.p-m-download-file-tag').eq(0);var obj=prt.find('[data-process="download:download_file_tag"]');var val=obj.val();if(val){val=val.split(',')}else{val=new Array()}
val.push($(this).attr('data-val'));val=val.join(',');obj.val(val)});$($_o.processForm).on('click','.c-p-process-sign-wildcard',function(){var toObj=$(this).parent().siblings('[data-process]');ruleInsertSign.wildcard(toObj)});$($_o.processForm).on('click','.c-p-process-title',function(){var panelTitle=$(this).parents('.panel[data-name]').eq(0).find('.panel-title-title');if(panelTitle.find('input').is(':visible')){panelTitle.find('*').show();panelTitle.find('input').hide()}else{panelTitle.find('*').hide();panelTitle.find('input').show()}});$($_o.processForm).on('click','.c-p-process-close',function(){var prtBox=$(this).parents('.panel[data-name]').eq(0);var closeObj=prtBox.find('.panel-title-ops').find('input[name$="[close]"]');var closeVal=toInt(closeObj.val());if(closeVal>0){closeObj.val(0);$(this).attr('title','禁用').removeClass('c-p-process-closed');prtBox.removeClass('wrapper-not-enable')}else{closeObj.val(1);$(this).attr('title','已禁用').addClass('c-p-process-closed');prtBox.addClass('wrapper-not-enable')}});(function(processForm,processBox){$(processForm).on('click','.c-p-process-clone',function(){var panelObj=$(this).parents('.panel[data-name^="process"]').eq(0);var formEle=document.createElement('form');$(formEle).append(panelObj.clone());$(panelObj).find('[name^="process"]').each(function(index){var processEle=$(formEle).find('[name^="process"]').eq(index);if($(this).is('input:radio')||$(this).is('input:checkbox')){processEle.prop('checked',$(this).is(':checked'))}else{processEle.val($(this).val())}});confirmRight({msg:'拷贝或复制数据处理',yes:'复制',no:'拷贝',close:!0},function(){ajaxOpen({type:'POST',dataType:'json',url:ulink('cpattern/clone_process'),data:$(formEle).serialize(),success:function(data){if(data.code==1){$_o.processForm=processForm;$_o.processBox=processBox;$_o.add(data.data);toastr.success(data.msg)}}})},function(){ajaxOpen({type:'POST',dataType:'json',url:ulink('cpattern/clone_process?op=copy'),data:$(formEle).serialize(),success:function(data){if(data.code==1){toastr.success(data.msg)}}})})})})($_o.processForm,$_o.processBox);$($_o.processForm).on('click','.c-p-process-del',function(){$_o.del(this)});globalOp.eleExchange($_o.processForm+' .c-p-process-accordion','.panel-title-ops .icon-drag-move','.panel');if(processData){for(var i in processData){if(processData[i]){$_o.add(processData[i])}}}
$($_o.processForm).prop('inited',1)},add_sub:function(){var $_o=this;ajaxOpen({type:'POST',dataType:'json',url:$($_o.processForm).attr('action'),data:$($_o.processForm).serialize(),success:function(data){if(data.code==1){$('#myModal').modal('hide');if(data.data&&data.data.objid){$($_o.$_cp.formid+' #'+data.data.objid).find('input[name="config[field_process][]"]').val(data.data.process_json?url_base64encode(data.data.process_json):'');var ptitle='';var processData=data.data.process;if(processData){ptitle=[];for(var i in processData){ptitle.push(window.tpl_lang['process_module_'+processData[i].module]+(processData[i].title?('：'+processData[i].title):''))}
ptitle=ptitle.join(' / ')}
if(processData&&ptitle){$($_o.$_cp.formid+' #'+data.data.objid).find('.field-process').addClass('exist-process').attr('title',ptitle)}else{$($_o.$_cp.formid+' #'+data.data.objid).find('.field-process').removeClass('exist-process').attr('title','')}}}else{toastr.error(data.msg)}},error:function(data){toastr.error(data)}});return!1},del:function(obj){var $_o=this;confirmRight('是否删除？',function(){$(obj).parents('.panel').eq(0).remove()})},load_if_func:function(box,setVal){var $_o=this;pluginFuncOp.load({module:'processIf',boxObj:box,funcObj:'[data-process="if:if_addon:func:"]',paramObj:'[data-process="if:if_val:"]',funcVal:setVal,cache:!0})},add:function(params){var $_o=this;params=params?params:{};if(!params.module){toastr.error('请选择处理方式');return!1}
params.module=htmlspecialchars(params.module);params.title=params.title?htmlspecialchars(params.title):'';var parentid=$($_o.processForm+' .c-p-process-accordion').attr('id');if(!parentid){parentid='p_accordion_'+generateUUID();$($_o.processForm+' .c-p-process-accordion').attr('id',parentid)}
var dataParent=parentid?('data-parent="#'+parentid+'"'):'';var moduleHtml=$($_o.processBox+' .c-p-process-module[module="'+params.module+'"]').html();if(params.module=='html'){moduleHtml=moduleHtml.replace(/p_m_html_allow/ig,'p_m_html_allow_'+generateUUID());moduleHtml=moduleHtml.replace(/p_m_html_filter/ig,'p_m_html_filter_'+generateUUID())}
var processName='process[i_'+generateUUID()+']';moduleHtml='<input type="hidden" name="'+processName+'[module]" value="'+params.module+'" />'+moduleHtml;var collapseId='p_collapse_'+generateUUID();var html=$_o.$_cp.clone_tpl('#coll_tpl_process',processName);html.attr('data-name',processName);html.find('a[data-toggle="collapse"]').attr('data-parent','#'+parentid).attr('href','#'+collapseId);if(params.title){html.find('.panel-title > a[data-toggle="collapse"]').text(window.tpl_lang['process_module_'+params.module]+'：');html.find('.panel-title-title > a[data-toggle="collapse"]').text(params.title).show()}else{html.find('.panel-title > a[data-toggle="collapse"]').text(window.tpl_lang['process_module_'+params.module]);html.find('.panel-title-title > a[data-toggle="collapse"]').hide()}
html.find('.panel-title-title input[name$="[title]"]').val(params.title?params.title:'');html.find('.panel-title-ops input[name$="[close]"]').val(params.close?params.close:'');html.find('.panel-collapse').attr('id',collapseId);if(toInt(params.close)>0){html.find('.c-p-process-close').attr('title','已禁用').addClass('c-p-process-closed');html.addClass('wrapper-not-enable')}
if(params.add_new){html.find('.panel-collapse').addClass('in')}
html.find('.panel-body').html(moduleHtml);$($_o.processForm+' .c-p-process-accordion').append(html);$($_o.processForm).show();var curCollapse=$_o.processForm+' #'+collapseId;$(curCollapse).find('[data-process]').each(function(){var eleName=$(this).attr('data-process').split(':');eleName[1]=processName+'['+eleName[1]+']';if(eleName.length>=3){eleName[1]+=eleName[2]?('['+eleName[2]+']'):'[]'}
if(eleName.length>=4){eleName[1]+=eleName[3]?('['+eleName[3]+']'):'[]'}
$(this).attr('name',eleName[1])});if(params.module=='html'){$(curCollapse).find('[data-process="html:html_allow"]').val(params.html_allow?params.html_allow:'');$(curCollapse).find('[data-process="html:html_filter"]').val(params.html_filter?params.html_filter:'');if(params.html_filter){$(curCollapse).find('a[href^="#p_m_html_filter"]').tab('show')}}else if(params.module=='insert'){$(curCollapse).find('[data-process="insert:insert_loc"]').val(params.insert_loc?params.insert_loc:'').trigger('change');$(curCollapse).find('[data-process="insert:insert_txt"]').val(params.insert_txt?params.insert_txt:'')}else if(params.module=='replace'){$(curCollapse).find('[data-process="replace:replace_from"]').val(params.replace_from?params.replace_from:'');$(curCollapse).find('[data-process="replace:replace_to"]').val(params.replace_to?params.replace_to:'')}else if(params.module=='filter'){$(curCollapse).find('[data-process="filter:filter_list"]').val(params.filter_list?params.filter_list:'');$(curCollapse).find('[data-process="filter:filter_replace"]').val(params.filter_replace?params.filter_replace:'');$(curCollapse).find('[data-process="filter:filter_pass"][value="'+params.filter_pass+'"]').prop('checked',!0)}else if(params.module=='tool'){$(curCollapse).find('[data-process="tool:tool_list"]').attr('name',processName+'[tool_list][]');if(params.tool_list){for(var ti in params.tool_list){$(curCollapse).find('[data-process="tool:tool_list"][value="'+params.tool_list[ti]+'"]').prop('checked',!0)}}}else if(params.module=='download'){$(curCollapse).find('[data-process="download:download_op"]').val(params.download_op?params.download_op:'').trigger('change');$(curCollapse).find('[data-process="download:download_file_tag"]').val(params.download_file_tag?params.download_file_tag:'');$(curCollapse).find('[data-process="download:download_file_must"]').val(params.download_file_must?params.download_file_must:'');$(curCollapse).find('[data-process="download:download_file_ban"]').val(params.download_file_ban?params.download_file_ban:'')}else if(params.module=='translate'){$(curCollapse).find('[data-process="translate:translate_from"]').val(params.translate_from?params.translate_from:'').trigger('change');$(curCollapse).find('[data-process="translate:translate_to"]').val(params.translate_to?params.translate_to:'').trigger('change');$(curCollapse).find('[data-process="translate:translate_from_custom"]').val(params.translate_from_custom?params.translate_from_custom:'');$(curCollapse).find('[data-process="translate:translate_to_custom"]').val(params.translate_to_custom?params.translate_to_custom:'')}else if(params.module=='batch'){$(curCollapse).find('[data-process="batch:batch_list"]').val(params.batch_list?params.batch_list:'');$(curCollapse).find('[data-process="batch:batch_sign"]').val(params.batch_sign?params.batch_sign:'')}else if(params.module=='substr'){$(curCollapse).find('[data-process="substr:substr_len"]').val(params.substr_len?params.substr_len:'');$(curCollapse).find('[data-process="substr:substr_end"]').val(params.substr_end?params.substr_end:'')}else if(params.module=='func'){$(curCollapse).find('[data-process="func:func_param"]').val(params.func_param?params.func_param:'');pluginFuncOp.load({module:'process',boxObj:$(curCollapse),funcObj:'[data-process="func:func_name"]',paramObj:'[data-process="func:func_param"]',funcVal:params.func_name,cache:!0})}else if(params.module=='if'){var ifTrTpl=$(curCollapse).find('.p-m-if-table-tpl');var ifTable=$(curCollapse).find('.p-m-if-table');ifTable.attr('data-tpl',ifTrTpl.html());ifTrTpl.remove();if(params.if_type){$(curCollapse).find('[data-process="if:if_type"]').val(params.if_type)}
if(params.if_stop){$(curCollapse).find('[data-process="if:if_stop"]').val(params.if_stop)}
if(params.if_logic&&params.if_cond&&params.if_val){params.if_addon=params.if_addon?params.if_addon:{};for(var i in params.if_logic){ifTable.find('tbody').append('<tr data-if-id="'+i+'">'+ifTable.attr('data-tpl')+'</tr>');var curIfTr=ifTable.find('tr[data-if-id="'+i+'"]');curIfTr.find('[data-process="if:if_logic:"]').val(params.if_logic[i]);curIfTr.find('[data-process="if:if_cond:"]').val(params.if_cond[i]).trigger('change');curIfTr.find('[data-process="if:if_val:"]').val(params.if_val[i]);if(params.if_cond[i]=='func'){var ifFuncVal='';if(params.if_addon.func){ifFuncVal=params.if_addon.func[i]}
$_o.load_if_func(curIfTr,ifFuncVal);if(params.if_addon.turn){curIfTr.find('[data-process="if:if_addon:turn:"]').val(params.if_addon.turn[i])}}}}
globalOp.eleExchange(curCollapse+' .p-m-if-table','.icon-drag-move','tbody tr')}else if(params.module=='api'){var apiTrTpl=$(curCollapse).find('.p-m-api-table-tpl');var apiTable=$(curCollapse).find('.p-m-api-table table');apiTable.attr('data-tpl',apiTrTpl.html());apiTrTpl.remove();var apiHdTrTpl=$(curCollapse).find('.p-m-api-header-table-tpl');var apiHdTable=$(curCollapse).find('.p-m-api-header-table table');apiHdTable.attr('data-tpl',apiHdTrTpl.html());apiHdTrTpl.remove();if(params.api_params){params.api_params.name=params.api_params.name?params.api_params.name:{};params.api_params.val=params.api_params.val?params.api_params.val:{};params.api_params.addon=params.api_params.addon?params.api_params.addon:{};for(var i in params.api_params.name){var trId='p-m-api-param_'+generateUUID();var trTpl='<tr id="'+trId+'">'+apiTable.attr('data-tpl')+'</tr>';apiTable.find('tbody').append(trTpl);apiTable.find('#'+trId+' [data-process="api:api_params:name:"]').val(params.api_params.name[i]);apiTable.find('#'+trId+' [data-process="api:api_params:val:"]').val(params.api_params.val[i]?params.api_params.val[i]:'').trigger('change');apiTable.find('#'+trId+' [data-process="api:api_params:addon:"]').val(params.api_params.addon[i]?params.api_params.addon[i]:'')}}
if(params.api_headers){params.api_headers.name=params.api_headers.name?params.api_headers.name:{};params.api_headers.val=params.api_headers.val?params.api_headers.val:{};params.api_headers.addon=params.api_headers.addon?params.api_headers.addon:{};for(var i in params.api_headers.name){var trId='p-m-api-header_'+generateUUID();var trTpl='<tr id="'+trId+'">'+apiHdTable.attr('data-tpl')+'</tr>';apiHdTable.find('tbody').append(trTpl);apiHdTable.find('#'+trId+' [data-process="api:api_headers:name:"]').val(params.api_headers.name[i]);apiHdTable.find('#'+trId+' [data-process="api:api_headers:val:"]').val(params.api_headers.val[i]?params.api_headers.val[i]:'').trigger('change');apiHdTable.find('#'+trId+' [data-process="api:api_headers:addon:"]').val(params.api_headers.addon[i]?params.api_headers.addon[i]:'')}}
params.api_json_arr=params.api_json_arr?params.api_json_arr:'implode';for(var i in params){if(isObject(params[i])){continue}
$(curCollapse).find('[data-process="api:'+i+'"]').val(params[i]?params[i]:'')}
$(curCollapse).find('[data-process="api:api_type"]').trigger('change');$(curCollapse).find('[data-process="api:api_charset"]').trigger('change');$(curCollapse).find('[data-process="api:api_encode"]').trigger('change');$(curCollapse).find('[data-process="api:api_rule_module"]').trigger('change');ruleInsertSign.cpRuleModuleLoad(curCollapse,processName,'api_',params)}else if(params.module=='apiapp'){pluginApiOp.load({module:'process',boxObj:$(curCollapse),appObj:'[data-process="apiapp:apiapp_app"]',appApp:params.apiapp_app,appConfig:params.apiapp_config,namePre:processName+'[apiapp_config]',cache:!0})}else if(params.module=='extract'){$(curCollapse).find('[data-process="extract:extract_module"]').val(params.extract_module).trigger('change');ruleInsertSign.cpRuleModuleLoad(curCollapse,processName,'extract_',params)}
if($_o.processForm!=$_o.processFormField){$('#myModal').modal('hide')}},txt_insert_field:function(boxEle,sltEle,txtObjFunc){var $_o=this;$(boxEle).on('mouseover',sltEle,function(){if(!$(this).attr('data-loaded')){var fieldNames=$_o.$_cp.get_field_names(!0);var html='<option value="">插入字段</option><option value="###">###表示当前字段</option>';if(fieldNames){var formField=$(this).parents($_o.processFormField).eq(0).find('[name="field"]').val();if(formField){for(var i=0;i<fieldNames.length;i++){var curField=fieldNames[i];if(formField&&formField==curField){if(i<fieldNames.length-1){html+='<optgroup label="不能调用当前字段顺序后面的字段，可移动字段位置使之生效"></optgroup>'}
break}
html+='<option value="[字段:'+curField+']">字段：'+curField+'</option>'}}else{html+='<optgroup label="通用数据处理仅支持调用当前字段"></optgroup>'}}
$(this).html(html);$(this).attr('data-loaded',1)}});$($_o.processForm).on('mouseout',sltEle,function(){$(this).removeAttr('data-loaded')});$($_o.processForm).on('change',sltEle,function(){var val=$(this).val();$(this).val('');if(val&&txtObjFunc){var txtObj=txtObjFunc(this);globalOp.insertAtCaret(txtObj,val)}})}}
function CpContentSign(cpClass){this.$_cp=cpClass;this.formObj='#form_content_sign';this.curPageType='';this.curPageConfig={}}
CpContentSign.prototype={constructor:CpContentSign,page_init:function(pageType){var $_o=this;var pageVars=$_o.$_cp.get_page_vars(pageType);var boxId=pageVars.boxId;var namePre=pageVars.namePre;var formId=pageVars.formId;if(!boxId||!namePre){return}
boxId+='_content_sign';var editFunc=function(postData){window.modal_scroll_top=$('#myModal').scrollTop();if(!isObject(postData)){postData={}}
postData.page_type=pageType;if($_o.$_cp.page_is_list(pageType)){postData.page_config=$(formId).serialize()}
var options={};options.ajax={type:'post',data:postData};windowModal('添加内容标签',ulink("cpattern/content_sign"),options)};$(boxId+' .add-url-content-sign').bind('click',function(){editFunc(null)});$(boxId+' .c-p-url-content-signs').on('click','[data-content-sign]',function(){var parent=$(this).parents('[id^="content_sign_"]').eq(0);var objid=parent.attr('id');var postData={};postData.objid=objid;postData.content_sign=parent.find('[name="'+namePre+'[content_signs][]"]').val();editFunc(postData)});$(boxId+' .c-p-url-content-signs').on('click','.delete',function(){var parent=$(this).parents('[id^="content_sign_"]').eq(0);confirmRight('确定删除？',function(){parent.remove()})})},page_load:function(pageType,contentSigns){var $_o=this;var pageVars=$_o.$_cp.get_page_vars(pageType);var boxId=pageVars.boxId;if(!boxId){return}
boxId+='_content_sign';if(isObject(contentSigns)&&contentSigns.length>0){for(var i in contentSigns){$_o.page_add(pageType,'',contentSigns[i])}
globalOp.showPanelCollapse(boxId)}},page_add:function(pageType,objid,contentSign){if(!isObject(contentSign)){return}
var $_o=this;var pageVars=$_o.$_cp.get_page_vars(pageType);var boxId=pageVars.boxId;var namePre=pageVars.namePre;if(!boxId||!namePre){return}
boxId+='_content_sign';if(contentSign._objid){objid=contentSign._objid;delete contentSign._objid}
var signName=window.tpl_lang.sign_match.replace('{:id}',htmlspecialchars(contentSign.identity));var tpl='<a href="javascript:;" data-content-sign="__ident__">__name__</a><em class="glyphicon glyphicon-remove-circle delete"></em><input type="hidden" name="'+namePre+'[content_signs][]" value="__val__" />';tpl=tpl.replace(/__ident__/ig,htmlspecialchars(contentSign.identity)).replace(/__name__/ig,signName).replace(/__val__/ig,encode_json2urlbase(contentSign));var eleId='content_sign_'+pageType+'_'+url_base64encode(contentSign.identity);if(!objid){$('#'+eleId).remove()}
if(!document.getElementById(eleId)){$(boxId+' .c-p-url-content-signs').append('<div class="param-label" id="'+eleId+'"></div>')}
$('#'+eleId).html(tpl);if(objid&&objid!=eleId){if(document.getElementById(objid)){$('#'+objid).after($('#'+eleId));$('#'+objid).remove()}}},init:function(contentSign,pageType,pageConfig){var $_o=this;var namePre=$_o.$_cp.get_page_vars(pageType,'namePre');if(!namePre){return}
$($_o.formObj).bind('submit',function(){$_o.add_sub();return!1});if(!isObject(pageConfig)){pageConfig={}}
if(!isObject(pageConfig[namePre])){pageConfig[namePre]={}}
$_o.curPageType=pageType;$_o.curPageConfig=pageConfig;if($_o.$_cp.page_is_list($_o.curPageType)){$('#myModal').on('hidden.bs.modal',function(e){if($_o.$_cp.page_is_list($_o.curPageType)){var curPageVars=$_o.$_cp.get_page_vars($_o.curPageType);var namePre=curPageVars.namePre;var options={'ajax_scroll_top':window.modal_scroll_top,lg:1,ajax:{type:'post',data:{}}};options.ajax.data.objid=$_o.curPageConfig.objid;options.ajax.data[namePre]=encode_json2urlbase($_o.curPageConfig[namePre]);windowModal('编辑'+curPageVars.title+'规则',ulink('cpattern/'+$_o.curPageType),options)}})}
$($_o.formObj+' select[name="content_sign[module]"]').bind('change',function(){$($_o.formObj+' .c-p-content-sign-module').hide();$($_o.formObj+' .c-p-content-sign-module[data-module="'+$(this).val()+'"]').show()});$($_o.formObj+' #c_p_content_sign_add_func').bind('click',function(){$_o.add_func(null)});pluginFuncOp.initHtml($_o.formObj+' #c_p_content_sign_funcs');ruleInsertSign.cpRuleModuleInit($_o.formObj,'content_sign','');if(contentSign){$($_o.formObj+' [name="objid"]').attr('data-identity',contentSign.identity);for(var i in contentSign){var csEle=$($_o.formObj+' [name="content_sign['+i+']"]');if(csEle.is('input:text')){csEle.val(contentSign[i])}else if(csEle.is('select')){csEle.val(contentSign[i]).trigger("change")}}
ruleInsertSign.cpRuleModuleLoad($_o.formObj,'content_sign','',contentSign);if(isObject(contentSign.funcs)){for(var i in contentSign.funcs){$_o.add_func(contentSign.funcs[i])}}}},add_func:function(contentSignFunc){var $_o=this;pluginFuncOp.addHtml({funcData:contentSignFunc,funcName:'content_sign[funcs][{id}][func]',funcParamName:'content_sign[funcs][{id}][func_param]',tplId:'c_p_content_sign_tpl_func',listId:'c_p_content_sign_funcs',funcId:'c_p_content_sign_func_{id}'},'contentSign')},add_sub:function(){var $_o=this;ajaxOpen({type:'POST',dataType:'json',url:$($_o.formObj).attr('action'),data:$($_o.formObj).serialize(),success:function(data){if(data.code==1){data=data.data;if(data&&data.content_sign){var contentSign=data.content_sign;if($_o.$_cp.page_is_list($_o.curPageType)){var namePre=$_o.$_cp.get_page_vars($_o.curPageType,'namePre');var pageTypeConfig=$_o.curPageConfig[namePre];if(!isObject(pageTypeConfig.content_signs)){pageTypeConfig.content_signs=[]}
contentSign._objid=data.objid;pageTypeConfig.content_signs.push(contentSign);$_o.curPageConfig[namePre]=pageTypeConfig}else{$_o.page_add($_o.curPageType,data.objid,contentSign)}}
$('#myModal').modal('hide')}else{toastr.error(data.msg)}},error:function(data){toastr.error(data)}});return!1}}