183 lines
6.1 KiB
JavaScript
183 lines
6.1 KiB
JavaScript
// 1 => LOADING
|
|
// 2 => DONE
|
|
// 3 => ERROR
|
|
import * as api from "../api/form.js"
|
|
|
|
export default {
|
|
namespaced: true,
|
|
state: {
|
|
errors:[],
|
|
save_status: 0,
|
|
save_error_message: '',
|
|
get_data_status: 0,
|
|
get_data_error_message: '',
|
|
xid:0,
|
|
sender:'',
|
|
server:'',
|
|
username:'',
|
|
password:'',
|
|
maxretry:0,
|
|
emailcc:'',
|
|
formatemail:'',
|
|
alert_success:false,
|
|
msg_success: "",
|
|
langs:[],
|
|
selected_lang:{},
|
|
datas:[],
|
|
search:'',
|
|
curpage:1,
|
|
total_page:0
|
|
},
|
|
mutations: {
|
|
update_curpage(state, val) {
|
|
state.curpage = val
|
|
},
|
|
update_total_page(state, val) {
|
|
state.total_page = val
|
|
},
|
|
update_search(state, val) {
|
|
state.search = val
|
|
},
|
|
update_datas(state, val) {
|
|
state.datas = val
|
|
},
|
|
update_langs(state, val) {
|
|
state.langs = val
|
|
},
|
|
update_selected_lang(state, val) {
|
|
state.selected_lang = val
|
|
},
|
|
update_errors(state, val) {
|
|
state.errors = val
|
|
},
|
|
update_save_status(state, val) {
|
|
state.save_status = val
|
|
},
|
|
update_save_error_message(state, val) {
|
|
state.save_error_message = val
|
|
},
|
|
update_get_data_status(state, val) {
|
|
state.get_data_status = val
|
|
},
|
|
update_get_data_error_message(state, val) {
|
|
state.get_data_error_message = val
|
|
},
|
|
update_xid(state, val) {
|
|
state.xid = val
|
|
},
|
|
update_sender(state, val) {
|
|
state.sender = val
|
|
},
|
|
update_server(state, val) {
|
|
state.server = val
|
|
},
|
|
update_username(state, val) {
|
|
state.username = val
|
|
},
|
|
update_password(state, val) {
|
|
state.password = val
|
|
},
|
|
update_maxretry(state, val) {
|
|
state.maxretry = val
|
|
},
|
|
update_emailcc(state, val) {
|
|
state.emailcc = val
|
|
},
|
|
update_formatemail(state, val) {
|
|
state.formatemail = val
|
|
},
|
|
update_alert_success(state, val) {
|
|
state.alert_success = val
|
|
},
|
|
update_msg_success(state, val) {
|
|
state.msg_success = val
|
|
}
|
|
},
|
|
actions: {
|
|
async getlang(context) {
|
|
context.commit("update_get_data_status", 1)
|
|
try {
|
|
let resp = await api.getlang(one_token())
|
|
if (resp.status != "OK") {
|
|
context.commit("update_get_data_status", 3)
|
|
} else {
|
|
context.commit("update_get_data_status", 2)
|
|
let data = {
|
|
records: resp.data.records,
|
|
total: resp.data.total
|
|
}
|
|
context.commit("update_save_status",2)
|
|
context.commit("update_langs",resp.data.records)
|
|
context.commit("update_selected_lang",resp.data.records[0])
|
|
context.dispatch("search",{search:context.state.search})
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_get_data_status", 3)
|
|
}
|
|
},
|
|
async getdata(context) {
|
|
context.commit("update_get_data_status", 1)
|
|
try {
|
|
let resp = await api.getdatax(one_token(),context.state.selected_lang,context.state.search)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_get_data_status", 3)
|
|
} else {
|
|
context.commit("update_get_data_status", 2)
|
|
let data = {
|
|
records: resp.data.records,
|
|
total: resp.data.total
|
|
}
|
|
context.commit("update_save_status",2)
|
|
context.commit("update_datas",resp.data.records)
|
|
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_get_data_status", 3)
|
|
}
|
|
},
|
|
async search(context,prm) {
|
|
context.commit("update_get_data_status", 1)
|
|
try {
|
|
console.log(prm)
|
|
prm.token = one_token()
|
|
prm.lang_id = context.state.selected_lang.id
|
|
prm.page = context.state.curpage
|
|
prm.lang = context.state.selected_lang.id
|
|
let resp = await api.search(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_get_data_status", 3)
|
|
} else {
|
|
context.commit("update_get_data_status", 2)
|
|
let data = {
|
|
records: resp.data.records,
|
|
total: resp.data.total
|
|
}
|
|
context.commit("update_save_status",2)
|
|
context.commit("update_datas",resp.data.records)
|
|
context.commit("update_total_page",resp.data.total)
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_get_data_status", 3)
|
|
}
|
|
},
|
|
async save(context,prm) {
|
|
context.commit("update_save_status",1)
|
|
try {
|
|
prm.token = one_token()
|
|
let resp= await api.save(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_save_status",3)
|
|
} else {
|
|
context.commit("update_save_status",2)
|
|
|
|
var msg = "Data sudah terupdate dong ..."
|
|
context.commit("update_msg_success", msg)
|
|
context.commit("update_alert_success", true)
|
|
context.dispatch("search",{search:context.state.search})
|
|
}
|
|
} catch(e) {
|
|
context.commit("update_save_status",3)
|
|
}
|
|
}
|
|
}
|
|
} |