/*
 |--------------------------------------------------------------------------
 | SkyCaiji (蓝天采集器)
 |--------------------------------------------------------------------------
 | Copyright (c) 2018 https://www.skycaiji.com All rights reserved.
 |--------------------------------------------------------------------------
 | 使用协议  https://www.skycaiji.com/licenses
 |--------------------------------------------------------------------------
 */
'use strict';function MyStoreClass(){}
MyStoreClass.prototype={constructor:MyStoreClass,init_rules:function(){var $_o=this;$('table.datatable thead th[data-order]').bind('click',function(){var order=$(this).attr('data-order');if(!order){return!1}
var className=$(this).attr('class');var sort='desc';if(className=='sorting_desc'){sort='asc'}
window.location.href=ulink('mystore/rule?order='+order+'&sort='+sort);return!1});$('#deleteall').bind('click',function(){var obj=$(this);confirmRight(window.tpl_lang.confirm_delete,function(){ajaxOpen({type:"POST",url:ulink('mystore/ruleOp?op=deleteall'),dataType:"json",data:$('#form_list').serialize(),success:function(data){data.code==1?toastr.success(data.msg):toastr.error(data.msg);window.setTimeout("window.location.reload();",2500)}})})});$('#list_table .delete').bind('click',function(){var obj=$(this);confirmRight(window.tpl_lang.confirm_delete,function(){ajaxOpen({type:"GET",url:obj.attr('url'),dataType:"json",success:function(data){data.code==1?toastr.success(data.msg):toastr.error(data.msg);if(data.code==1){obj.parents('tr').eq(0).remove()}}})})});$('#list_table').on('click','.store-detail',function(){globalOp.openStoreUrl($(this).attr('data-url'))});$('#check_update').bind('click',function(){$_o.check_rules_update()});$('#auto_check').bind('click',function(){var auto=$(this).is(':checked')?1:0;ajaxOpen({type:"GET",url:ulink('mystore/ruleOp?op=auto_check&auto='+auto),dataType:"json",success:function(data){data.code==1?toastr.success(data.msg):toastr.error(data.msg)}})});if($('#auto_check').is(':checked')){$_o.check_rules_update()}},check_rules_update:function(){var ids=new Array();$('#list_table').find('tr[data-rule-id]').each(function(){ids.push($(this).attr('data-rule-id'))});if(ids.length>0){$('.nav-check-update #check_update').html('<div class="loading-sm"></div> 正在检测更新');$('.store-detail').find('.new-version').remove();ajaxOpen({type:"get",url:ulink('mystore/ruleOp?op=check_store_update'),dataType:"json",async:!0,data:{ids:ids},success:function(data){if(data.code==1){for(var id in data.data){var storeDetail=$('tr[data-rule-id="'+data.data[id]+'"]').find('.store-detail');storeDetail.append('<span class="new-version">新</span>')}}},complete:function(){$('.nav-check-update #check_update').html('检测更新')}})}},init_releaseapp:function(){var $_o=this;$('table.datatable thead th[data-order]').bind('click',function(){var order=$(this).attr('data-order');if(!order){return!1}
var className=$(this).attr('class');var sort='desc';if(className=='sorting_desc'){sort='asc'}
window.location.href=ulink('mystore/releaseApp?order='+order+'&sort='+sort);return!1});$('#deleteall').bind('click',function(){var obj=$(this);confirmRight(window.tpl_lang.confirm_delete,function(){ajaxOpen({type:"POST",url:ulink('mystore/releaseAppOp?op=deleteall'),dataType:"json",data:$('#form_list').serialize(),success:function(data){data.code==1?toastr.success(data.msg):toastr.error(data.msg);window.setTimeout("window.location.reload();",2500)}})})});$('#list_table .delete').bind('click',function(){var obj=$(this);confirmRight(window.tpl_lang.confirm_delete,function(){ajaxOpen({type:"GET",url:obj.attr('url'),dataType:"json",success:function(data){data.code==1?toastr.success(data.msg):toastr.error(data.msg);if(data.code==1){obj.parents('tr').eq(0).remove()}}})})});$('#list_table').on('click','.store-detail',function(){globalOp.openStoreUrl($(this).attr('data-url'))});$('#check_update').bind('click',function(){$_o.check_releaseapp_update()});$('#auto_check').bind('click',function(){var auto=$(this).is(':checked')?1:0;ajaxOpen({type:"GET",url:ulink('mystore/releaseAppOp?op=auto_check&auto='+auto),dataType:"json",success:function(data){data.code==1?toastr.success(data.msg):toastr.error(data.msg)}})});if($('#auto_check').is(':checked')){$_o.check_releaseapp_update()}},check_releaseapp_update:function(){var ids=new Array();$('#list_table').find('tr[data-app-id]').each(function(){ids.push($(this).attr('data-app-id'))});if(ids.length>0){$('.nav-check-update #check_update').html('<div class="loading-sm"></div> 正在检测更新');$('.store-detail').find('.new-version').remove();ajaxOpen({type:"get",url:ulink('mystore/releaseAppOp?op=check_store_update'),dataType:"json",async:!0,data:{ids:ids},success:function(data){if(data.code==1){for(var id in data.data){var storeDetail=$('tr[data-app-id="'+data.data[id]+'"]').find('.store-detail');storeDetail.append('<span class="new-version">新</span>')}}},complete:function(){$('.nav-check-update #check_update').html('检测更新')}})}},init_funcapp:function(){var $_o=this;$('table.datatable thead th[data-order]').bind('click',function(){var order=$(this).attr('data-order');if(!order){return!1}
var className=$(this).attr('class');var sort='desc';if(className=='sorting_desc'){sort='asc'}
window.location.href=ulink('mystore/funcApp?order='+order+'&sort='+sort);return!1});$('#deleteall').bind('click',function(){var obj=$(this);confirmRight(window.tpl_lang.confirm_delete,function(){ajaxOpen({type:"POST",url:ulink('mystore/funcAppOp?op=deleteall'),dataType:"json",data:$('#form_list').serialize(),success:function(data){data.code==1?toastr.success(data.msg):toastr.error(data.msg);window.setTimeout("window.location.reload();",2500)}})})});$('#list_table .delete').bind('click',function(){var obj=$(this);var id=$(this).parents('tr[data-app-id]').attr('data-app-id');confirmRight(window.tpl_lang.confirm_delete,function(){ajaxOpen({type:"GET",url:ulink('mystore/funcAppOp?op=delete'),dataType:"json",data:{id:id},success:function(data){data.code==1?toastr.success(data.msg):toastr.error(data.msg);if(data.code==1){obj.parents('tr').eq(0).remove()}}})})});$('#list_table .enable').bind('click',function(){var obj=$(this);var id=$(this).parents('tr[data-app-id]').attr('data-app-id');var enable=$(this).attr('data-val');enable=(enable==1)?0:1;ajaxOpen({type:'GET',url:ulink('mystore/funcAppOp?op=enable'),dataType:'json',data:{id:id,enable:enable},success:function(data){if(data.code){obj.attr('data-val',enable?1:0);obj.text(enable?'已启用':'已禁用');obj.css('color',(enable?'green':'red'))}else{toastr.error(data.msg)}}})});$('#list_table .methods .dropdown-toggle').bind('click',function(){var obj=$(this);var id=$(this).parents('tr[data-app-id]').attr('data-app-id');var box=obj.parents('.methods');box.find('.dropdown-menu').html('<li style="padding-left:15px;"><div class="loading-sm"></div></li>');ajaxOpen({type:'GET',url:ulink('mystore/funcAppOp?op=detail'),dataType:'json',data:{id:id},success:function(data){if(data.code&&data.data){var methods=data.data.methods;methods=methods?methods:{};var html='';for(var m in methods){var mMethod=methods[m];mMethod=mMethod?mMethod:{};html+='<li><a href="javascript:;" data-func-method="'+m+'">'+m+'：'+(mMethod.comment_cut?mMethod.comment_cut:'')+'</a></li>'}
if(!html){html='<li><a href="javascript:;">无方法</a></li>'}
box.find('.dropdown-menu').html(html);box.find('.dropdown-menu [data-func-method]').bind('click',function(){var funcMethod=$(this).attr('data-func-method');windowModal('方法：'+funcMethod,ulink('mystore/funcAppOp?op=method&id=_id_&name=_name_',{'_id_':id,'_name_':funcMethod}),{lg:1,'full_height':1})})}}})});$('#list_table').on('click','.store-detail',function(){globalOp.openStoreUrl($(this).attr('data-url'))});$('#check_update').bind('click',function(){$_o.check_funcapp_update()});$('#auto_check').bind('click',function(){var auto=$(this).is(':checked')?1:0;ajaxOpen({type:"GET",url:ulink('mystore/funcAppOp?op=auto_check&auto='+auto),dataType:"json",success:function(data){data.code==1?toastr.success(data.msg):toastr.error(data.msg)}})});if($('#auto_check').is(':checked')){$_o.check_funcapp_update()}},check_funcapp_update:function(){var ids=new Array();$('#list_table').find('tr[data-app-id]').each(function(){ids.push($(this).attr('data-app-id'))});if(ids.length>0){$('.nav-check-update #check_update').html('<div class="loading-sm"></div> 正在检测更新');$('.store-detail').find('.new-version').remove();ajaxOpen({type:"get",url:ulink('mystore/funcAppOp?op=check_store_update'),dataType:"json",async:!0,data:{ids:ids},success:function(data){if(data.code==1){for(var id in data.data){var storeDetail=$('tr[data-app-id="'+data.data[id]+'"]').find('.store-detail');storeDetail.append('<span class="new-version">新</span>')}}},complete:function(){$('.nav-check-update #check_update').html('检测更新')}})}},init_apiapp:function(){var $_o=this;$('table.datatable thead th[data-order]').bind('click',function(){var order=$(this).attr('data-order');if(!order){return!1}
var className=$(this).attr('class');var sort='desc';if(className=='sorting_desc'){sort='asc'}
window.location.href=ulink('mystore/apiApp?order='+order+'&sort='+sort);return!1});$('#list_table .enable').bind('click',function(){var obj=$(this);var id=$(this).parents('tr[data-app-id]').attr('data-app-id');var enable=$(this).attr('data-val');enable=(enable==1)?0:1;ajaxOpen({type:'GET',url:ulink('mystore/apiAppOp?op=enable'),dataType:'json',data:{id:id,enable:enable},success:function(data){if(data.code){obj.attr('data-val',enable?1:0);obj.text(enable?'已启用':'已禁用');obj.css('color',(enable?'green':'red'))}else{toastr.error(data.msg)}}})});$('#list_table .delete').bind('click',function(){var obj=$(this);confirmRight(window.tpl_lang.confirm_delete,function(){ajaxOpen({type:"GET",url:obj.attr('url'),dataType:"json",success:function(data){data.code==1?toastr.success(data.msg):toastr.error(data.msg);if(data.code==1){obj.parents('tr').eq(0).remove()}}})})});$('#list_table .config').bind('click',function(){var curTr=$(this).parents('tr[data-app-id]').eq(0);var appId=curTr.attr('data-app-id');var appName=curTr.find('.name').text();windowModal('全局配置：'+appName,ulink('mystore/apiAppConfig?id='+appId))});$('#list_table').on('click','.store-detail',function(){globalOp.openStoreUrl($(this).attr('data-url'))});$('#check_update').bind('click',function(){$_o.check_apiapp_update()});$('#auto_check').bind('click',function(){var auto=$(this).is(':checked')?1:0;ajaxOpen({type:"GET",url:ulink('mystore/apiAppOp?op=auto_check&auto='+auto),dataType:"json",success:function(data){data.code==1?toastr.success(data.msg):toastr.error(data.msg)}})});if($('#auto_check').is(':checked')){$_o.check_apiapp_update()}},check_apiapp_update:function(){var ids=new Array();$('#list_table').find('tr[data-app-id]').each(function(){ids.push($(this).attr('data-app-id'))});if(ids.length>0){$('.nav-check-update #check_update').html('<div class="loading-sm"></div> 正在检测更新');$('.store-detail').find('.new-version').remove();ajaxOpen({type:"get",url:ulink('mystore/apiAppOp?op=check_store_update'),dataType:"json",async:!0,data:{ids:ids},success:function(data){if(data.code==1){for(var id in data.data){var storeDetail=$('tr[data-app-id="'+data.data[id]+'"]').find('.store-detail');storeDetail.append('<span class="new-version">新</span>')}}},complete:function(){$('.nav-check-update #check_update').html('检测更新')}})}},apiapp_config:function(config){if(isObject(config)){globalOp.loadFormConfig('#win_form_api_app_config',config.global,'global')}},apiapp_config_none:function(){$(document).ready(function(){$('#myModal').modal('hide');prompt_success('无需配置')})}}
var myStoreClass=new MyStoreClass()