-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
/
Copy pathedit.blade.php
executable file
·382 lines (298 loc) · 16.3 KB
/
edit.blade.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
@extends('layouts/edit-form', [
'createText' => trans('admin/hardware/form.create'),
'updateText' => trans('admin/hardware/form.update'),
'topSubmit' => true,
'helpText' => trans('help.assets'),
'helpPosition' => 'right',
'formAction' => ($item->id) ? route('hardware.update', ['hardware' => $item->id]) : route('hardware.store'),
])
{{-- Page content --}}
@section('inputFields')
@include ('partials.forms.edit.company-select', ['translated_name' => trans('general.company'), 'fieldname' => 'company_id'])
<!-- Asset Tag -->
<div class="form-group {{ $errors->has('asset_tag') ? ' has-error' : '' }}">
<label for="asset_tag" class="col-md-3 control-label">{{ trans('admin/hardware/form.tag') }}</label>
@if ($item->id)
<!-- we are editing an existing asset, there will be only one asset tag -->
<div class="col-md-7 col-sm-12{{ (Helper::checkIfRequired($item, 'asset_tag')) ? ' required' : '' }}">
<input class="form-control" type="text" name="asset_tags[1]" id="asset_tag" value="{{ old('asset_tag', $item->asset_tag) }}" data-validation="required">
{!! $errors->first('asset_tags', '<span class="alert-msg"><i class="fas fa-times"></i> :message</span>') !!}
{!! $errors->first('asset_tag', '<span class="alert-msg"><i class="fas fa-times"></i> :message</span>') !!}
</div>
@else
<!-- we are creating a new asset - let people use more than one asset tag -->
<div class="col-md-7 col-sm-12{{ (Helper::checkIfRequired($item, 'asset_tag')) ? ' required' : '' }}">
<input class="form-control" type="text" name="asset_tags[1]" id="asset_tag" value="{{ old('asset_tags.1', \App\Models\Asset::autoincrement_asset()) }}" data-validation="required">
{!! $errors->first('asset_tags', '<span class="alert-msg"><i class="fas fa-times"></i> :message</span>') !!}
{!! $errors->first('asset_tag', '<span class="alert-msg"><i class="fas fa-times"></i> :message</span>') !!}
</div>
<div class="col-md-2 col-sm-12">
<button class="add_field_button btn btn-default btn-sm">
<i class="fas fa-plus"></i>
</button>
</div>
@endif
</div>
@include ('partials.forms.edit.serial', ['fieldname'=> 'serials[1]', 'old_val_name' => 'serials.1', 'translated_serial' => trans('admin/hardware/form.serial')])
<div class="input_fields_wrap">
</div>
@include ('partials.forms.edit.model-select', ['translated_name' => trans('admin/hardware/form.model'), 'fieldname' => 'model_id', 'field_req' => true])
@include ('partials.forms.edit.status', [ 'required' => 'true'])
@if (!$item->id)
@include ('partials.forms.checkout-selector', ['user_select' => 'true','asset_select' => 'true', 'location_select' => 'true', 'style' => 'display:none;'])
@include ('partials.forms.edit.user-select', ['translated_name' => trans('admin/hardware/form.checkout_to'), 'fieldname' => 'assigned_user', 'style' => 'display:none;', 'required' => 'false'])
@include ('partials.forms.edit.asset-select', ['translated_name' => trans('admin/hardware/form.checkout_to'), 'fieldname' => 'assigned_asset', 'style' => 'display:none;', 'required' => 'false'])
@include ('partials.forms.edit.location-select', ['translated_name' => trans('admin/hardware/form.checkout_to'), 'fieldname' => 'assigned_location', 'style' => 'display:none;', 'required' => 'false'])
@elseif (($item->assignedTo) && ($item->deleted_at == ''))
<!-- This is an asset and it's currently deployed, so let them edit the expected checkin date -->
@include ('partials.forms.edit.datepicker', ['translated_name' => trans('admin/hardware/form.expected_checkin'),'fieldname' => 'expected_checkin'])
@endif
@include ('partials.forms.edit.notes')
@include ('partials.forms.edit.location-select', ['translated_name' => trans('admin/hardware/form.default_location'), 'fieldname' => 'rtd_location_id'])
@include ('partials.forms.edit.requestable', ['requestable_text' => trans('admin/hardware/general.requestable')])
@include ('partials.forms.edit.image-upload', ['image_path' => app('assets_upload_path')])
<div id='custom_fields_content'>
<!-- Custom Fields -->
@if ($item->model && $item->model->fieldset)
<?php $model = $item->model; ?>
@endif
@if (Request::old('model_id'))
@php
$model = \App\Models\AssetModel::find(old('model_id'));
@endphp
@elseif (isset($selected_model))
@php
$model = $selected_model;
@endphp
@endif
@if (isset($model) && $model)
@include("models/custom_fields_form",["model" => $model])
@endif
</div>
<div class="form-group">
<label class="col-md-3 control-label"></label>
<div class="col-md-9 col-sm-9 col-md-offset-3">
<a id="optional_info" class="text-primary">
<i class="fa fa-caret-right fa-2x" id="optional_info_icon"></i>
<strong>{{ trans('admin/hardware/form.optional_infos') }}</strong>
</a>
</div>
<div id="optional_details" class="col-md-12" style="display:none">
<br>
@include ('partials.forms.edit.name', ['translated_name' => trans('admin/hardware/form.name')])
@include ('partials.forms.edit.warranty')
<!-- byod checkbox -->
<div class="form-group">
<div class="col-md-7 col-md-offset-3">
<label for="byod" class="form-control">
<input type="checkbox" value="1" name="byod" {{ (old('remote', $item->byod)) == '1' ? ' checked="checked"' : '' }} aria-label="byod">
{{ trans('general.byod') }}
</label>
<p class="help-block">{{ trans('general.byod_help') }}
</p>
</div>
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-9 col-sm-9 col-md-offset-3">
<a id="order_info" class="text-primary">
<i class="fa fa-caret-right fa-2x" id="order_info_icon"></i>
<strong>{{ trans('admin/hardware/form.order_details') }}</strong>
</a>
</div>
<div id='order_details' class="col-md-12" style="display:none">
<br>
@include ('partials.forms.edit.order_number')
@include ('partials.forms.edit.purchase_date')
@include ('partials.forms.edit.eol_date')
@include ('partials.forms.edit.supplier-select', ['translated_name' => trans('general.supplier'), 'fieldname' => 'supplier_id'])
@php
$currency_type = null;
if ($item->id && $item->location) {
$currency_type = $item->location->currency;
}
@endphp
@include ('partials.forms.edit.purchase_cost', ['currency_type' => $currency_type])
</div>
</div>
@stop
@section('moar_scripts')
<script nonce="{{ csrf_token() }}">
@if(Request::has('model_id'))
//TODO: Refactor custom fields to use Livewire, populate from server on page load when requested with model_id
$(document).ready(function() {
fetchCustomFields()
});
@endif
var transformed_oldvals={};
function fetchCustomFields() {
//save custom field choices
var oldvals = $('#custom_fields_content').find('input,select').serializeArray();
for(var i in oldvals) {
transformed_oldvals[oldvals[i].name]=oldvals[i].value;
}
var modelid = $('#model_select_id').val();
if (modelid == '') {
$('#custom_fields_content').html("");
} else {
$.ajax({
type: 'GET',
url: "{{ config('app.url') }}/models/" + modelid + "/custom_fields",
headers: {
"X-Requested-With": 'XMLHttpRequest',
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr('content')
},
_token: "{{ csrf_token() }}",
dataType: 'html',
success: function (data) {
$('#custom_fields_content').html(data);
$('#custom_fields_content select').select2(); //enable select2 on any custom fields that are select-boxes
//now re-populate the custom fields based on the previously saved values
$('#custom_fields_content').find('input,select').each(function (index,elem) {
if(transformed_oldvals[elem.name]) {
{{-- If there already *is* is a previously-input 'transformed_oldvals' handy,
overwrite with that previously-input value *IF* this is an edit of an existing item *OR*
if there is no new default custom field value coming from the model --}}
if({{ $item->id ? 'true' : 'false' }} || $(elem).val() == '') {
$(elem).val(transformed_oldvals[elem.name]).trigger('change'); //the trigger is for select2-based objects, if we have any
}
}
});
}
});
}
}
function user_add(status_id) {
if (status_id != '') {
$(".status_spinner").css("display", "inline");
$.ajax({
url: "{{config('app.url') }}/api/v1/statuslabels/" + status_id + "/deployable",
headers: {
"X-Requested-With": 'XMLHttpRequest',
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr('content')
},
success: function (data) {
$(".status_spinner").css("display", "none");
$("#selected_status_status").fadeIn();
if (data == true) {
$("#assignto_selector").show();
$("#assigned_user").show();
$("#selected_status_status").removeClass('text-danger');
$("#selected_status_status").removeClass('text-warning');
$("#selected_status_status").addClass('text-success');
$("#selected_status_status").html('<i class="fas fa-check"></i> {{ trans('admin/hardware/form.asset_deployable')}}');
} else {
$("#assignto_selector").hide();
$("#selected_status_status").removeClass('text-danger');
$("#selected_status_status").removeClass('text-success');
$("#selected_status_status").addClass('text-warning');
$("#selected_status_status").html('<i class="fas fa-exclamation-triangle"></i> {{ trans('admin/hardware/form.asset_not_deployable')}} ');
}
}
});
}
}
$(function () {
//grab custom fields for this model whenever model changes.
$('#model_select_id').on("change", fetchCustomFields);
//initialize assigned user/loc/asset based on statuslabel's statustype
user_add($(".status_id option:selected").val());
//whenever statuslabel changes, update assigned user/loc/asset
$(".status_id").on("change", function () {
user_add($(".status_id").val());
});
});
// Add another asset tag + serial combination if the plus sign is clicked
$(document).ready(function() {
var max_fields = 100; //maximum input boxes allowed
var wrapper = $(".input_fields_wrap"); //Fields wrapper
var add_button = $(".add_field_button"); //Add button ID
var x = 1; //initial text box count
$(add_button).click(function(e){ //on add input button click
e.preventDefault();
var auto_tag = $("#asset_tag").val().replace(/[^\d]/g, '');
var box_html = '';
const zeroPad = (num, places) => String(num).padStart(places, '0');
// Check that we haven't exceeded the max number of asset fields
if (x < max_fields) {
if (auto_tag!='') {
auto_tag = zeroPad(parseInt(auto_tag) + parseInt(x),auto_tag.length);
} else {
auto_tag = '';
}
x++; //text box increment
box_html += '<span class="fields_wrapper">';
box_html += '<div class="form-group"><label for="asset_tag" class="col-md-3 control-label">{{ trans('admin/hardware/form.tag') }} ' + x + '</label>';
box_html += '<div class="col-md-7 col-sm-12 required">';
box_html += '<input type="text" class="form-control" name="asset_tags[' + x + ']" value="{{ (($snipeSettings->auto_increment_prefix!='') && ($snipeSettings->auto_increment_assets=='1')) ? $snipeSettings->auto_increment_prefix : '' }}'+ auto_tag +'" data-validation="required">';
box_html += '</div>';
box_html += '<div class="col-md-2 col-sm-12">';
box_html += '<a href="#" class="remove_field btn btn-default btn-sm"><i class="fas fa-minus"></i></a>';
box_html += '</div>';
box_html += '</div>';
box_html += '</div>';
box_html += '<div class="form-group"><label for="serial" class="col-md-3 control-label">{{ trans('admin/hardware/form.serial') }} ' + x + '</label>';
box_html += '<div class="col-md-7 col-sm-12">';
box_html += '<input type="text" class="form-control" name="serials[' + x + ']">';
box_html += '</div>';
box_html += '</div>';
box_html += '</span>';
$(wrapper).append(box_html);
// We have reached the maximum number of extra asset fields, so disable the button
} else {
$(".add_field_button").attr('disabled');
$(".add_field_button").addClass('disabled');
}
});
$(wrapper).on("click",".remove_field", function(e){ //user clicks on remove text
$(".add_field_button").removeAttr('disabled');
$(".add_field_button").removeClass('disabled');
e.preventDefault();
//console.log(x);
$(this).parent('div').parent('div').parent('span').remove();
x--;
});
$('.expand').click(function(){
id = $(this).attr('id');
fields = $(this).text();
if (txt == '+'){
$(this).text('-');
}
else{
$(this).text('+');
}
$("#"+id).toggle();
});
{{-- TODO: Clean up some of the duplication in here. Not too high of a priority since we only copied it once. --}}
$("#optional_info").on("click",function(){
$('#optional_details').fadeToggle(100);
$('#optional_info_icon').toggleClass('fa-caret-right fa-caret-down');
var optional_info_open = $('#optional_info_icon').hasClass('fa-caret-down');
document.cookie = "optional_info_open="+optional_info_open+'; path=/';
});
$("#order_info").on("click",function(){
$('#order_details').fadeToggle(100);
$("#order_info_icon").toggleClass('fa-caret-right fa-caret-down');
var order_info_open = $('#order_info_icon').hasClass('fa-caret-down');
document.cookie = "order_info_open="+order_info_open+'; path=/';
});
var all_cookies = document.cookie.split(';')
for(var i in all_cookies) {
var trimmed_cookie = all_cookies[i].trim(' ')
if (trimmed_cookie.startsWith('optional_info_open=')) {
elems = all_cookies[i].split('=', 2)
if (elems[1] == 'true') {
$('#optional_info').trigger('click')
}
}
if (trimmed_cookie.startsWith('order_info_open=')) {
elems = all_cookies[i].split('=', 2)
if (elems[1] == 'true') {
$('#order_info').trigger('click')
}
}
}
});
</script>
@stop