93e5c047f4d332451ed7b63R6">6
+
7
+class Migration(migrations.Migration):
8
+
9
+    dependencies = [
10
+        ('backend', '0018_ambulance_color'),
11
+    ]
12
+
13
+    operations = [
14
+        migrations.CreateModel(
15
+            name='AmbulanceTicket',
16
+            fields=[
17
+                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
18
+                ('status', models.CharField(choices=[('working', 'Working'), ('free', 'Free'), ('ma', 'MA')], max_length=30, null=True)),
19
+                ('checkin_at', models.DateTimeField(blank=True, null=True)),
20
+                ('checkout_at', models.DateTimeField(blank=True, null=True)),
21
+                ('created_at', models.DateTimeField(auto_now_add=True, null=True)),
22
+                ('updated_at', models.DateTimeField(auto_now=True)),
23
+                ('ambulance', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='backend.ambulance')),
24
+                ('driver', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='backend.driver')),
25
+            ],
26
+        ),
27
+    ]

+ 18 - 0
backend/migrations/0020_driver_status.py

@@ -0,0 +1,18 @@
1
+# Generated by Django 3.2.5 on 2021-07-18 16:51
2
+
3
+from django.db import migrations, models
4
+
5
+
6
+class Migration(migrations.Migration):
7
+
8
+    dependencies = [
9
+        ('backend', '0019_ambulanceticket'),
10
+    ]
11
+
12
+    operations = [
13
+        migrations.AddField(
14
+            model_name='driver',
15
+            name='status',
16
+            field=models.CharField(choices=[('working', 'Working'), ('free', 'Free'), ('block', 'Block')], max_length=30, null=True),
17
+        ),
18
+    ]

+ 24 - 0
backend/migrations/0021_auto_20210719_0014.py

@@ -0,0 +1,24 @@
1
+# Generated by Django 3.2.5 on 2021-07-18 17:14
2
+
3
+from django.db import migrations
4
+import django_google_maps.fields
5
+
6
+
7
+class Migration(migrations.Migration):
8
+
9
+    dependencies = [
10
+        ('backend', '0020_driver_status'),
11
+    ]
12
+
13
+    operations = [
14
+        migrations.AddField(
15
+            model_name='hospital',
16
+            name='address2',
17
+            field=django_google_maps.fields.AddressField(max_length=200, null=True),
18
+        ),
19
+        migrations.AddField(
20
+            model_name='hospital',
21
+            name='geolocation2',
22
+            field=django_google_maps.fields.GeoLocationField(max_length=100, null=True),
23
+        ),
24
+    ]

+ 21 - 0
backend/migrations/0022_auto_20210719_0024.py

@@ -0,0 +1,21 @@
1
+# Generated by Django 3.2.5 on 2021-07-18 17:24
2
+
3
+from django.db import migrations
4
+
5
+
6
+class Migration(migrations.Migration):
7
+
8
+    dependencies = [
9
+        ('backend', '0021_auto_20210719_0014'),
10
+    ]
11
+
12
+    operations = [
13
+        migrations.RemoveField(
14
+            model_name='hospital',
15
+            name='address2',
16
+        ),
17
+        migrations.RemoveField(
18
+            model_name='hospital',
19
+            name='geolocation2',
20
+        ),
21
+    ]

+ 25 - 0
backend/migrations/0023_place.py

@@ -0,0 +1,25 @@
1
+# Generated by Django 3.2.5 on 2021-07-18 17:29
2
+
3
+from django.db import migrations, models
4
+import django_google_maps.fields
5
+
6
+
7
+class Migration(migrations.Migration):
8
+
9
+    dependencies = [
10
+        ('backend', '0022_auto_20210719_0024'),
11
+    ]
12
+
13
+    operations = [
14
+        migrations.CreateModel(
15
+            name='Place',
16
+            fields=[
17
+                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
18
+                ('address', django_google_maps.fields.AddressField(max_length=200)),
19
+                ('geolocation', django_google_maps.fields.GeoLocationField(max_length=100)),
20
+                ('created_at', models.DateTimeField(auto_now_add=True, null=True)),
21
+                ('updated_at', models.DateTimeField(auto_now=True)),
22
+                ('more_info', models.JSONField(blank=True, null=True)),
23
+            ],
24
+        ),
25
+    ]

+ 0 - 0
backend/migrations/__init__.py


BIN
backend/migrations/__pycache__/0001_initial.cpython-39.pyc


BIN
backend/migrations/__pycache__/0002_hospital_geolocation.cpython-39.pyc


BIN
backend/migrations/__pycache__/0003_alter_hospital_address.cpython-39.pyc


BIN
backend/migrations/__pycache__/0004_alter_hospital_location.cpython-39.pyc


BIN
backend/migrations/__pycache__/0005_hospital_address_text.cpython-39.pyc


BIN
backend/migrations/__pycache__/0006_bed_patient.cpython-39.pyc


BIN
backend/migrations/__pycache__/0007_auto_20210718_0246.cpython-39.pyc


BIN
backend/migrations/__pycache__/0007_auto_20210718_0249.cpython-39.pyc


BIN
backend/migrations/__pycache__/0008_alter_patient_prefix.cpython-39.pyc


BIN
backend/migrations/__pycache__/0008_auto_20210718_0659.cpython-39.pyc


BIN
backend/migrations/__pycache__/0009_auto_20210718_0702.cpython-39.pyc


BIN
backend/migrations/__pycache__/0010_auto_20210718_0711.cpython-39.pyc


BIN
backend/migrations/__pycache__/0010_auto_20210718_0713.cpython-39.pyc


BIN
backend/migrations/__pycache__/0011_auto_20210718_0722.cpython-39.pyc


BIN
backend/migrations/__pycache__/0012_patient_comment.cpython-39.pyc


BIN
backend/migrations/__pycache__/0013_patientlog.cpython-39.pyc


BIN
backend/migrations/__pycache__/0014_alter_patientlog_bed.cpython-39.pyc


BIN
backend/migrations/__pycache__/0015_alter_patientlog_bed.cpython-39.pyc


BIN
backend/migrations/__pycache__/0016_auto_20210718_1031.cpython-39.pyc


BIN
backend/migrations/__pycache__/0017_ambulance_driver.cpython-39.pyc


BIN
backend/migrations/__pycache__/0018_ambulance_color.cpython-39.pyc


BIN
backend/migrations/__pycache__/0019_ambulanceticket.cpython-39.pyc


BIN
backend/migrations/__pycache__/0020_driver_status.cpython-39.pyc


BIN
backend/migrations/__pycache__/0021_auto_20210719_0014.cpython-39.pyc


BIN
backend/migrations/__pycache__/0022_auto_20210719_0024.cpython-39.pyc


BIN
backend/migrations/__pycache__/0023_place.cpython-39.pyc


BIN
backend/migrations/__pycache__/__init__.cpython-39.pyc


+ 192 - 0
backend/models.py

@@ -0,0 +1,192 @@
1
+#from django.db import models
2
+from django.contrib.gis.db import models
3
+from django_google_maps import fields as map_fields
4
+from colorfield.fields import ColorField
5
+#from smart_selects.db_fields import GroupedForeignKey
6
+from smart_selects.db_fields import (
7
+    ChainedForeignKey,
8
+    ChainedManyToManyField,
9
+    GroupedForeignKey,
10
+)
11
+# Create your models here.
12
+GENDER_CHOICES = (
13
+    ('นางสาว','นางสาว'),
14
+    ('นาย','นาย'),
15
+    ('นาง', 'นาง'),
16
+    ("ด.ช.","เด็กชาย"),
17
+    ("ด.ญ.","เด็กหญิง"),
18
+)
19
+
20
+class Ambulance(models.Model):
21
+    code = models.CharField(max_length=100)
22
+    license_plate = models.CharField(max_length=100)
23
+    brand = models.CharField(max_length=100)
24
+    model_name = models.CharField(max_length=100)
25
+    comment  = models.TextField(blank=True, null=True)
26
+
27
+    color = ColorField(default='#FF0000')
28
+    status = models.CharField(
29
+        max_length=30,
30
+        choices=(("working", "Working"), ("free", "Free"), ("ma", "MA")),
31
+        null=True,
32
+    )
33
+
34
+    created_at = models.DateTimeField(auto_now_add=True, null=True)
35
+    updated_at = models.DateTimeField(auto_now=True)
36
+
37
+    def __str__(self):
38
+        return f"{self.license_plate} ({self.get_status_display()}) {self.code} {self.brand} / {self.model_name}"
39
+
40
+class Driver(models.Model):
41
+    first_name = models.CharField(max_length=100)
42
+    last_name = models.CharField(max_length=100)
43
+    age = models.IntegerField()
44
+    idcard = models.CharField(max_length=20, null=True, blank=False)
45
+    prefix = models.CharField(
46
+        max_length=30,
47
+        choices=GENDER_CHOICES,
48
+        null=True,
49
+    )
50
+    sex = models.CharField(
51
+        max_length=30,
52
+        choices=(("male", "Male"), ("female", "Female"),),
53
+        null=True,
54
+    )
55
+    photo  = models.FileField(upload_to="uploads/%Y/%m/%d/", blank=True, verbose_name="Photo")
56
+
57
+    address  = models.TextField(blank=True, null=True)
58
+    #test
59
+    status = models.CharField(
60
+        max_length=30,
61
+        choices=(("working", "Working"), ("free", "Free"), ("block", "Block")),
62
+        null=True,
63
+    )
64
+    created_at = models.DateTimeField(auto_now_add=True, null=True)
65
+    updated_at = models.DateTimeField(auto_now=True)
66
+
67
+    def __str__(self):
68
+        return f"{self.first_name} {self.last_name} ({self.get_status_display()})"
69
+
70
+class AmbulanceTicket(models.Model):
71
+    driver = models.ForeignKey(Driver, on_delete=models.SET_NULL, null=True)
72
+    ambulance = models.ForeignKey(Ambulance, on_delete=models.SET_NULL, null=True)
73
+
74
+    status = models.CharField(
75
+        max_length=30,
76
+        choices=(("working", "Working"), ("free", "Free"), ("ma", "MA")),
77
+        null=True,
78
+    )
79
+
80
+    checkin_at = models.DateTimeField(null=True, blank=True)
81
+    checkout_at = models.DateTimeField(null=True, blank=True)
82
+
83
+
84
+    created_at = models.DateTimeField(auto_now_add=True, null=True)
85
+    updated_at = models.DateTimeField(auto_now=True)
86
+
87
+
88
+    def save(self, *args, **kwargs):
89
+        super(AmbulanceTicket, self).save(*args, **kwargs)
90
+        self.ambulance.status = self.status
91
+        self.ambulance.save()
92
+        self.driver.status = "working"
93
+        self.driver.save()
94
+
95
+    def __str__(self):
96
+        return f"{self.driver}@{self.ambulance}"
97
+
98
+class Patient(models.Model):
99
+    first_name = models.CharField(max_length=100)
100
+    last_name = models.CharField(max_length=100)
101
+    age = models.IntegerField()
102
+    idcard = models.CharField(max_length=20, null=True, blank=False)
103
+    prefix = models.CharField(
104
+        max_length=30,
105
+        choices=GENDER_CHOICES,
106
+        null=True,
107
+    )
108
+    sex = models.CharField(
109
+        max_length=30,
110
+        choices=(("male", "Male"), ("female", "Female"),),
111
+        null=True,
112
+    )
113
+    photo  = models.FileField(upload_to="uploads/%Y/%m/%d/", blank=True, verbose_name="Photo")
114
+
115
+    address = map_fields.AddressField(max_length=200, null=True)
116
+    geolocation = map_fields.GeoLocationField(max_length=100, null=True)
117
+    condition_level = models.CharField(
118
+        max_length=30,
119
+        choices=(("green", "Green"), ("yellow", "Yellow"), ("red", "Red")),
120
+        null=True,
121
+    )
122
+    comment  = models.TextField(blank=True, null=True)
123
+    #test
124
+    def __str__(self):
125
+        return f"{self.first_name} {self.last_name}"
126
+
127
+class Place(models.Model):
128
+    address = map_fields.AddressField(max_length=200)
129
+    geolocation = map_fields.GeoLocationField(max_length=100)
130
+
131
+    created_at = models.DateTimeField(auto_now_add=True, null=True)
132
+    updated_at = models.DateTimeField(auto_now=True)
133
+
134
+    more_info  = models.JSONField(null=True, blank=True)
135
+
136
+class Hospital(models.Model):
137
+    title = models.CharField(max_length=200)
138
+    location = models.PointField(blank=True, null=True)
139
+    address_text = models.TextField(blank=True, null=True)
140
+    #address = models.CharField(max_length=100)
141
+    address = map_fields.AddressField(max_length=200)
142
+    geolocation = map_fields.GeoLocationField(max_length=100)
143
+
144
+    created_at = models.DateTimeField(auto_now_add=True, null=True)
145
+    updated_at = models.DateTimeField(auto_now=True)
146
+
147
+    def __str__(self):
148
+        return f"{self.title} {self.address_text}"
149
+
150
+
151
+class Bed(models.Model):
152
+    code = models.CharField(max_length=30)
153
+    occupy = models.BooleanField(default=False)
154
+    patient = models.ForeignKey(Patient, on_delete=models.SET_NULL, null=True, blank=True)
155
+    hospital = models.ForeignKey(Hospital, on_delete=models.CASCADE)
156
+    created_at = models.DateTimeField(auto_now_add=True, null=True)
157
+    updated_at = models.DateTimeField(auto_now=True)
158
+
159
+
160
+    def __str__(self):
161
+        return self.code
162
+
163
+
164
+class PatientLog(models.Model):
165
+    patient = models.ForeignKey(Patient, on_delete=models.SET_NULL, null=True)
166
+    hospital = models.ForeignKey(Hospital, on_delete=models.CASCADE, null=True)
167
+    bed = ChainedForeignKey(
168
+        "Bed",
169
+        chained_field="hospital",
170
+        chained_model_field="hospital",
171
+        show_all=False,
172
+        auto_choose=True,
173
+        null=True
174
+    )
175
+    notes  = models.TextField(blank=True, null=True)
176
+    condition_level = models.CharField(
177
+        max_length=30,
178
+        choices=(("green", "Green"), ("yellow", "Yellow"), ("red", "Red")),
179
+        null=True,
180
+    )
181
+    status = models.CharField(
182
+        max_length=30,
183
+        choices=(("active", "Active"), ("inactive", "Inactive"), ("transfer", "Transfer")),
184
+        null=True,
185
+    )
186
+    checkin_at = models.DateTimeField(null=True, blank=True)
187
+    checkout_at = models.DateTimeField(null=True, blank=True)
188
+
189
+    created_at = models.DateTimeField(auto_now_add=True, null=True)
190
+    updated_at = models.DateTimeField(auto_now=True)
191
+
192
+

+ 3 - 0
backend/tests.py

@@ -0,0 +1,3 @@
1
+from django.test import TestCase
2
+
3
+# Create your tests here.

+ 7 - 0
backend/urls.py

@@ -0,0 +1,7 @@
1
+from django.urls import path
2
+
3
+from . import views
4
+
5
+urlpatterns = [
6
+    path('', views.index, name='index'),
7
+]

+ 8 - 0
backend/views.py

@@ -0,0 +1,8 @@
1
+from django.shortcuts import render
2
+
3
+# Create your views here.
4
+from django.http import HttpResponse
5
+
6
+
7
+def index(request):
8
+    return HttpResponse("Hello, world. You're at the polls index.")

+ 1 - 0
data/db/PG_VERSION

@@ -0,0 +1 @@
1
+13

BIN
data/db/base/1/112


BIN
data/db/base/1/113


BIN
data/db/base/1/1247


BIN
data/db/base/1/1247_fsm


BIN
data/db/base/1/1247_vm


BIN
data/db/base/1/1249


BIN
data/db/base/1/1249_fsm


BIN
data/db/base/1/1249_vm


BIN
data/db/base/1/1255


BIN
data/db/base/1/1255_fsm


BIN
data/db/base/1/1255_vm


BIN
data/db/base/1/1259


BIN
data/db/base/1/1259_fsm


BIN
data/db/base/1/1259_vm


BIN
data/db/base/1/13245


BIN
data/db/base/1/13245_fsm


BIN
data/db/base/1/13245_vm


+ 0 - 0
data/db/base/1/13247


BIN
data/db/base/1/13249


BIN
data/db/base/1/13250


BIN
data/db/base/1/13250_fsm


BIN
data/db/base/1/13250_vm


+ 0 - 0
data/db/base/1/13252


BIN
data/db/base/1/13254


BIN
data/db/base/1/13255


BIN
data/db/base/1/13255_fsm


BIN
data/db/base/1/13255_vm


+ 0 - 0
data/db/base/1/13257


BIN
data/db/base/1/13259


BIN
data/db/base/1/13260


BIN
data/db/base/1/13260_fsm


BIN
data/db/base/1/13260_vm


+ 0 - 0
data/db/base/1/13262


+ 0 - 0
data/db/base/1/13264


Some files were not shown because too many files changed in this diff

tum/whitesports - Gogs: Simplico Git Service

説明なし

form-nav-menu.php 7.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. <?php
  2. if ( ! defined( 'ABSPATH' ) ) {
  3. exit; // Exit if accessed directly
  4. }
  5. if ( ! class_exists( 'acf_form_nav_menu' ) ) :
  6. class acf_form_nav_menu {
  7. /*
  8. * __construct
  9. *
  10. * This function will setup the class functionality
  11. *
  12. * @type function
  13. * @date 5/03/2014
  14. * @since 5.0.0
  15. *
  16. * @param n/a
  17. * @return n/a
  18. */
  19. function __construct() {
  20. // actions
  21. add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
  22. add_action( 'wp_update_nav_menu', array( $this, 'update_nav_menu' ) );
  23. add_action( 'acf/validate_save_post', array( $this, 'acf_validate_save_post' ), 5 );
  24. add_action( 'wp_nav_menu_item_custom_fields', array( $this, 'wp_nav_menu_item_custom_fields' ), 10, 5 );
  25. // filters
  26. add_filter( 'wp_get_nav_menu_items', array( $this, 'wp_get_nav_menu_items' ), 10, 3 );
  27. add_filter( 'wp_edit_nav_menu_walker', array( $this, 'wp_edit_nav_menu_walker' ), 10, 2 );
  28. }
  29. /*
  30. * admin_enqueue_scripts
  31. *
  32. * This action is run after post query but before any admin script / head actions.
  33. * It is a good place to register all actions.
  34. *
  35. * @type action (admin_enqueue_scripts)
  36. * @date 26/01/13
  37. * @since 3.6.0
  38. *
  39. * @param N/A
  40. * @return N/A
  41. */
  42. function admin_enqueue_scripts() {
  43. // validate screen
  44. if ( ! acf_is_screen( 'nav-menus' ) ) {
  45. return;
  46. }
  47. // load acf scripts
  48. acf_enqueue_scripts();
  49. // actions
  50. add_action( 'admin_footer', array( $this, 'admin_footer' ), 1 );
  51. }
  52. /**
  53. * wp_nav_menu_item_custom_fields
  54. *
  55. * description
  56. *
  57. * @date 30/7/18
  58. * @since 5.6.9
  59. *
  60. * @param type $var Description. Default.
  61. * @return type Description.
  62. */
  63. function wp_nav_menu_item_custom_fields( $item_id, $item, $depth, $args, $id = '' ) {
  64. // vars
  65. $prefix = "menu-item-acf[$item_id]";
  66. // get field groups
  67. $field_groups = acf_get_field_groups(
  68. array(
  69. 'nav_menu_item' => $item->type,
  70. 'nav_menu_item_id' => $item_id,
  71. 'nav_menu_item_depth' => $depth,
  72. )
  73. );
  74. // render
  75. if ( ! empty( $field_groups ) ) {
  76. // open
  77. echo '<div class="acf-menu-item-fields acf-fields -clear">';
  78. // loop
  79. foreach ( $field_groups as $field_group ) {
  80. // load fields
  81. $fields = acf_get_fields( $field_group );
  82. // bail if not fields
  83. if ( empty( $fields ) ) {
  84. continue;
  85. }
  86. // change prefix
  87. acf_prefix_fields( $fields, $prefix );
  88. // render
  89. acf_render_fields( $fields, $item_id, 'div', $field_group['instruction_placement'] );
  90. }
  91. // close
  92. echo '</div>';
  93. // Trigger append for newly created menu item (via AJAX)
  94. if ( acf_is_ajax( 'add-menu-item' ) ) : ?>
  95. <script type="text/javascript">
  96. (function($) {
  97. acf.doAction('append', $('#menu-item-settings-<?php echo $item_id; ?>') );
  98. })(jQuery);
  99. </script>
  100. <?php
  101. endif;
  102. }
  103. }
  104. /*
  105. * update_nav_menu
  106. *
  107. * description
  108. *
  109. * @type function
  110. * @date 26/5/17
  111. * @since 5.6.0
  112. *
  113. * @param $post_id (int)
  114. * @return $post_id (int)
  115. */
  116. function update_nav_menu( $menu_id ) {
  117. // vars
  118. $post_id = 'term_' . $menu_id;
  119. // verify and remove nonce
  120. if ( ! acf_verify_nonce( 'nav_menu' ) ) {
  121. return $menu_id;
  122. }
  123. // validate and show errors
  124. acf_validate_save_post( true );
  125. // save
  126. acf_save_post( $post_id );
  127. // save nav menu items
  128. $this->update_nav_menu_items( $menu_id );
  129. }
  130. /*
  131. * update_nav_menu_items
  132. *
  133. * description
  134. *
  135. * @type function
  136. * @date 26/5/17
  137. * @since 5.6.0
  138. *
  139. * @param $post_id (int)
  140. * @return $post_id (int)
  141. */
  142. function update_nav_menu_items( $menu_id ) {
  143. // bail ealry if not set
  144. if ( empty( $_POST['menu-item-acf'] ) ) {
  145. return;
  146. }
  147. // loop
  148. foreach ( $_POST['menu-item-acf'] as $post_id => $values ) {
  149. acf_save_post( $post_id, $values );
  150. }
  151. }
  152. /**
  153. * wp_get_nav_menu_items
  154. *
  155. * WordPress does not provide an easy way to find the current menu being edited.
  156. * This function listens to when a menu's items are loaded and stores the menu.
  157. * Needed on nav-menus.php page for new menu with no items
  158. *
  159. * @date 23/2/18
  160. * @since 5.6.9
  161. *
  162. * @param type $var Description. Default.
  163. * @return type Description.
  164. */
  165. function wp_get_nav_menu_items( $items, $menu, $args ) {
  166. acf_set_data( 'nav_menu_id', $menu->term_id );
  167. return $items;
  168. }
  169. /**
  170. * Called when WP renders a menu edit form.
  171. * Used to set global data and customize the Walker class.
  172. *
  173. * @date 26/5/17
  174. * @since 5.6.0
  175. *
  176. * @param string $class The walker class to use. Default 'Walker_Nav_Menu_Edit'.
  177. * @param int $menu_id ID of the menu being rendered.
  178. * @return string
  179. */
  180. function wp_edit_nav_menu_walker( $class, $menu_id = 0 ) {
  181. // update data (needed for ajax location rules to work)
  182. acf_set_data( 'nav_menu_id', $menu_id );
  183. // Use custom walker class to inject "wp_nav_menu_item_custom_fields" action prioir to WP 5.4.
  184. if ( acf_version_compare( 'wp', '<', '5.3.99' ) ) {
  185. acf_include( 'includes/walkers/class-acf-walker-nav-menu-edit.php' );
  186. return 'ACF_Walker_Nav_Menu_Edit';
  187. }
  188. // Return class.
  189. return $class;
  190. }
  191. /*
  192. * acf_validate_save_post
  193. *
  194. * This function will loop over $_POST data and validate
  195. *
  196. * @type action 'acf/validate_save_post' 5
  197. * @date 7/09/2016
  198. * @since 5.4.0
  199. *
  200. * @param n/a
  201. * @return n/a
  202. */
  203. function acf_validate_save_post() {
  204. // bail ealry if not set
  205. if ( empty( $_POST['menu-item-acf'] ) ) {
  206. return;
  207. }
  208. // loop
  209. foreach ( $_POST['menu-item-acf'] as $post_id => $values ) {
  210. // vars
  211. $prefix = 'menu-item-acf[' . $post_id . ']';
  212. // validate
  213. acf_validate_values( $values, $prefix );
  214. }
  215. }
  216. /*
  217. * admin_footer
  218. *
  219. * This function will add some custom HTML to the footer of the edit page
  220. *
  221. * @type function
  222. * @date 11/06/2014
  223. * @since 5.0.0
  224. *
  225. * @param n/a
  226. * @return n/a
  227. */
  228. function admin_footer() {
  229. // vars
  230. $nav_menu_id = acf_get_data( 'nav_menu_id' );
  231. $post_id = 'term_' . $nav_menu_id;
  232. // get field groups
  233. $field_groups = acf_get_field_groups(
  234. array(
  235. 'nav_menu' => $nav_menu_id,
  236. )
  237. );
  238. ?>
  239. <div id="tmpl-acf-menu-settings" style="display: none;">
  240. <?php
  241. // data (always needed to save nav menu items)
  242. acf_form_data(
  243. array(
  244. 'screen' => 'nav_menu',
  245. 'post_id' => $post_id,
  246. 'ajax' => 1,
  247. )
  248. );
  249. // render
  250. if ( ! empty( $field_groups ) ) {
  251. // loop
  252. foreach ( $field_groups as $field_group ) {
  253. $fields = acf_get_fields( $field_group );
  254. echo '<div class="acf-menu-settings -' . $field_group['style'] . '">';
  255. echo '<h2>' . $field_group['title'] . '</h2>';
  256. echo '<div class="acf-fields -left -clear">';
  257. acf_render_fields( $fields, $post_id, 'div', $field_group['instruction_placement'] );
  258. echo '</div>';
  259. echo '</div>';
  260. }
  261. }
  262. ?>
  263. </div>
  264. <script type="text/javascript">
  265. (function($) {
  266. // append html
  267. var html = $('#tmpl-acf-menu-settings').html();
  268. $('#tmpl-acf-menu-settings').remove();
  269. $('#post-body-content').append( html );
  270. // avoid WP over-writing $_POST data
  271. // - https://core.trac.wordpress.org/ticket/41502#ticket
  272. $(document).on('submit', '#update-nav-menu', function() {
  273. // vars
  274. var $form = $(this);
  275. var $input = $('input[name="nav-menu-data"]');
  276. // decode json
  277. var json = $form.serializeArray();
  278. var json2 = [];
  279. // loop
  280. $.each( json, function( i, pair ) {
  281. // avoid nesting (unlike WP)
  282. if( pair.name === 'nav-menu-data' ) return;
  283. // bail early if is 'acf[' input
  284. if( pair.name.indexOf('acf[') > -1 ) return;
  285. // append
  286. json2.push( pair );
  287. });
  288. // update
  289. $input.val( JSON.stringify(json2) );
  290. });
  291. })(jQuery);
  292. </script>
  293. <?php
  294. }
  295. }
  296. acf_new_instance( 'acf_form_nav_menu' );
  297. endif;
  298. ?>