Flatten nested repos
This commit is contained in:
169
test/vuex/one-md-nat-unit---/modules/unitlang.js
Normal file
169
test/vuex/one-md-nat-unit---/modules/unitlang.js
Normal file
@@ -0,0 +1,169 @@
|
||||
// 1 => LOADING
|
||||
// 2 => DONE
|
||||
// 3 => ERROR
|
||||
import * as api from "../api/unitlang.js"
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
state: {
|
||||
unitlangs: [],
|
||||
save_status: 0,
|
||||
save_error_message: '',
|
||||
dialog_form_unitlang: false,
|
||||
lookup_unitlang: 0,
|
||||
lookupunitlang: 0,
|
||||
errors:[],
|
||||
startdate:moment(new Date()).format('YYYY-MM-DD'),
|
||||
enddate:moment(new Date()).format('YYYY-MM-DD')
|
||||
},
|
||||
mutations: {
|
||||
update_errors(state, val) {
|
||||
state.errors = val
|
||||
},
|
||||
update_unitlangs(state, data) {
|
||||
state.unitlangs = data
|
||||
},
|
||||
update_save_status(state, val) {
|
||||
state.save_status = val
|
||||
},
|
||||
update_save_error_message(state, val) {
|
||||
state.save_error_message = val
|
||||
},
|
||||
update_dialog_form_unitlang(state, val) {
|
||||
state.dialog_form_unitlang = val
|
||||
},
|
||||
update_lookup_unitlang(state, val) {
|
||||
state.lookup_unitlang = val
|
||||
},
|
||||
update_lookupunitlang(state, val) {
|
||||
state.lookupunitlang = val
|
||||
},
|
||||
update_startdate(state,val){
|
||||
state.startdate = val
|
||||
},
|
||||
update_enddate(state,val){
|
||||
state.enddate = val
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
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("unit/update_save_status", 3, { root: true })
|
||||
context.commit("unit/update_save_error_message", resp.message, { root: true })
|
||||
} else {
|
||||
var data = {
|
||||
records: resp.data.records,
|
||||
total: resp.data.total
|
||||
}
|
||||
if(data.total !== -1){
|
||||
context.commit("unit/update_save_status", 2, { root: true })
|
||||
context.commit("unit/update_save_error_message", resp.message, { root: true })
|
||||
context.commit("unit/update_alert_success", true, { root: true })
|
||||
|
||||
context.commit("update_dialog_form_unitlang", false)
|
||||
var msg = "Bahan " + prm.unitname + " sudah update dong"
|
||||
context.commit("unit/update_msg_success", msg, { root: true })
|
||||
context.commit("unit/update_alert_success", true, { root: true })
|
||||
context.dispatch("lookup", {
|
||||
id: prm.unitid
|
||||
})
|
||||
}else{
|
||||
context.commit("update_errors", resp.data.errors)
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
context.commit("update_save_status", 3)
|
||||
context.commit("update_save_error_message", e.message)
|
||||
console.log(e)
|
||||
}
|
||||
},
|
||||
async lookup(context, prm) {
|
||||
context.commit("update_lookup_unitlang", 1)
|
||||
try {
|
||||
let resp = await api.lookup(one_token(),prm.id)
|
||||
if (resp.status != "OK") {
|
||||
context.commit("update_lookup_unitlang", 3)
|
||||
} else {
|
||||
context.commit("update_lookup_unitlang", 2)
|
||||
let data = {
|
||||
records: resp.data.records,
|
||||
total: resp.data.total
|
||||
}
|
||||
context.commit("update_unitlangs", data.records)
|
||||
}
|
||||
} catch (e) {
|
||||
context.commit("update_lookup_unitlang", 3)
|
||||
}
|
||||
},
|
||||
async lookupunitlang(context, prm) {
|
||||
context.commit("update_lookupunitlang", 1)
|
||||
try {
|
||||
let resp = await api.lookupunitlang(one_token(),prm.id,prm.search, prm.current_page)
|
||||
if (resp.status != "OK") {
|
||||
context.commit("update_lookupunitlang", 3)
|
||||
} else {
|
||||
context.commit("update_lookupunitlang", 2)
|
||||
let data = {
|
||||
records: resp.data.records,
|
||||
total: resp.data.total,
|
||||
total_filter: resp.data.total_filter
|
||||
}
|
||||
context.commit("unit/update_units", data, { root: true })
|
||||
// context.commit("unit/update_showunits", data, { root: true })
|
||||
}
|
||||
} catch (e) {
|
||||
context.commit("update_lookupunitlang", 3)
|
||||
}
|
||||
},
|
||||
async lookupunitlanghide(context, prm) {
|
||||
context.commit("update_lookupunitlang", 1)
|
||||
try {
|
||||
let resp = await api.lookupunitlanghide(one_token(),prm.id,prm.search, prm.current_page)
|
||||
if (resp.status != "OK") {
|
||||
context.commit("update_lookupunitlang", 3)
|
||||
} else {
|
||||
context.commit("update_lookupunitlang", 2)
|
||||
let data = {
|
||||
records: resp.data.records,
|
||||
total: resp.data.total,
|
||||
total_filter: resp.data.total_filter
|
||||
}
|
||||
context.commit("unit/update_units", data, { root: true })
|
||||
// context.commit("unit/update_showunits", data, { root: true })
|
||||
}
|
||||
} catch (e) {
|
||||
context.commit("update_lookupunitlang", 3)
|
||||
}
|
||||
},
|
||||
async delete(context, prm) {
|
||||
context.commit("update_save_status", 1)
|
||||
try {
|
||||
let resp = await api.xdelete(one_token(),prm.xid)
|
||||
if (resp.status != "OK") {
|
||||
context.commit("unit/update_save_status", 3, { root: true })
|
||||
context.commit("unit/update_save_error_message", resp.message, { root: true })
|
||||
} else {
|
||||
context.commit("unit/update_save_status", 2, { root: true })
|
||||
context.commit("unit/update_save_error_message", resp.message, { root: true })
|
||||
context.commit("unit/update_alert_success", true, { root: true })
|
||||
|
||||
//context.commit("update_dialog_form_schedule_promise", false)
|
||||
var msg = "Mou "+prm.name+" dari unit " + prm.unitname + " sudah dihapus dong"
|
||||
context.commit("unit/update_msg_success", msg, { root: true })
|
||||
context.commit("unit/update_alert_success", true, { root: true })
|
||||
context.dispatch("lookup", {
|
||||
id: prm.unitid
|
||||
})
|
||||
}
|
||||
} catch (e) {
|
||||
context.commit("update_save_status", 3)
|
||||
context.commit("update_save_error_message", e.message)
|
||||
console.log(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user