/*
 |--------------------------------------------------------------------------
 | SkyCaiji (蓝天采集器)
 |--------------------------------------------------------------------------
 | Copyright (c) 2018 https://www.skycaiji.com All rights reserved.
 |--------------------------------------------------------------------------
 | 使用协议  https://www.skycaiji.com/licenses
 |--------------------------------------------------------------------------
 */
'use strict';function ProviderClass(){}
ProviderClass.prototype={constructor:ProviderClass,init_list:function(search){search=search?search:{};$('#form_search [name="title"]').val(search.title?search.title:'');$('#form_search [name="url"]').val(search.url?search.url:'');$('#form_list').on('click','.delete',function(){var tr=$(this).parents('tr[data-id]');var id=tr.attr('data-id');confirmRight('确定删除？',function(){ajaxOpen({type:'GET',url:ulink('provider/delete?id='+id),dataType:'json',success:function(data){if(data.code){tr.remove();toastr.success('删除成功')}else{toastr.error(data.msg)}}})})});$('#form_list').on('click','.comment',function(){var url=$(this).parents('tr[data-url]').attr('data-url');var provStoreUrl=$('#prov_store_url').val();url=provStoreUrl+(provStoreUrl.indexOf('?')>-1?'&':'?')+'url='+encodeURIComponent(url);globalOp.openStoreUrl(url);return!1});$('#form_list').on('click','.edit',function(){var id=$(this).parents('tr[data-id]').attr('data-id');windowModal('编辑',ulink('provider/save?id='+id));return!1});$('#form_list').on('click','.store',function(){var url=$(this).parents('tr[data-url]').attr('data-url');window.open(ulink('mystore/store?url='+encodeURIComponent(url)));return!1});$('#form_list').on('click','.enable',function(){var obj=$(this);var id=$(this).parents('tr[data-id]').attr('data-id');var enable=$(this).attr('data-val');enable=(enable==1)?0:1;ajaxOpen({type:'GET',url:ulink('provider/enable?id='+id+'&enable='+enable),dataType:'json',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)}}})});$('#btn_add').bind('click',function(){windowModal('添加',ulink('provider/save'));return!1});$('#box_tip .close').bind('click',function(){confirmRight('关闭该提示？',function(){ajaxOpen({type:'GET',url:ulink('provider/tip_close'),dataType:'json',success:function(data){$('#box_tip').remove()}})})})},init_prov:function(data){var formId='#win_form_provider';$(formId).bind('submit',function(){var obj=$(this);ajaxOpen({type:'post',url:obj.attr('action'),dataType:'json',data:obj.serialize(),success:function(data){if(data.code==1){ajaxDataMsg(data)}else{if(data.msg){toastr.error(data.msg)}
var data=data.data;if(data&&data.same_as_pwd){confirmRight(data.same_as_pwd,function(){obj.find('[name="same_as_pwd"]').val(1);obj.trigger('submit')})}}}});return!1});if(data){$(formId).find('[name="url"]').val(data.url);$(formId).find('[name="title"]').val(data.title);$(formId).find('[name="authkey"]').val(data.authkey);$(formId).find('[name="sort"]').val(data.sort);$(formId).find('[name="enable"][value="'+data.enable+'"]').prop('checked','checked')}},init_authkeys:function(search){search=search?search:{};$('#search_title').val(search.title?search.title:'');$('#search_url').val(search.url?search.url:'');$('#btn_search').bind('click',function(){var title=$('#search_title').val();var url=$('#search_url').val();window.location.href=ulink('provider/authkeys?url=_url_&title=_title_',{'_url_':url,'_title_':title})});$('#form_list').bind('submit',function(){var obj=$(this);$('#form_list [data-prov-id]').removeClass('has-error');ajaxOpen({type:'post',url:obj.attr('action'),dataType:'json',data:obj.serialize(),success:function(data){if(data.code==1){if(data.msg){toastr.success(data.msg)}
window.setTimeout(function(){window.location.reload()},2000)}else{if(data.msg){toastr.error(data.msg)}
var data=data.data;if(data){if(data.prov_id){$('#form_list').find('[data-prov-id="'+data.prov_id+'"]').addClass('has-error')}
if(data.same_as_pwd){confirmRight(data.same_as_pwd,function(){obj.find('[name="same_as_pwd"]').val(1);obj.trigger('submit')})}}}}});return!1})}}
var providerClass=new ProviderClass()