diff --git a/tailbone/templates/people/view_profile_buefy.mako b/tailbone/templates/people/view_profile_buefy.mako index 31779e89..7b413621 100644 --- a/tailbone/templates/people/view_profile_buefy.mako +++ b/tailbone/templates/people/view_profile_buefy.mako @@ -200,7 +200,51 @@
- {{ employee.id }} +
+
+
+ {{ employee.id }} +
+ % if request.has_perm('employees.edit'): +
+ + Edit ID + + + + +
+ % endif +
+
@@ -643,17 +687,79 @@ employeeHistoryEndDate: null, employeeHistoryEndDateRequired: false, + % if request.has_perm('employees.edit'): + showEditEmployeeIDDialog: false, + newEmployeeID: null, + updatingEmployeeID: false, + % endif + ## TODO: should find a better way to handle CSRF token csrftoken: ${json.dumps(request.session.get_csrf_token() or request.session.new_csrf_token())|n}, } }, + computed: { + + % if request.has_perm('employees.edit'): + + editEmployeeIDSaveButtonText() { + if (this.updatingEmployeeID) { + return "Working, please wait..." + } + return "Save" + }, + + % endif + }, + methods: { changeContentTitle(newTitle) { this.$emit('change-content-title', newTitle) }, + % if request.has_perm('employees.edit'): + + initEditEmployeeID() { + this.newEmployeeID = this.employee.id + this.updatingEmployeeID = false + this.showEditEmployeeIDDialog = true + }, + + updateEmployeeID() { + this.updatingEmployeeID = true + + let url = '${url('people.profile_update_employee_id', uuid=instance.uuid)}' + + let params = { + 'employee_id': this.newEmployeeID, + } + + let headers = { + ## TODO: should find a better way to handle CSRF token + 'X-CSRF-TOKEN': this.csrftoken, + } + + ## TODO: should find a better way to handle CSRF token + this.$http.post(url, params, {headers: headers}).then(({ data }) => { + if (data.success) { + this.employee.id = data.employee.id + this.showEditEmployeeIDDialog = false + this.updatingEmployeeID = false + } else { + this.$buefy.toast.open({ + message: "Save failed: " + data.error, + type: 'is-danger', + duration: 4000, // 4 seconds + }) + } + }, response => { + alert("Unexpected error occurred!") + }) + }, + + % endif + % if request.has_perm('people_profile.toggle_employee'): showStartEmployee() { diff --git a/tailbone/views/employees.py b/tailbone/views/employees.py index ae59e3da..aa97b9b7 100644 --- a/tailbone/views/employees.py +++ b/tailbone/views/employees.py @@ -186,7 +186,12 @@ class EmployeeView(MasterView): employee = f.model_instance f.set_renderer('person', self.render_person) - f.set_renderer('users', self.render_users) + + if self.creating or self.editing: + f.remove('users') + else: + f.set_readonly('users') + f.set_renderer('users', self.render_users) f.set_renderer('stores', self.render_stores) f.set_label('stores', "Stores") # TODO: should not be necessary diff --git a/tailbone/views/people.py b/tailbone/views/people.py index 0613d3d7..a393df99 100644 --- a/tailbone/views/people.py +++ b/tailbone/views/people.py @@ -634,6 +634,25 @@ class PersonView(MasterView): 'employee_history_data': self.get_context_employee_history(employee), } + def profile_update_employee_id(self): + """ + View to update an employee's ID value. + """ + app = self.get_rattail_app() + employment = app.get_employment_handler() + + person = self.get_instance() + employee = employment.get_employee(person) + + data = self.request.json_body + employee.id = data['employee_id'] + self.Session.flush() + + return { + 'success': True, + 'employee': self.get_context_employee(employee), + } + def make_note_form(self, mode, person): schema = NoteSchema().bind(session=self.Session(), person_uuid=person.uuid) @@ -784,6 +803,15 @@ class PersonView(MasterView): config.add_view(cls, attr='profile_edit_employee_history', route_name='{}.profile_edit_employee_history'.format(route_prefix), permission='people_profile.edit_employee_history', renderer='json') + # profile - update employee ID + config.add_route('{}.profile_update_employee_id'.format(route_prefix), + '{}/profile/update-employee-id'.format(instance_url_prefix), + request_method='POST') + config.add_view(cls, attr='profile_update_employee_id', + route_name='{}.profile_update_employee_id'.format(route_prefix), + renderer='json', + permission='employees.edit') + # manage notes from profile view if cls.manage_notes_from_profile_view: