98 lines
3.3 KiB
JavaScript
98 lines
3.3 KiB
JavaScript
// 1 => LOADING
|
|
// 2 => DONE
|
|
// 3 => ERROR
|
|
import * as api from "../api/position.js"
|
|
|
|
export default {
|
|
namespaced: true,
|
|
state: {
|
|
lookup_position: 0,
|
|
lookup_error_message: '',
|
|
positions: [],
|
|
total_positions: 0,
|
|
total_filter_positions: 0,
|
|
alert_success: false,
|
|
msg_success: "",
|
|
errors: []
|
|
},
|
|
mutations: {
|
|
update_errors(state, val) {
|
|
state.errors = val
|
|
},
|
|
update_lookup_position(state, val) {
|
|
state.lookup_position=val
|
|
},
|
|
update_lookup_error_message(state, status) {
|
|
state.lookup_error_message = status
|
|
},
|
|
update_positions(state, data) {
|
|
state.positions = data.records
|
|
state.total_positions = data.total
|
|
state.total_filter_positions = data.total_filter
|
|
},
|
|
update_positions_only(state,data) {
|
|
state.positions = data
|
|
},
|
|
update_alert_success(state, val) {
|
|
state.alert_success = val
|
|
},
|
|
update_msg_success(state, val) {
|
|
state.msg_success = val
|
|
},
|
|
|
|
},
|
|
actions: {
|
|
update_positions_only(context,data) {
|
|
context.commit("update_positions_only",data)
|
|
},
|
|
async save(context,dt) {
|
|
try {
|
|
let resp = await api.xsave(one_token(), dt.positionid,dt.requirementid)
|
|
if (resp.status === "OK") {
|
|
var msg = "Posisi " + dt.positionname + " telah ditambahkan"
|
|
context.commit("requirement/update_msg_success", msg, { root: true })
|
|
context.commit("requirement/update_alert_success", true, { root: true })
|
|
}
|
|
return resp.data.status
|
|
|
|
} catch(e) {
|
|
}
|
|
},
|
|
async delete(context,dt) {
|
|
try {
|
|
let resp = await api.xdelete(one_token(), dt.positionid,dt.requirementid)
|
|
if (resp.status === "OK") {
|
|
var msg = "Posisi " + dt.positionname + " telah dihapus"
|
|
context.commit("requirement/update_msg_success", msg, { root: true })
|
|
context.commit("requirement/update_alert_success", true, { root: true })
|
|
}
|
|
return resp.data.status
|
|
|
|
} catch(e) {
|
|
}
|
|
},
|
|
async lookup(context, id) {
|
|
context.commit("update_lookup_position", 1)
|
|
try {
|
|
let resp = await api.list(one_token(), id)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_lookup_position", 3)
|
|
context.commit("update_lookup_error_message", resp.message)
|
|
} else {
|
|
context.commit("update_lookup_position", 2)
|
|
context.commit("update_lookup_error_message", "")
|
|
let data = {
|
|
records: resp.data.records,
|
|
total: resp.data.total,
|
|
total_filter: resp.data.total_filter
|
|
}
|
|
context.commit("update_positions", data)
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_lookup_position", 3)
|
|
context.commit("update_lookup_error_message", e.message)
|
|
}
|
|
},
|
|
}
|
|
}
|