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

feat(ZMS-3503): added logic to end emergency with checkbox #805

Merged
merged 5 commits into from
Feb 4, 2025
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
40 changes: 40 additions & 0 deletions zmsadmin/js/block/scope/emergencyend.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import $ from 'jquery'

class EndEmergencyView {

constructor(element, options) {
this.includeUrl = options.includeurl
this.scope = options.scope
this.workstationName = "" + options.workstationname
this.data = {}
this.$ = $(element)

this.$.find('.emergency__button-end').on('click', this.endEmergency.bind(this))
}

endEmergency() {
this.update({ activated: "0", calledByWorkstation: "-1", acceptedByWorkstation: "-1" })
this.sendEmergencyCancel()
}
Comment on lines +15 to +18
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add error handling and user feedback.

The endEmergency method should handle errors from sendEmergencyCancel and provide feedback to the user.

     endEmergency() {
         this.update({ activated: "0", calledByWorkstation: "-1", acceptedByWorkstation: "-1" })
-        this.sendEmergencyCancel()
+        this.sendEmergencyCancel()
+            .then(() => {
+                // Add success feedback (e.g., toast notification)
+            })
+            .catch(error => {
+                // Add error feedback
+                this.update({ activated: "1" }) // Revert state on error
+            })
     }

Committable suggestion skipped: line range outside the PR's diff.


update(newData) {
this.data = Object.assign({}, this.data, newData)
}

sendEmergencyCancel() {
const url = `${this.includeUrl}/scope/${this.scope.id}/emergency/`

return new Promise((resolve, reject) => {
$.ajax(url, {
method: 'GET'
}).done(() => {
resolve()
}).fail(err => {
console.log('XHR error', url, err)
reject(err)
})
})
}
}

export default EndEmergencyView;
5 changes: 5 additions & 0 deletions zmsadmin/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import PickupKeyboardHandheldView from "./page/pickup/keyboard-handheld"
import StatisticView from './page/statistic'

import LoginScopeSelectView from './block/scope/loginselectform'
import EmergencyEnd from './block/scope/emergencyend'
//import AvailabilityDayPage from './page/availabilityDay'
import WeekCalendarPage from './page/weekCalendar'
import printScopeAppointmentsByDay from './page/scopeAppointmentsByDay/print'
Expand Down Expand Up @@ -108,6 +109,10 @@ $('[data-scope-select-form]').each(function () {
new LoginScopeSelectView(this, getDataAttributes(this));
})

$('.emergency-end').each(function () {
new EmergencyEnd(this, getDataAttributes(this));
})

$('.pickup-view').each(function () {
new PickupView(this, getDataAttributes(this));
})
Expand Down
10 changes: 8 additions & 2 deletions zmsadmin/templates/block/scope/form.twig
Original file line number Diff line number Diff line change
Expand Up @@ -627,18 +627,24 @@

<fieldset>
<legend>Notruf</legend>
<div class="panel--heavy">
<div class="panel--heavy emergency-end"
data-scope="{{workstation.scope | json_encode}}"
data-scopestate={{ scopeState|json_encode|e('html_attr') }}
data-labels={{ dataLabels|json_encode|e('html_attr') }}
data-includeurl="{{ includeUrl() }}"
>
{{ formgroup(
{
"label": null
},
[{
"type":"checkbox",
"parameter": {
"label": "Notruffunktion im Backend",
"label": "Notruffunktion im Backend (Durch das Deaktivieren der Funktion wird auch ein aktuell bestehender Notruf am Standort beendet.)",
"name": "preferences[workstation][emergencyEnabled]",
"value": 1,
"checked": scope.preferences.workstation.emergencyEnabled|default(0),
"class": "emergency__button-end"
}
}]
) }}
Expand Down
4 changes: 3 additions & 1 deletion zmsentities/src/Zmsentities/Schema/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,9 @@ public function withLessData()
public function withCleanedUpFormData()
{
$entity = clone $this;
unset($entity['save']);
if (isset($entity['save'])) {
unset($entity['save']);
}
if (isset($entity['removeImage'])) {
unset($entity['removeImage']);
}
Expand Down
Loading