import {
	observable,
	action,
	computed,
	extendObservable,
	toJS
} from 'mobx';
import {
	WeaForm,
	WeaTableNew
} from 'comsMobx';
import {WeaTools} from 'ecCom';
import {
	Button,
	message
} from 'antd';
import HrmBaseStore from './baseStore';
import * as api from '../apis/authorizationSetting';
import FormInfo from '../coms/FormInfo';
import {
	has
} from 'lodash';
import {
	findTabCount
} from '../util/index';
import {
	i18n
} from '../public/i18n';
import {addContentPath} from '../util/index.js'
const {
	TableStore
} = WeaTableNew;

export class HrmAuthorizationSetting extends HrmBaseStore {
	/********************* unobservable list *********************/
	//override baseStore.tabConfig
	tabConfig = {
		tabs: [{
			color: '#000000',
			groupId: 'authorizationGroup',
			title: i18n.label.authorizationGroup,
			viewCondition: '1',
			searchType: ['base', 'advanced'],
			searchKey: 'rightgroupname',			
			doSearch: (params) => this.getTableData('groupTable', params),
			topButtonDef: [{
				comType: 'button',
				type: 'primary',
				onClickHandle: () => this.initAuthorizationEditDialog(),
				label: i18n.button.create,
				icon: 'icon-coms-New-Flow',
				disabled: false
			}, {
				comType: 'button',
				type: 'primary',
				onClickHandle: this.multiRemoveAuthorizationGroup,
				label: i18n.button.multiDelete,
				icon: 'icon-coms-Batch-delete',
				checkAction: 'groupTableMultiRemoveable'
			}],
		}, {
			color: '#000000',
			groupId: 'authorizationGroup',
			title: i18n.label.allAuthorization,
			viewCondition: '2',
			searchType: ['base', 'advanced'],
			searchKey: 'rightname',
			doSearch: (params) => this.getTableData('authorizationListTable', params)
		}],
		keyParam: 'viewCondition',
		activeTabKey: '1'
	}

	editGroupTabConfig = {
		tabs: [{
			color: '#000000',
			groupId: 'authorizationGroup',
			title: i18n.label.authorizationGroupInfo,
			viewCondition: '1',
			searchType: []
		}, {
			color: '#000000',
			groupId: 'authorizationGroup',
			title: i18n.label.authorizationDetail,
			viewCondition: '2',
			searchType: ['base', 'advanced'],
			searchKey: 'rightname',
			doSearch: (params) => this.getTableData('authorizationListTable', { ...params,
				id: this.opId
			}),
			tabButtonDef: [{
				comType: 'button',
				icon: 'icon-coms-Add-to-hot',
				label: i18n.button.create,
				rightMenuIcon: this.menuIconCollection.create,
				brower: 'authorization',
				onClickHandle: (ids) => this.saveGroupAuthorizationRela({
					groupID: this.opId,
					id: ids
				})
			}, {
				comType: 'button',
				icon: 'icon-coms-form-delete-hot',
				label: i18n.button.delete,
				rightMenuIcon: this.menuIconCollection.remove,
				onClickHandle: () => this.removeGroupAuthorizatioRela({
					groupID: this.opId
				}),
				checkAction: 'authorizationListTableMultiRemoveable'
			}]
		}],
		keyParam: 'viewCondition',
		activeTabKey: '1'
	}

	activeTabInfo = {}
	/********************* unobservable list *********************/

	/********************* dialog info setting *********************/
	editorDialogRightMenu = [];
	getDialogOpButtons = () => { //获取权限组编辑对话框按钮列表
		this.editorDialogRightMenu.length = 0;
		let buttons = [<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@oo8fpb`} type="primary" onClick={() => this.saveAuthorizationGroup()}>{i18n.button.save()}</Button>];
		this.editorDialogRightMenu.push({
			key: '1',
			content: i18n.button.save(),
			icon: <i className={this.menuIconCollection.save}/>,
			onClick: () => this.saveAuthorizationGroup(false)
		});
		if (this.dialogParams.addGroupInfo.visible) {
			buttons.push(<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@i98ozy`} type="primary" onClick={() => this.saveAuthorizationGroup(true)}>{i18n.button.saveAndSetting()}</Button>);
			this.editorDialogRightMenu.push({
				key: '2',
				content: i18n.button.saveAndSetting(),
				icon: <i className={this.menuIconCollection.entry}/>,
				onClick: () => this.saveAuthorizationGroup(true)
			});
		} else if (this.dialogParams.editGroupInfo.visible) {
			this.editGroupTabConfig.activeTabKey === '2' && buttons.splice(0, 1) && this.editorDialogRightMenu.splice(0, 1);
		} else if(this.refsDialogParams.visible){
			buttons = [<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@gxauat`} type="primary" onClick={() => this.refsAction()}>{i18n.button.save()}</Button>];
			this.editorDialogRightMenu.length = 0;
			this.editorDialogRightMenu.push({
				key: '1',
				content: i18n.button.save(),
				icon: <i className={this.menuIconCollection.save}/>,
				onClick: () => this.refsAction()
			});
		}

		// this.dialogParams.moreBtn.datas = this.editorDialogRightMenu;
		return buttons;
	}

	roleEditDialogParams = {
		params: {},
		tabKey: ''
	}

	showRoleEditDialog = (params, tabKey) => {
		this.roleEditDialogParams = {
			params,
			tabKey
		};
		this.refreshDialog = new Date().getTime();
	}
	/********************* dialog info setting *********************/

	/********************* observable list *********************/
	dialogParams = { //override baseStore.dialogParams
		addGroupInfo: {
			visible: false,
			title: ''
		},
		editGroupInfo: {
			visible: false,
			title: ''
		}
	}
	@observable groupTable = new TableStore(); //权限组tableStore
	@observable authorizationListTable = new TableStore(); //权限项tableStore

	@observable refreshMainTabComponent = new Date().getTime(); //当需要刷新主页面tab时，变更此值
	@observable refreshEditGroupTabComponent = new Date().getTime(); //当需要刷新权限组编辑tab时，变更此值
	@observable refreshDialog = new Date().getTime();
	@observable refreshTab = new Date().getTime();

	@observable roleRefsDialogParams = {
		...this.refsDialogPropsDef,
		visible: false,
		style: {
			width: 820,
			height: 650
		},
		onCancel: () => {
			this.roleRefsDialogParams.visible = false;
		}
	}

	@observable roleInfoDialogParams = {
		...this.refsDialogPropsDef,
		visible: false,
		style: {
			width: 820,
			height: 650
		},
		onCancel: () => {
			this.roleInfoDialogParams.visible = false;
		}
	}
	/********************* observable list *********************/

	/********************* computed list *********************/
	@computed get groupTableMultiRemoveable() { //权限组列表是否有选中行
		return this.groupTable.selectedRowKeys.length === 0;
	}

	@computed get authorizationListTableMultiRemoveable() { //权限明细列表是否有选中行
		return this.authorizationListTable.selectedRowKeys.length === 0;
	}
	/********************* computed list *********************/

	/********************* action list *********************/
	/**
	 * 初始化模块数据
	 * @return {null}
	 */
	@action initData = () => {
		api.initData().then(rs => {
			try {
				rs.map((result, index) => {
					if (result.status === '1') {
						switch (index) {
							case 0:
								let tabArr = [];
								result.tabs && result.tabs.map(tabInfo => {
									let t = null;
									const tabIndex = this.getTabIndex(this.tabConfig.tabs, tabInfo.key);
									if (tabIndex >= 0) {
										t = this.tabConfig.tabs[tabIndex];
										if (t.showcount) {
											let {
												title,
												count
											} = findTabCount(tabInfo.title);
											t.title = title;
											t.counts = {
												[t.groupId]: count
											}
										} else {
											t.title = tabInfo.title;
										}
									}
									t && tabArr.push(t);
								});
								if (tabArr.length > 0) {
									this.tabConfig.tabs = [...tabArr];
									this.setActiveTab(this.tabConfig, '1');
									this.containerInitFinished = {
										...this.containerInitFinished,
										init: true
									}
								}
								break;
							case 1:
								this.setFormData('conditionForm', result.formField);
								this.refreshMainTabComponent = new Date().getTime();
								break;
							default:
								break;
						}
					}
				});
			} catch (e) {}
		}, error => {

		})
	}

	/**
	 * tab change事件(通过变更refreshMainTabComponent使index重新render)
	 * @param  {Object} tabConfig [tabConfig]
	 * @param  {String} key       [tabKey]
	 * @return {null}
	 */
	@action setActiveTab = (tabConfig, key) => {
		tabConfig.activeTabKey = key || tabConfig.tabs[0].viewCondition;
		const tabIndex = this.getTabIndex(this.tabConfig.tabs, key);
		if (tabIndex < 0) return;
		this.activeTabInfo = {
			activeTabKey: this.tabConfig.activeTabKey,
			activeTabIndex: this.getTabIndex(this.tabConfig.tabs, this.tabConfig.activeTabKey),
			tabInfo: this.tabConfig.tabs[tabIndex]
		}
		if (!this.dialogParams.editGroupInfo.visible) {
			const apiFunc = tabConfig.activeTabKey === '1' ? api.initAuthorizationGroupData : api.initAuthorizationListData;
			apiFunc().then(rs => {
				rs.map((result, index) => {
					if (result.status === '1') {
						switch (index) {
							case 0:
								this.setFormData('conditionForm', result.formField);
								break;
							case 1:
								tabConfig.activeTabKey === '1' && (this.groupTable = new TableStore()) && this.groupTable.getDatas(result.sessionkey, 1);
								tabConfig.activeTabKey === '2' && (this.authorizationListTable = new TableStore()) && this.authorizationListTable.getDatas(result.sessionkey, 1);
								this.refreshMainTabComponent = new Date().getTime();
								break;
							default:
								break;
						}
					}
				});
			})
		} else {
			this.refreshEditGroupTabComponent = new Date().getTime();
		}
	}

	/**
	 * 清空已选中编辑数据主键
	 * @return {null}
	 */
	@action reloadGroupCurrentData = () => {
		this.opId = null;
		this.groupTable.getDatas();
	}

	/**
	 * 根据传进来的tbStore's name创建TableStore
	 * @param  {String} tbStore [tableStore's name]
	 * @param  {Object} params  [restful request url params]
	 * @return {null}
	 */
	@action getTableData = (tbStore, params) => {
		this[tbStore] = new TableStore();
		switch (tbStore) {
			case 'groupTable':
				this.requestTableData(this[tbStore], api.getAuthorizationGroupList, params);
				break;
			case 'authorizationListTable':
				this.requestTableData(this[tbStore], api.getAuthorizationList, params);
				break;
			default:
				break;
		}
	}

	/**
	 * 初始化权限组新建/编辑对话框
	 * @param  {Object} params [restful request url params]
	 * @param  {String} entry  [根据对话框入口，加载内容]
	 * @return {null}
	 */
	@action initAuthorizationEditDialog = (params = {}, entry) => {
		const formKey = 'authorizationGroupForm';
		if (entry == null) {
			this.requestFormData(formKey, api.getAuthorizationGroupForm, params, () => {
				this.setDialogVisible('addGroupInfo', true, i18n.label.createAuthorizationGroup());
				this.opId = null;
			});
		} else {
			api.initAuthorizationEditDialog(params).then(rs => {
				rs.map((result, index) => {
					if (result.status === '1') {
						switch (index) {
							case 0:
								this.setFormData('authorizationGroupForm', result.formField);
								break;
							case 1:
								this.setFormData('authorizationListConditionForm', result.formField);
								break;
							case 2:
								this.authorizationListTable.getDatas(result.sessionkey, 1);
								break;
							default:
								break;
						}
					}
				});
				this.editGroupTabConfig.activeTabKey = entry === 'rightgroupname' ? '1' : '2';
				this.setDialogVisible('editGroupInfo', true, i18n.label.modifyAuthorizationGroup());
				this.opId = (params && params.id ? params.id : null);
			});
		}
	}

	/**
	 * 保存权限组信息，如果选择保存并进入设置，变更dialog的visible值
	 * @param  {Boolean} setting [是否保存后进入设置，default: false]
	 * @return {null}
	 */
	@action saveAuthorizationGroup = (setting = false, closeDialog = true) => {
		this.formTarget.authorizationGroupForm.validateForm().then(f => {
			if (f.isValid) {
				let params = {
					...this.formTarget.authorizationGroupForm.getFormParams(),
					id: this.opId
				}
				api.saveAuthorizationGroup(params).then(data => {
					if (data.status === '1') {
						// this.getTableData('groupTable');
						this.dialogParams.addGroupInfo.visible && this.setDialogVisible('addGroupInfo', false, '', () => this.getTableData('groupTable'));
						if (!setting) {
							message.success(i18n.message.saveSuccess());
							this.dialogParams.editGroupInfo.visible && closeDialog && this.setDialogVisible('editGroupInfo', false, '', () => this.getTableData('groupTable'));
						} else {
							this.initAuthorizationEditDialog({
								id: data.id
							}, 'result');
						}
					} else
						message.error(data.message);
				}, error => {
					message.error(i18n.message.actionError());
				});
			} else {
				f.showErrors();
				this.showError = new Date().getTime();
			}
		});
	}

	/**
	 * 删除某一或批量删除权限组，操作成功后刷新table数据
	 * @param  {Object} params [restful request url params]
	 * @return {null}
	 */
	@action multiRemoveAuthorizationGroup = (params) => {
		let content = '';
		if (!has(params, 'id')) {
			params = {
				id: this.groupTable.selectedRowKeys
			}
			content = i18n.confirm.deleteSelected();
		}else{
			content = i18n.confirm.delete();
		}

		this.confirmInfo({
			content,
			onOk: () => {
				api.removeAuthorizationGroup(params).then(data => {
					if (data.status === '1') {
						message.success(i18n.message.deleteSuccess());
						this.getTableData('groupTable');
					} else
						message.error(data.message);
				}, error => {
					message.error(i18n.message.actionError());
				});
			}
		});
	}

	/**
	 * 保存权限组与权限项的关系，操作成功后刷新权限项列表数据以及权限组列表当前页数据
	 * @param  {Object} params [restful request url params]
	 * @return {null}
	 */
	@action saveGroupAuthorizationRela = (params) => {
		if (params.groupID == null || params.id.length === 0)
			return;
		api.saveGroupAuthorizatioRela(params).then(data => {
			if (data.status === '1') {
				message.success(i18n.message.saveSuccess());
				this.getTableData('authorizationListTable', {
					id: this.opId
				});
				this.groupTable.getDatas();
			} else
				message.error(data.message);
		}, error => {
			message.error(i18n.message.actionError());
		});
	}

	/**
	 * 删除某一或批量删除权限组与权限的关系，操作成功后刷新权限项列表数据以及权限组列表当前页数据
	 * @param  {Object} params [restful request url params]
	 * @return {null}
	 */
	@action removeGroupAuthorizatioRela = (params) => {
		if (params.groupID == null)
			return;
		let content = '';
		if (!has(params, 'id')) {
			if (this.authorizationListTable.selectedRowKeys.length === 0)
				return;
			params = {
				...params,
				id: this.authorizationListTable.selectedRowKeys
			}
			content = i18n.confirm.removeSelected();
		}else{
			content = i18n.confirm.remove();
		}

		this.confirmInfo({
			content,
			onOk: () => {
				api.removeGroupAuthorizatioRela(params).then(data => {
					if (data.status === '1') {
						message.success(i18n.message.deleteSuccess());
						this.getTableData('authorizationListTable', {
							id: this.opId
						});
						this.groupTable.getDatas();
					} else
						message.error(data.message);
				}, error => {
					message.error(i18n.message.actionError());
				});
			}
		});
	}
	/********************* action list *********************/

	//查看引用
    selectedAuthInfo;
    @observable refsTable = new TableStore();
    refsTabConfig = {
        tabs: [{
            color: '#000000',
            groupId: 'roleList',
            title: '',
            viewCondition: '1',
            searchType: ['base', 'advanced'],
            searchKey: 'rolename',
            doSearch: () => this.getRefsList(),
            tabButtonDef: [{
                comType: 'button',
                icon: 'icon-coms-Add-to-hot',
                label: i18n.button.add,
                rightMenuIcon: this.menuIconCollection.create,
                onClickHandle: () => this.addRefs()
            }, {
                comType: 'button',
                icon: 'icon-coms-BatchEditing-Hot',
                label: i18n.button.multiModifyAuthRoleLevel,
                rightMenuIcon: this.menuIconCollection.multiModify,
                onClickHandle: () => this.modifyRefs(),
                checkAction: 'refsRemoveable'
            }, {
                comType: 'button',
                icon: 'icon-coms-form-delete-hot',
                label: i18n.button.multiDelete,
                rightMenuIcon: this.menuIconCollection.remove,
                onClickHandle: () => this.deleteRefs(),
                checkAction: 'refsRemoveable'
            }]
        }],
        keyParam: 'viewCondition',
        activeTabKey: '1'
	}
	
	@observable refsDialogParams = {
		...this.dialogPropsDef,
		opType: '',
		opId: '',
		onCancel: () => {
			this.refsDialogParams.opType = '';
			this.refsDialogParams.visible = false;
			this.refsDialogParams.opId = null;
		}
	}

    @computed get refsRemoveable(){
        return this.refsTable.selectedRowKeys.length == 0;
	}
	
	@action showRefs = (id, authName, height) => {
		if(this.tabConfig.activeTabKey == 2 && height != null && height > 0){
			height -= 180;
			if(height < 0)
				height = null;
		}
		// this.roleRefsDialogParams.title = `${i18n.label.viewRefs()}：${authName}`;
		// this.roleRefsDialogParams.url = `/spa/hrm/engine.html#/hrmengine/roleRefs?isSingle=1&id=${id}`;
		// this.roleRefsDialogParams.visible = true;
		const dialog = WeaTools.createDialog({
			title: `${i18n.label.viewRefs()}：${authName}`,
			moduleName: 'hrm',
			url: addContentPath(`/spa/hrm/engine.html#/hrmengine/roleRefs?isSingle=1&id=${id}&height=${height}`),
			style: {
				width: 820,
				height: height || 650
			},
			callback: (datas) => {
			},
			onCancel: () => {
			}
		});
		dialog.show();
	}

    @action initRefsData = (id) => {
        this.selectedAuthInfo = {id};
        api.getSystemRightRolesCondition().then(data => {
            if(data.status === '1'){
                this.setFormData('refsConditionForm', data.formField);
				this.containerInitFinished.init = true;
                this.getRefsList();
            }else{
                message.error(data.message);
            }
        }, error => {})
    }

    @action getRefsList = () => {
        const params = this.formTarget.refsConditionForm.getFormParams();
        Object.assign(params, {...this.selectedAuthInfo});
        this.refsTable = new TableStore();
        api.getSystemRightRolesList(params).then(data => {
            if(data.status === '1'){
				this.refsTable.getDatas(data.sessionkey, 1);
				this.refreshTab = new Date().getTime();
            }else{
                message.error(data.message);
            }
        }, error => {})
	}
	
	@action showRoleInfo = (id, tab) => {
		// this.roleInfoDialogParams.title = i18n.label.modifyRole();
		// this.roleInfoDialogParams.url = `/spa/hrm/engine.html#/hrmengine/roleInfo?isSingle=1&id=${id}&tab=${tab}`;
		// this.roleInfoDialogParams.visible = true;


		const dialog = WeaTools.createDialog({
			title: i18n.label.modifyRole(),
			moduleName: 'hrm',
			url: addContentPath(`/spa/hrm/engine.html#/hrmengine/roleInfo?isSingle=1&id=${id}&tab=${tab}`),
			style: {
				width: 820,
				height: 650
			},
			callback: (datas) => {
			},
			onCancel: () => {

			}
		});
		dialog.show();
	}

	@action refsAction = () => {
		let func, params;
		switch(this.refsDialogParams.opType){
			case 'add':
				func = api.addSystemRightRoles;
				params = {
					rightid: this.selectedAuthInfo.id,
					...this.formTarget.refsForm.getFormParams()
				}
				break;
			case 'modify':
				func = api.editSystemRightRoles;
				params = {
					id: this.refsDialogParams.opId,
					rightid: this.selectedAuthInfo.id,
					...this.formTarget.refsForm.getFormParams()
				}
				break;
		}
		this.formTarget.refsForm.validateForm().then(f => {
			if (f.isValid) {
				func(params).then(data => {
					if(data.status === '1'){
						message.success(i18n.message.saveSuccess());
						this.getRefsList();
						this.refsDialogParams.onCancel();
					}else{
						message.error(data.message);
					}
				}, error => {})
			} else {
				f.showErrors();
				this.showError = new Date().getTime();
			}
		});
	}

    @action addRefs = () => {
		api.getSystemRightRolesForm().then(data => {
			if(data.status === '1'){
				// data.formField[0].items[0].browserConditionParam.hasAddBtn = true;
				// data.formField[0].items[0].browserConditionParam.addOnClick = this.callCreateRole;
				this.setFormData('refsForm', data.formField);
				if (this.formTarget.refsForm.isFormInit) {
					const {
						refsForm: form,
						refsFormFields: fields
					} = this.formTarget;
					this.refsDialogParams.title = i18n.label.addRoleRefs();
					this.refsDialogParams.opType = 'add';
					this.refsDialogParams.opId = '';
					this.refsDialogParams.coms = <FormInfo ecId={`${this && this.props && this.props.ecId || ''}_FormInfo@mc9qaz`} center={false} form={form} formFields={fields} menu={this.editorDialogRightMenu}/>;
					this.refsDialogParams.style = {
						width: 400,
						height: 205
					}
					this.refsDialogParams.visible = true;
				}
			}else{
				message.error(data.message);
			}
		}, error => {})
    }

    @action modifyRefs = (record) => {
		api.getSystemRightRolesForm().then(data => {
			if(data.status === '1'){
				let formField = data.formField;
				formField[0].items.splice(0, 1);
				this.setFormData('refsForm', formField);
				if (this.formTarget.refsForm.isFormInit) {
					record != null && this.formTarget.refsForm.updateFields({
						rolelevel: {
							value: record.rolelevel
						}
					})
					const {
						refsForm: form,
						refsFormFields: fields
					} = this.formTarget;
					this.refsDialogParams.title = (record != null ? `${i18n.label.editRoleAuth()}：${record.rolesmark}` : i18n.button.multiModifyAuthRoleLevel());
					this.refsDialogParams.opType = 'modify';
					this.refsDialogParams.opId = (record != null ? record.id : this.refsTable.selectedRowKeys);
					this.refsDialogParams.coms = <FormInfo ecId={`${this && this.props && this.props.ecId || ''}_FormInfo@k6kpc5`} center={false} form={form} formFields={fields} menu={this.editorDialogRightMenu}/>;
					this.refsDialogParams.style = {
						width: 400,
						height: 95
					}
					this.refsDialogParams.visible = true;
				}
			}else{
				message.error(data.message);
			}
		}, error => {})
    }

    @action deleteRefs = (params) => {
        let content = '';
        if(params == null){
            content = i18n.confirm.deleteSelected();
            params = {id: this.refsTable.selectedRowKeys}
        }else{
            content = i18n.confirm.delete();
        }
        this.confirmInfo({
            content,
            onOk: () => {
                api.delSystemRightRoles(params).then(data => {
                    if (data.status === '1') {
                        message.success(i18n.message.deleteSuccess());
                        this.getRefsList();
                    } else
                        message.error(data.message);
                }, error => {
                    message.error(i18n.message.actionError());
                });
            }
        });
	}

	callback = false;
	@action callCreateRole = () => {
		this.callback = false;
		const dialog = WeaTools.createDialog({
			title: i18n.label.createRole(),
			moduleName: 'hrm',
			url: addContentPath(`/spa/hrm/engine.html#/hrmengine/addRole?isSingle=1`),
			style: {
				width: 520,
				height: 345
			},
			callback: (datas, callback) => {
				this.callback = callback || false;
				this.formTarget.refsForm.updateFields({
					roleid: {
						value: datas.id.toString(),
						valueSpan: datas.name,
						valueObj: [{
							id: datas.id.toString(),
							name: datas.name
						}]
					}
				})
			},
			onCancel: () => {
				if(this.callback){
					this.showRoleInfo(this.formTarget.refsForm.getFormParams().roleid, '2');
				}
			}
		});
		dialog.show();
	}

	@observable formLoaded = new Date().getTime();
	@action addRefs1 = () => {
		api.getSystemRightRolesForm().then(data => {
			if(data.status === '1'){
				data.formField[0].items[0].browserConditionParam.hasAddBtn = true;
				data.formField[0].items[0].browserConditionParam.addOnClick = this.callCreateRole;
				this.setFormData('refsForm', data.formField);
				this.formLoaded = new Date().getTime();
			}else{
				message.error(data.message);
			}
		}, error => {})
    }
}