|
27 | 27 |
|
28 | 28 | <div class="modal-footer"> |
29 | 29 | <button type="button" class="btn btn-sm btn-primary" data-bs-dismiss="modal">Next</button> |
30 | | - {{-- |
31 | | - <button type="button" class="btn btn-sm btn-primary" data-bs-dismiss="modal"><i class="fas fa-fw fa-spinner fa-spin d-none"></i> Next</button> |
32 | | - --}} |
33 | 30 | </div> |
34 | 31 | </div> |
35 | 32 | </div> |
|
45 | 42 | $('#new_objectclass-modal').on('shown.bs.modal',function() { |
46 | 43 | if (! rendered) |
47 | 44 | $.ajax({ |
48 | | - type: 'POST', |
49 | | - cache: false, |
| 45 | + method: 'POST', |
50 | 46 | url: '{{ url('entry/objectclass/add') }}', |
51 | 47 | data: { |
52 | 48 | oc: oc, |
53 | 49 | }, |
| 50 | + cache: false, |
54 | 51 | success: function(data) { |
55 | 52 | $('select#newoc').select2({ |
56 | 53 | dropdownParent: $('#new_objectclass-modal'), |
|
60 | 57 | }); |
61 | 58 | }, |
62 | 59 | error: function(e) { |
63 | | - if (e.status != 412) |
| 60 | + if (e.status !== 412) |
64 | 61 | alert('That didnt work? Please try again....'); |
65 | 62 | }, |
66 | 63 | }); |
|
70 | 67 |
|
71 | 68 | // When the ObjectClass modal is closed, process what was selected |
72 | 69 | $('#new_objectclass-modal').on('hide.bs.modal',function() { |
73 | | - var c = {{ $o->values->count() }}; // @todo do we need this? |
74 | 70 | var newadded = $('select#newoc').val(); |
75 | 71 |
|
76 | 72 | // If nothing selected, we dont have anything to do |
77 | | - if (added_oc.sort().join('|') == newadded.sort().join('|')) |
| 73 | + if (added_oc.sort().join('|') === newadded.sort().join('|')) |
78 | 74 | return; |
79 | 75 |
|
80 | 76 | // Find out what was selected, and add them |
|
84 | 80 |
|
85 | 81 | // Add attribute to the page |
86 | 82 | $.ajax({ |
87 | | - type: 'POST', |
88 | | - beforeSend: function() {}, |
89 | | - success: function(data) { |
90 | | - $('#{{ $o->name }}').append(data); |
91 | | - }, |
92 | | - error: function(e) { |
93 | | - if (e.status != 412) |
94 | | - alert('That didnt work? Please try again....'); |
95 | | - }, |
| 83 | + method: 'POST', |
96 | 84 | url: '{{ url('entry/attr/add',[$o->name_lc]) }}', |
97 | 85 | data: { |
98 | 86 | noheader: true, |
99 | 87 | value: item, |
100 | 88 | objectclasses: oc, |
101 | | - loop: c++, // @todo can we omit loop and c |
102 | 89 | }, |
103 | | - cache: false |
| 90 | + cache: false, |
| 91 | + success: function(data) { |
| 92 | + $('#{{ $o->name }}').append(data); |
| 93 | + }, |
| 94 | + error: function(e) { |
| 95 | + if (e.status !== 412) |
| 96 | + alert('That didnt work? Please try again....'); |
| 97 | + }, |
104 | 98 | }); |
105 | 99 |
|
106 | 100 | $.ajax({ |
107 | | - type: 'POST', |
108 | | - beforeSend: function() {}, |
| 101 | + method: 'POST', |
| 102 | + url: '{{ url('api/schema/objectclass/attrs') }}/'+item, |
| 103 | + cache: false, |
109 | 104 | success: function(data) { |
110 | 105 | // Render any must attributes |
111 | 106 | if (data.must.length) { |
112 | 107 | data.must.forEach(function(item) { |
113 | 108 | // Add attribute to the page |
114 | 109 | $.ajax({ |
115 | | - type: 'POST', |
116 | | - beforeSend: function() {}, |
| 110 | + method: 'POST', |
| 111 | + url: '{{ url('entry/attr/add') }}/'+item, |
| 112 | + data: { |
| 113 | + value: item, |
| 114 | + objectclasses: oc, |
| 115 | + }, |
| 116 | + cache: false, |
117 | 117 | success: function(data) { |
118 | 118 | $('#newattrs').append(data); |
119 | 119 | }, |
120 | 120 | error: function(e) { |
121 | | - if (e.status != 412) |
| 121 | + if (e.status !== 412) |
122 | 122 | alert('That didnt work? Please try again....'); |
123 | 123 | }, |
124 | | - url: '{{ url('entry/attr/add') }}/'+item, |
125 | | - data: { |
126 | | - value: item, |
127 | | - objectclasses: oc, |
128 | | - loop: c++, // @todo can we omit loop and c |
129 | | - }, |
130 | | - cache: false |
131 | 124 | }); |
132 | 125 | }) |
133 | 126 | } |
134 | 127 |
|
135 | 128 | // Add attributes to "Add new Attribute" that are now available |
136 | 129 | if (data.may.length) { |
137 | 130 | var newattr = $('select#newattr'); |
| 131 | + var oldoptions = $('select#newattr option').map((i,o)=>o.value).get(); |
138 | 132 |
|
139 | | - // @todo It might be nice to re-sort these options |
140 | 133 | data.may.forEach(function(item) { |
141 | | - newattr.append(new Option(item,item,false,false)); |
| 134 | + if (! oldoptions.includes(item)) |
| 135 | + newattr.append(new Option(item,item,false,false)); |
142 | 136 | }); |
| 137 | +
|
| 138 | + // Sort the attributes |
| 139 | + newattr |
| 140 | + .append($('select#newattr option') |
| 141 | + .remove() |
| 142 | + .sort(function (a,b) { |
| 143 | + let at = $(a).text(), |
| 144 | + bt = $(b).text(); |
| 145 | + return (at > bt) ? 1 : ((at < bt) ? -1 : 0); |
| 146 | + })) |
| 147 | + .val(''); |
143 | 148 | } |
144 | 149 | }, |
145 | 150 | error: function(e) { |
146 | | - if (e.status != 412) |
| 151 | + if (e.status !== 412) |
147 | 152 | alert('That didnt work? Please try again....'); |
148 | 153 | }, |
149 | | - url: '{{ url('api/schema/objectclass/attrs') }}/'+item, |
150 | | - cache: false |
151 | 154 | }); |
152 | 155 | }); |
153 | 156 |
|
|
156 | 159 | if (newadded.indexOf(item) === -1) { |
157 | 160 | $('span#objectclass_'+item).empty(); |
158 | 161 |
|
159 | | - // @todo Remove attributes from "Add new Attribute" that are no longer available |
160 | 162 | $.ajax({ |
161 | | - type: 'POST', |
162 | | - beforeSend: function() {}, |
| 163 | + method: 'POST', |
| 164 | + url: '{{ url('api/schema/objectclass/attrs') }}/'+item, |
| 165 | + cache: false, |
163 | 166 | success: function(data) { |
164 | 167 | var attrs = []; |
165 | 168 |
|
|
183 | 186 |
|
184 | 187 | x.css('background-color','#f0c0c0').attr('readonly',true).attr('placeholder',x.val()).val(''); |
185 | 188 | }); |
186 | | -
|
187 | | - // remove the Add Values box |
188 | | - // Remove any keyed in values |
189 | | - // @todo remove any required attributes that are no longer defined as a result of removing this OC |
190 | 189 | }, |
191 | 190 | error: function(e) { |
192 | | - if (e.status != 412) |
| 191 | + if (e.status !== 412) |
193 | 192 | alert('That didnt work? Please try again....'); |
194 | 193 | }, |
195 | | - url: '{{ url('api/schema/objectclass/attrs') }}/'+item, |
196 | | - cache: false |
197 | 194 | }); |
198 | 195 | } |
199 | 196 | }); |
|
0 commit comments