Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grant officers access to adding and editing returns in draft statuses #232

Merged
merged 2 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@

<script>
import datatable from '@/utils/vue/datatable.vue'
import utils from '@/components/internal/utils'
import utils from '@/components/external/utils'
import $ from 'jquery'
import Vue from 'vue'
import Returns from '../../returns_form.vue'
Expand Down Expand Up @@ -508,7 +508,7 @@ export default {
},
created: function(){
this.form = document.forms.enter_return_sheet;
this.readonly = !this.is_external;
this.readonly = !(this.is_external || this.returns.user_in_officers) || !this.returns.is_draft
this.select_species_list = this.species_list;
},
mounted: function(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,24 @@

<!-- End template for Return Tab -->

<div v-show="showSaveAndContinueButton" class="row" style="margin-bottom:50px;">
<div class="navbar navbar-fixed-bottom" style="background-color: #f5f5f5 ">
<div class="navbar-inner">
<div class="container">
<p class="pull-right" style="margin-top:5px;">
<button v-if="spinner_exit" style="width:150px;" disabled class="btn btn-primary btn-md"><i class="fa fa-spin fa-spinner"></i>&nbsp;Saving</button>
<button v-else-if="!spinner_exit && disable_exit" style="width:150px;" disabled class="btn btn-primary btn-md" name="save_exit">Save and Exit</button>
<button v-else style="width:150px;" class="btn btn-primary btn-md" @click.prevent="saveandcontinue(false)" name="save_exit">Save and Exit</button>

<button v-if="spinner_continue" style="width:150px;" disabled class="btn btn-primary btn-md"><i class="fa fa-spin fa-spinner"></i>&nbsp;Saving</button>
<button v-else-if="!spinner_continue && disable_continue" disabled style="width:150px;" class="btn btn-primary btn-md" name="save_continue">Save and Continue</button>
<button v-else style="width:150px;" class="btn btn-primary btn-md" @click.prevent="saveandcontinue(true)" name="save_continue">Save and Continue</button>
</p>
</div>
</div>
</div>
</div>

<div v-show="showSaveButton" class="row" style="margin-bottom:50px;">
<div class="navbar navbar-fixed-bottom" style="background-color: #f5f5f5 ">
<div class="navbar-inner">
Expand Down Expand Up @@ -98,6 +116,11 @@ export default {
assignTo: false,
loading: [],
spinner: false,
spinner_exit: false,
spinner_continue: false,
disable_exit: false,
disable_continue: false,

DATE_TIME_FORMAT: 'DD/MM/YYYY HH:mm:ss',
members: [],

Expand All @@ -120,13 +143,17 @@ export default {
'isReturnsLoaded',
'returns',
'is_external',
'species_cache',
]),
showSpinner: function() {
return this.spinner
},
showSaveButton: function() {
return !this.returns.is_draft && this.returns.can_be_processed && this.returns.user_in_officers;
},
showSaveAndContinueButton: function() {
return this.returns.is_draft && this.returns.user_in_officers;
},
},
methods: {
...mapActions({
Expand Down Expand Up @@ -163,6 +190,71 @@ export default {
)
});
},
saveandcontinue: async function(andContinue) {
this.is_saving = true
this.disable_submit = true;
this.disable_exit = true;
this.disable_continue = true;
this.spinner_exit = !andContinue;
this.spinner_continue = andContinue;
this.form=document.forms.internal_returns_form;
var data = new FormData(this.form);
// cache only used in Returns sheets
for (const speciesID in this.species_cache) { // Running Sheet Cache
let speciesJSON = []
for (let i=0;i<this.species_cache[speciesID].length;i++){
speciesJSON[i] = this.species_cache[speciesID][i]
}
data.append(speciesID, JSON.stringify(speciesJSON))
};
var speciesJSON = []
let cnt = 0;
for (const speciesID in this.species_transfer) { // Running Sheet Transfers
Object.keys(this.species_transfer[speciesID]).forEach(function(key) {
speciesJSON[cnt] = JSON.stringify(this.species_transfer[speciesID][key])
cnt++;
});
data.append('transfer', speciesJSON)
}
await this.$http.post(helpers.add_endpoint_json(api_endpoints.returns,this.returns.id+'/save'),data,{
emulateJSON:true,
}).then((response)=>{
let species_id = this.returns.sheet_species;
this.setReturns(response.body);
this.returns.sheet_species = species_id;
this.returns.species = species_id;
this.is_saving = false
this.disable_submit = false;
this.disable_exit = false;
this.disable_continue = false;
this.spinner_exit = false;
this.spinner_continue = false;
if (andContinue) {

swal( 'Save',
'Return Details Saved',
'success'
)

} else { // route back to main dashboard

this.$router.push({name:"internal-returns-dash",});

}
},(error)=>{
this.is_saving = false
this.disable_submit = false;
this.disable_exit = false;
this.disable_continue = false;
this.spinner_exit = false;
this.spinner_continue = false;
console.log(error);
swal('Error',
'There was an error saving your return details.<br/>' + error.body,
'error'
)
});
},
},
beforeRouteEnter: function(to, from, next){
next(vm => {
Expand Down
Loading