/*
 |--------------------------------------------------------------------------
 | SkyCaiji (蓝天采集器)
 |--------------------------------------------------------------------------
 | Copyright (c) 2018 https://www.skycaiji.com All rights reserved.
 |--------------------------------------------------------------------------
 | 使用协议  https://www.skycaiji.com/licenses
 |--------------------------------------------------------------------------
 */
'use strict';function ReleaseClass(formid,releid){this.formid='#'+formid;this.releid=releid;this.curFocusResIpt=''}
ReleaseClass.prototype={constructor:ReleaseClass,init:function(){var $_o=this;$($_o.formid).bind('submit',function(){var module=$($_o.formid+' select[name="module"]').val();if(module=='diy'&&$_o.has_diy_editor()){var diyCode=globalOp.editorCodeIfr('#diy_editor_ifr',{'get_value':1});if(diyCode){$($_o.formid+' [name="diy[code]"]').val(diyCode)}}
var settings=getFormAjaxSettings($(this));settings.data={'_post_data_':settings.data};ajaxOpen(settings);return!1});$($_o.formid+' select[name="module"]').bind('change',function(){var module=$(this).val();$($_o.formid+' .rele-module').hide();$($_o.formid+' .rele-module[module="'+module+'"]').show()});$('#rele_module_dataset #btn_dataset_list').bind('click',function(){windowModal('数据集',ulink('dataset/select?from=release'))});$('#rele_module_dataset #btn_dataset_create').bind('click',function(){confirmRight('确定自动创建数据集？',function(){$($_o.formid+' [name="dataset[auto_create]"]').val(1);$($_o.formid).trigger('submit')})});$('#rele_module_cms .btn-cms-detect').bind('click',function(){$_o.cms_detect()});$('#rele_module_cms .btn-cms-bind').bind('click',function(){$_o.cms_bind()});$('#rele_module_cms').on('change','select[name="cms[app]"]',function(){var cmsApp=$(this).val();$_o.cms_bind({cms:{app:cmsApp}})});$('#cms_list').on('click','li a',function(){var path=$(this).attr('path');if(path){$($_o.formid+' [name="cms[path]"]').val(path);$('#cms_tab a[href="#cms_tab_bind"]').tab('show');$_o.cms_bind()}});globalOp.inputSelectCustom(null,null,{box:'#rele_module_cms',slt:'select[name^="cms_app[param]"]',ipt:'input[name^="cms_app[custom]"]'},'custom:');$('#db_tab_config .dm-db-charset li span').bind('click',function(){var charset=$(this).attr('data-val');charset=charset?charset:'';$('#db_tab_config [name="db[charset]"]').val(charset)});$('#db_tab_config .btn-db-names').bind('click',function(){$_o.db_connect('db_names')});$('#db_tab_config .btn-db-connect').bind('click',function(){$_o.db_connect()});$('#rele_module_file').on('click','.btn-file-rand-path',function(){var randStr=$_o.rand_str(10);$($_o.formid+' [name="file[path]"]').val(randStr)});$('#rele_module_api').on('click','.btn-api-rand-url',function(){var randStr=$_o.rand_str(10);$($_o.formid+' [name="api[key]"]').val(randStr)});$('#diy_tab').on('click','[data-type]',function(){var type=$(this).attr('data-type');$($_o.formid+' [name="diy[type]"]').val(type);if(type=='code'&&$_o.has_diy_editor()){var diyCode=$($_o.formid+' [name="diy[code]"]').val();diyCode=diyCode?diyCode:'';globalOp.editorCodeIfr('#diy_editor_ifr',{'set_value':diyCode})}});$('#toapi_tab').on('click','[data-module]',function(){var module=$(this).attr('data-module');$($_o.formid+' [name="toapi[module]"]').val(module)});$('#rele_module_toapi').on('change','[name="toapi[type]"]',function(){if($(this).val()=='post'){$('#rele_module_toapi .toapi-content-type').show()}else{$('#rele_module_toapi .toapi-content-type').hide()}});$('#rele_module_toapi').on('click','.toapi-add-param',function(){$_o.toapi_add_param(null,null)});$('#rele_module_toapi').on('click','.toapi-del-param',function(){$(this).parents('tr').eq(0).remove()});$('#rele_module_toapi').on('click','.toapi-field-txt a[data-val]',function(){globalOp.insertAtCaret($(this).parents('.toapi-field-txt').eq(0).find('input:text,textarea').eq(0),$(this).attr('data-val'))});globalOp.inputSelectCustom('#rele_module_toapi [name="toapi[charset]"]','toapi[charset_custom]');globalOp.inputSelectCustom('#rele_module_toapi [name="toapi[encode]"]','toapi[encode_custom]');$('#rele_module_toapi').on('click','.toapi-add-header',function(){$_o.toapi_add_header(null,null)});$('#rele_module_toapi').on('click','.toapi-del-header',function(){$(this).parents('tr').eq(0).remove()});$('#toapi_url_field').bind('change',function(){var val=$(this).val();$(this).val('');globalOp.insertAtCaret($('#rele_module_toapi [name="toapi[url]"]'),val)});$('#toapi_app_url_field').bind('change',function(){var val=$(this).val();$(this).val('');globalOp.insertAtCaret($('#rele_module_toapi [name="toapi[app_url]"]'),val)});$($_o.formid).find('[name="toapi[response][module]"]').bind('change',function(){var module=$(this).val();var resNames=['id','target','desc','error'];for(var i in resNames){var obj=$($_o.formid).find('[name="toapi[response]['+resNames[i]+']"]');var objPh=obj.attr('data-placeholder');if(!module){objPh+='，默认：'+resNames[i]}
obj.attr('placeholder',objPh);$('#toapi_resp_module_help').find('[data-module]').hide();$('#toapi_resp_module_help').find('[data-module="'+module+'"]').show()}});$($_o.formid).find('input[name^="toapi[response]"]').bind('focus',function(){$_o.curFocusResIpt=$(this).attr('name')});$('#toapi_resp_module_help').find('[data-rule-sign]').bind('click',function(){var curName=$_o.curFocusResIpt?$_o.curFocusResIpt:'toapi[response][id]';var ruleSign=$(this).attr('data-rule-sign');if(ruleSign=='sign_wildcard'){ruleInsertSign.wildcard('[name="'+curName+'"]')}else if(ruleSign=='sign_match'){ruleInsertSign.match('[name="'+curName+'"]')}else if(ruleSign=='sign_group'){ruleInsertSign.match('[name="'+curName+'"]',{group:1})}});$('#btn_toapi_app').bind('click',function(){$('#toapi_app_params').html('<div class="loading" style="margin-bottom:20px;"></div>');ajaxOpen({type:'post',url:ulink("release/toapiApp"),data:{'task_id':$($_o.formid+' [name="task_id"]').val(),'app_url':$('#rele_module_toapi [name="toapi[app_url]"]').val()},success:function(data){$('#toapi_app_params').html('');if(dataIsJson(data)){var html=data.data?data.data.html:'';if(html){modal('<b>'+data.msg+'<b>',html)}else{ajaxDataMsg(data)}}else{$('#toapi_app_params').html(data)}},error:function(){$('#toapi_app_params').html('')}})});$('#toapi_tab a[href="#toapi_tab_app"]').bind('click',function(){ajaxOpen({type:'get',url:ulink("release/toapiApp?task_id=_id_",{'_id_':$($_o.formid+' [name="task_id"]').val()}),success:function(data){if(dataIsJson(data)){ajaxDataMsg(data)}else{$('#toapi_app_params').html(data)}}})});$('#btn_rele_test').bind('click',function(){globalOp.collectorWindow('测试','admin/release/test?id='+$_o.releid,null,{lg:1})})},load:function(data){var $_o=this;if(data.module){$($_o.formid+' select[name="module"]').val(data.module).trigger('change')}
if(data.config){if('dataset'==data.module){$_o.dataset_load(data.config.dataset)}else if('cms'==data.module){$_o.cms_bind(data.config);$(document).ready(function(){$('#cms_tab a[href="#cms_tab_bind"]').tab('show')})}else if('db'==data.module){$_o.db_bind(data.config)}else if('file'==data.module){if(data.config.file){$($_o.formid+' [name="file[path]"]').val(data.config.file.path);$($_o.formid+' [name="file[type]"]').each(function(){if($(this).val()==data.config.file.type){$(this).prop('checked',!0)}});$($_o.formid+' [name="file[txt_implode]"]').val(data.config.file.txt_implode);$($_o.formid+' [name="file[max_line]"]').val(toInt(data.config.file.max_line));if(data.config.file.hide_fields){for(var fi in data.config.file.hide_fields){$($_o.formid+' [name="file[hide_fields][]"][value="'+data.config.file.hide_fields[fi]+'"]').prop('checked',!0)}}}}else if('api'==data.module){if(data.config.api){$($_o.formid+' [name="api[key]"]').val(data.config.api.key);$($_o.formid+' [name="api[cache_time]"]').val(data.config.api.cache_time);if(data.config.api.hide_fields){for(var fi in data.config.api.hide_fields){$($_o.formid+' [name="api[hide_fields][]"][value="'+data.config.api.hide_fields[fi]+'"]').prop('checked',!0)}}}}else if('diy'==data.module){if(data.config.diy){$(document).ready(function(){$('#diy_tab a[href="#diy_tab_'+data.config.diy.type+'"]').tab('show').trigger('click');for(var i in data.config.diy){$($_o.formid+' [name="diy['+i+']"]').val(data.config.diy[i])}
if(data.config.diy.app){var appName=data.config.diy.app;if(appName.length>1){appName=appName.substr(0,1).toUpperCase()+appName.substr(1).toLowerCase()}else{appName=appName.toUpperCase()}
$($_o.formid+' [name="diy[app]"]').parent().find('.diy-app-name').text(appName+'.php');$($_o.formid+' [name="diy[app]"]').parent().find('.diy-app-editor').show().find('.btn_diy_editor').attr('href',ulink('develop/editor?type=release&module=diy&app=_app_',{'_app_':appName}))}
if($_o.has_diy_editor()&&data.config.diy.code){globalOp.editorCodeIfr('#diy_editor_ifr',{'set_value':data.config.diy.code})}})}}else if('toapi'==data.module){var config=data.config.toapi;if(config){$($_o.formid+' [name="toapi[module]"]').val(config.module);$($_o.formid+' [name="toapi[url]"]').val(config.url);$($_o.formid+' [name="toapi[type]"]').val(config.type).trigger('change');$($_o.formid+' [name="toapi[content_type]"]').val(config.content_type);$($_o.formid+' [name="toapi[charset_custom]"]').val(config.charset_custom);$($_o.formid+' [name="toapi[charset]"]').val(config.charset).trigger('change');$($_o.formid+' [name="toapi[encode_custom]"]').val(config.encode_custom);$($_o.formid+' [name="toapi[encode]"]').val(config.encode).trigger('change');if(config.response){for(var i in config.response){$($_o.formid+' [name="toapi[response]['+i+']"]').val(config.response[i])}}
$($_o.formid+' [name="toapi[response][module]"]').trigger('change');if(config.param_name){config.param_val=config.param_val?config.param_val:{};for(var i in config.param_name){var pname=config.param_name[i]?config.param_name[i]:'';var pval=config.param_val[i]?config.param_val[i]:'';$_o.toapi_add_param({name:pname,val:pval},i)}}
if(config.header_name){config.header_val=config.header_val?config.header_val:{};for(var i in config.header_name){var hname=config.header_name[i]?config.header_name[i]:'';var hval=config.header_val[i]?config.header_val[i]:'';$_o.toapi_add_header({name:hname,val:hval},i)}}
$($_o.formid+' [name="toapi[app_url]"]').val(config.app_url);config.interval=toInt(config.interval);config.wait=toInt(config.wait);config.retry=toInt(config.retry);$($_o.formid+' [name="toapi[interval]"]').val(config.interval);$($_o.formid+' [name="toapi[wait]"]').val(config.wait);$($_o.formid+' [name="toapi[retry]"]').val(config.retry);$(document).ready(function(){$('#toapi_tab a[href="#toapi_tab_'+config.module+'"]').tab('show').trigger('click');if(config.interval>0||config.wait>0||config.retry>0){globalOp.showPanelCollapse('#panel_toapi')}})}}}},dataset_load:function(dsConfig){var $_o=this;dsConfig=isObject(dsConfig)?dsConfig:{};var dsId=toInt(dsConfig.dataset_id);if(dsId>0){ajaxOpen({url:ulink('release/dataset?ds_id='+dsId+'&task_id='+$($_o.formid+' [name="task_id"]').val()),dataType:'html',success:function(html){$('#dataset_config').show();$('#myModal').modal('hide');$('#dataset_config').html(html);$('#dataset_config .dataset-field-txt a[data-val]').bind('click',function(){globalOp.insertAtCaret($(this).parents('.dataset-field-txt').eq(0).find('input[name^="dataset[fields]"]'),$(this).attr('data-val'))});if(isObject(dsConfig.fields)){for(var i in dsConfig.fields){$('#dataset_config').find('[name="dataset[fields]['+i+']"]').val(dsConfig.fields[i]?dsConfig.fields[i]:'')}}}})}},cms_detect:function(){var $_o=this;$('#cms_list').html('').addClass('loading');ajaxOpen({type:'get',url:ulink("release/cmsDetect"),dataType:'json',success:function(data){$('#cms_list').removeClass('loading');if(data.code==1){var html='<p>点击选择CMS</p>';for(var x in data.data){var list=data.data[x];html+='<label>'+x+'</label><ul>';for(var y in list){html+='<li><a href="javascript:;" path="'+list[y]+'">'+list[y]+'</a></li>'}
html+='</ul>'}
$('#cms_list').html(html)}else{$('#cms_list').html(data.msg)}}})},cms_bind:function(config){var $_o=this;$('#cms_bind').html('').addClass('loading');var postData=$($_o.formid).serialize();if(config&&config.cms&&config.cms.app){postData='cms[app]='+encodeURIComponent(config.cms.app)+'&'+postData}
ajaxOpen({type:'post',url:ulink("release/cmsBind"),dataType:'html',data:postData,success:function(data,textStatus,request){$('#cms_bind').removeClass('loading').show();if((/application\/json/i).test(request.getResponseHeader('Content-Type'))){data=jQuery.parseJSON(data);$('#cms_bind').html('<b style="color:red;">'+data.msg+'</b>')}else{$('#cms_bind').html(data);if(config&&config.cms_app){if(config.cms_app.param){for(var f in config.cms_app.param){var paramEle=$('#cms_bind').find('[name="cms_app[param]['+f+']"]');if(paramEle.is('select')){paramEle.val(config.cms_app.param[f]).trigger('change')}else if(paramEle.is('input:radio')){$('#cms_bind').find('[name="cms_app[param]['+f+']"][value="'+config.cms_app.param[f]+'"]').prop('checked','checked')}else{paramEle.val(config.cms_app.param[f])}}
if(config.cms_app.custom){for(var f in config.cms_app.custom){$('#cms_bind').find('[name="cms_app[custom]['+f+']"]').val(config.cms_app.custom[f])}}}}}},error:function(XMLHttpRequest,textStatus,errorThrown){$('#cms_bind').removeClass('loading').show();$('#cms_bind').html(XMLHttpRequest.responseText)}})},db_bind:function(config){var $_o=this;$($_o.formid+' select[name="db[type]"]').val(config.db.type);$(document).ready(function(){$('#db_tab a[href="#db_tab_table"]').tab('show');$('#db_tab_table .db-table-list').html('').addClass('loading');ajaxOpen({type:'get',url:ulink("release/dbTables?id=_id_",{_id_:$_o.releid}),timeout:10000,dataType:'json',success:function(data){if(data.code==1){$('#db_tab_table .db-table-list').html(data.msg)}else{$('#db_tab_table .db-table-list').css('color','red').html(data.msg)}},complete:function(XMLHttpRequest,status){$('#db_tab_table .db-table-list').removeClass('loading');if(status=='timeout'){$('#db_tab_table .db-table-list').css('color','red').html('数据库连接超时')}}});$('#db_tab_table .db-table-list').on('click','.btn-db-table-bind',function(){var curTable=$(this).parents('.db-table-list').eq(0).find('.db-table-select').val();$_o.db_table_bind(curTable)});globalOp.eleExchange('#db_table_bind_list','.db-table-bind-move','[id^="db_table_t_"]');$('#db_table_bind_list').on('click','.db-table-bind-del',function(){var obj=$(this);confirmRight(window.tpl_lang.confirm_delete,function(){obj.parents('[id^="db_table_t_"]').eq(0).remove()})});$('#db_tab_table').on('click','.icon-db-table-bind-tips',function(){confirmRight({msg:'<p><b>采集字段：</b>在“任务»采集器设置»获取内容”中添加</p><p><b>查询：</b>在表的查询操作中可添加查询内容</p><p><b>自增主键：</b>在当前表之前有新增表时会自动显示</p>',yes:'确定',width:400,textAlign:'left'})});$('#db_table_bind_list').on('change','.db-table-bind-op',function(){var prtObj=$(this).parents('[id^="db_table_t_"]').eq(0);prtObj.find('.db-table-bind-query').hide();prtObj.find('.db-table-bind-data').hide();prtObj.find('.db-table-bind-data-seq').hide();var val=$(this).val();var showData=!1;if(!val){showData=!0;prtObj.find('.db-table-bind-data').show()}else if(val=='update'){showData=!0;prtObj.find('.db-table-bind-data').show()}else if(val=='query'){prtObj.find('.db-table-bind-query').show()}
if(showData){var seqObj=prtObj.find('.db-table-bind-data-seq');if(seqObj.length>0){seqObj.show()}}
prtObj.find('.db-table-bind-help').hide();prtObj.find('.db-table-bind-help[data-bind-op="'+val+'"]').show()});$('#db_table_bind_list').on('click','.db-table-bind-signs .btn-db-table-bind-signs',function(){var boxObj=$(this).parents('.db-table-bind-signs').eq(0);if(!boxObj||boxObj.length<=0){return}
var dropdownMenu=boxObj.find('.dropdown-menu');if(dropdownMenu.length>0){dropdownMenu.html('');var key=$(this).parents('[id^="db_table_t_"]').eq(0).attr('data-key');ajaxOpen({type:'POST',dataType:'html',url:ulink('release/dbTableBindSings?table_key=_key_',{'_key_':key}),data:$($_o.formid).serialize(),success:function(html){dropdownMenu.html(html);dropdownMenu.find('a[data-val]').bind('click',function(){globalOp.insertAtCaret($(this).parents('.db-table-bind-signs').eq(0).find('input[name^="db_tables"]').eq(0),$(this).attr('data-val'))})}})}});$('#db_table_bind_list').on('click','.db-table-bind-where-add',function(){$_o.db_table_bind_where_add(this)});$('#db_table_bind_list').on('click','.db-table-bind-where-del',function(){var curObj=$(this);confirmRight('确定删除？',function(){curObj.parents('tr').eq(0).remove()})});$('#db_table_bind_list').on('click','.db-table-bind-query-add',function(){$_o.db_table_bind_query_add(this)});$('#db_table_bind_list').on('click','.db-table-bind-query-del',function(){var curObj=$(this);confirmRight('确定删除？',function(){curObj.parents('tr').eq(0).remove()})});if(isObject(config.db_tables)&&config.db_tables.length>0){$('#db_tab_table .db-table-binding').addClass('loading');$_o.db_table_bind(null,1)}})},db_table_bind:function(curTable,isDbTables){var $_o=this;curTable=curTable?curTable:'';isDbTables=isDbTables?isDbTables:'';var bindUrl=ulink('release/dbTableBind?id=_id_&table=_tb_&is_db_tables=_dbtb_',{'_id_':$_o.releid,'_tb_':curTable,'_dbtb_':isDbTables});ajaxOpen({type:'get',url:bindUrl,dataType:'html',success:function(data){if(dataIsJson(data)){ajaxDataMsg(data)}else{$('#db_table_bind_list').append(data)}},complete:function(){$('#db_tab_table .db-table-binding').removeClass('loading').hide()}})},db_table_bind_load:function(dbTables){var $_o=this;if(isObject(dbTables)){for(var key in dbTables){var tBoxId='#db_table_t_'+key;var namePre='db_tables['+key+']';var dbTable=dbTables[key];if(isObject(dbTable)){$(tBoxId).find('[name="'+namePre+'[op]').val(dbTable.op).trigger('change');var opTypes=['where','query'];for(var opi in opTypes){var opType=opTypes[opi];if(isObject(dbTable[opType])){for(var i in dbTable[opType]){if(!isObject(dbTable[opType])){dbTable[opType][i]=[]}}
for(var i in dbTable[opType].field){var opData={};for(var ii in dbTable[opType]){opData[ii]=dbTable[opType][ii][i]}
$_o.db_table_bind_op_add(opType,key,opData)}}}
if(isObject(dbTable.query)){for(var qk in dbTable.query){$(tBoxId).find('[name="'+namePre+'[field]['+qk+']"]').val(dbTable.query[qk])}}
if(isObject(dbTable.field)){for(var fk in dbTable.field){$(tBoxId).find('[name="'+namePre+'[field]['+fk+']"]').val(dbTable.field[fk])}}
if(isObject(dbTable.sequence)){for(var sk in dbTable.sequence){$(tBoxId).find('[name="'+namePre+'[sequence]['+sk+']"]').val(dbTable.sequence[sk])}}
globalOp.eleExchange(tBoxId+' .db-table-bind-where','.db-table-bind-where-move','tbody tr')}}}},db_table_bind_where_add:function(curObj,whereData){var key=$(curObj).parents('[id^="db_table_t_"]').eq(0).attr('data-key');this.db_table_bind_op_add('where',key,whereData)},db_table_bind_query_add:function(curObj,queryData){var key=$(curObj).parents('[id^="db_table_t_"]').eq(0).attr('data-key');this.db_table_bind_op_add('query',key,queryData)},db_table_bind_op_add:function(opType,key,opData){if(opType&&key){var boxObj=$('#db_table_bind_list').find('#db_table_t_'+key);if(boxObj.length>0){var opTypeClass='.db-table-bind-'+opType;var tbBox=boxObj.find(opTypeClass);if(tbBox.length>0){var tpl=tbBox.find(opTypeClass+'-tpl').clone();tpl.removeClass('db-table-bind-'+opType+'-tpl');if(isObject(opData)){for(var dk in opData){tpl.find('[data-name="['+opType+']['+dk+'][]"]').val(opData[dk])}}
tpl.find('[data-name]').each(function(){$(this).attr('name','db_tables['+key+']'+$(this).attr('data-name'));$(this).removeAttr('data-name')});tbBox.find('tbody').append(tpl)}}}},db_connect:function(op){op=op?op:'';var $_o=this;$('#db_tab_config .rele-db-error').html('').addClass('loading');ajaxOpen({type:'post',url:ulink("release/dbConnect?op="+op),timeout:10000,dataType:'json',data:$($_o.formid).serialize(),success:function(data){if(data.code==1){if(op=='db_names'){modal('选择数据库',data.msg)}else{$('#db_tab_config .rele-db-error').css('color','green').html(data.msg)}}else{toastr.error(data.msg);$('#db_tab_config .rele-db-error').css('color','red').html(data.msg)}},complete:function(XMLHttpRequest,status){$('#db_tab_config .rele-db-error').removeClass('loading');if(status=='timeout'){$('#db_tab_config .rele-db-error').css('color','red').html('数据库连接超时')}}})},toapi_add_param:function(param,index){var $_o=this;var paramTable=$('#rele_module_toapi').find('.toapi-param-table table');if(!paramTable.attr('data-tpl')){var paramTpl=$('#rele_module_toapi').find('.toapi-param-tpl');paramTable.attr('data-tpl',paramTpl.html());paramTpl.remove()}
param=param?param:{};if(!index){index=generateUUID()}
paramTable.find('tbody').append('<tr data-param-id="'+index+'">'+paramTable.attr('data-tpl')+'</tr>');var curTr=paramTable.find('[data-param-id="'+index+'"]');curTr.find('[name="toapi[param_name][]"]').val(param.name?param.name:'');curTr.find('[name="toapi[param_val][]"]').val(param.val?param.val:'')},toapi_add_header:function(header,index){var $_o=this;var headerTable=$('#rele_module_toapi').find('.toapi-header-table table');if(!headerTable.attr('data-tpl')){var headerTpl=$('#rele_module_toapi').find('.toapi-header-tpl');headerTable.attr('data-tpl',headerTpl.html());headerTpl.remove()}
header=header?header:{};if(!index){index=generateUUID()}
headerTable.find('tbody').append('<tr data-header-id="'+index+'">'+headerTable.attr('data-tpl')+'</tr>');var curTr=headerTable.find('[data-header-id="'+index+'"]');curTr.find('[name="toapi[header_name][]"]').val(header.name?header.name:'');curTr.find('[name="toapi[header_val][]"]').val(header.val?header.val:'')},toapi_app_load:function(appParams,appCustomParams){$('#toapi_app_params').off('change','select[name^="toapi[app_params]"]').on('change','select[name^="toapi[app_params]"]',function(){var val=$(this).val();var prt=$(this).parents('.toapi-field-txt').eq(0);var custom=!1;if(isObject(val)){custom=val.indexOf('@skycaiji_custom')>-1?true:!1}else{custom=(val=='@skycaiji_custom')?true:!1}
if(custom){prt.addClass('toapi-field-slt-txt')}else{prt.removeClass('toapi-field-slt-txt')}});if(isObject(appParams)){appCustomParams=isObject(appCustomParams)?appCustomParams:{};for(var key in appParams){var val=appParams[key];if(isObject(val)){var curObjs=$('#toapi_app_params').find('[name="toapi[app_params]['+key+'][]"]');if(curObjs.is('select')){curObjs.find('option').each(function(){if(val.indexOf($(this).val())>-1){$(this).prop('selected',!0)}});curObjs.trigger('change')}else{curObjs.each(function(){if(val.indexOf($(this).val())>-1){$(this).prop('checked',!0)}})}}else{var curObj=$('#toapi_app_params').find('[name="toapi[app_params]['+key+']"]');if(curObj.is('input:radio')){$('#toapi_app_params').find('[name="toapi[app_params]['+key+']"][value="'+val+'"]').prop('checked',!0)}else{curObj.val(val)}
if(curObj.is('select')){curObj.trigger('change')}}
if(appCustomParams[key]){$('#toapi_app_params').find('[name="toapi[app_custom_params]['+key+']"]').val(appCustomParams[key])}}}},rand_str:function(len){var chars='ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';　　var maxPos=chars.length;　　var str='';　　for(var i=0;i<len;i++){　　　　str+=chars.charAt(Math.floor(Math.random()*maxPos));　　}
return str},import_rele:function(releaseImport,name){var $_o=this;$($_o.formid+' input[name="release_import"]').val(releaseImport);$('#btn_import_release').html('导入配置：'+name+'<a href="javascript:;" class="glyphicon glyphicon-remove delete" style="font-size:12px;margin-left:5px;"></a>');$('#btn_import_release .delete').bind('click',function(){$($_o.formid+' input[name="release_import"]').val('');$('#btn_import_release').html('导入配置 <span class="caret"></span>')});$('#myModal').modal('hide')},has_diy_editor:function(){return $('#diy_editor_ifr').length>0?true:!1}}