",
- //String - A tooltip template
- tooltipTemplate: "<%=value %> <%=label%> "
-};
-
-//-----------------
-//- END PIE CHART -
-//-----------------
-
-var baseUrl = $('meta[name="baseUrl"]').attr('content');
-$(function () {
- var $el = $('table');
-
- // confirm restore modal
-
- $el.on('click', '.restore-asset', function (evnt) {
- var $context = $(this);
- var $restoreConfirmModal = $('#restoreConfirmModal');
- var href = $context.attr('href');
- var message = $context.attr('data-content');
- var title = $context.attr('data-title');
- $('#confirmModalLabel').text(title);
- $restoreConfirmModal.find('.modal-body').text(message);
- $('#restoreForm').attr('action', href);
- $restoreConfirmModal.modal({
- show: true
- });
- return false;
- });
-
- // confirm delete modal
-
- $el.on('click', '.delete-asset', function (evnt) {
- var $context = $(this);
- var $dataConfirmModal = $('#dataConfirmModal');
- var href = $context.attr('href');
- var message = $context.attr('data-content');
- var title = $context.attr('data-title');
- $('#myModalLabel').text(title);
- $dataConfirmModal.find('.modal-body').text(message);
- $('#deleteForm').attr('action', href);
- $dataConfirmModal.modal({
- show: true
- });
- return false;
- });
-
- /*
- * Slideout help menu
- */
- $('.slideout-menu-toggle').on('click', function (event) {
- event.preventDefault();
- // create menu variables
- var slideoutMenu = $('.slideout-menu');
- var slideoutMenuWidth = $('.slideout-menu').width();
-
- // toggle open class
- slideoutMenu.toggleClass("open");
-
- // slide menu
- if (slideoutMenu.hasClass("open")) {
- slideoutMenu.show();
- slideoutMenu.animate({
- right: "0px"
- });
- } else {
- slideoutMenu.animate({
- right: -slideoutMenuWidth
- }, "-350px");
- slideoutMenu.fadeOut();
- }
- });
-
- /*
- * Select2
- */
-
- $('select.select2:not(".select2-hidden-accessible")').each(function (i, obj) {
- {
- $(obj).select2();
- }
- });
-
- // $('.datepicker').datepicker();
- // var datepicker = $.fn.datepicker.noConflict(); // return $.fn.datepicker to previously assigned value
- // $.fn.bootstrapDP = datepicker;
- // $('.datepicker').datepicker();
-
- // Crazy select2 rich dropdowns with images!
- $('.js-data-ajax').each(function (i, item) {
- var link = $(item);
- var endpoint = link.data("endpoint");
- var select = link.data("select");
- link.select2({
- /**
- * Adds an empty placeholder, allowing every select2 instance to be cleared.
- * This placeholder can be overridden with the "data-placeholder" attribute.
- */
- placeholder: '',
- allowClear: true,
- language: $('meta[name="language"]').attr('content'),
- dir: $('meta[name="language-direction"]').attr('content'),
- ajax: {
- // the baseUrl includes a trailing slash
- url: baseUrl + 'api/v1/' + endpoint + '/selectlist',
- dataType: 'json',
- delay: 250,
- headers: {
- "X-Requested-With": 'XMLHttpRequest',
- "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr('content')
- },
- data: function data(params) {
- var data = {
- search: params.term,
- page: params.page || 1,
- assetStatusType: link.data("asset-status-type")
- };
- return data;
- },
- /* processResults: function (data, params) {
- params.page = params.page || 1;
- var answer = {
- results: data.items,
- pagination: {
- more: data.pagination.more
- }
- };
- return answer;
- }, */
- cache: true
- },
- //escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
- templateResult: formatDatalistSafe
- //templateSelection: formatDataSelection
- });
- });
- function getSelect2Value(element) {
- // if the passed object is not a jquery object, assuming 'element' is a selector
- if (!(element instanceof jQuery)) element = $(element);
- var select = element.data("select2");
-
- // There's two different locations where the select2-generated input element can be.
- searchElement = select.dropdown.$search || select.$container.find(".select2-search__field");
- var value = searchElement.val();
- return value;
- }
- $(".select2-hidden-accessible").on('select2:selecting', function (e) {
- var data = e.params.args.data;
- var isMouseUp = false;
- var element = $(this);
- var value = getSelect2Value(element);
- if (e.params.args.originalEvent) isMouseUp = e.params.args.originalEvent.type == "mouseup";
-
- // if selected item does not match typed text, do not allow it to pass - force close for ajax.
- if (!isMouseUp) {
- if (value.toLowerCase() && data.text.toLowerCase().indexOf(value) < 0) {
- e.preventDefault();
- element.select2('close');
-
- // if it does match, we set a flag in the event (which gets passed to subsequent events), telling it not to worry about the ajax
- } else if (value.toLowerCase() && data.text.toLowerCase().indexOf(value) > -1) {
- e.params.args.noForceAjax = true;
- }
- }
- });
- $(".select2-hidden-accessible").on('select2:closing', function (e) {
- var element = $(this);
- var value = getSelect2Value(element);
- var noForceAjax = false;
- var isMouseUp = false;
- if (e.params.args.originalSelect2Event) noForceAjax = e.params.args.originalSelect2Event.noForceAjax;
- if (e.params.args.originalEvent) isMouseUp = e.params.args.originalEvent.type == "mouseup";
- if (value && !noForceAjax && !isMouseUp) {
- var endpoint = element.data("endpoint");
- var assetStatusType = element.data("asset-status-type");
- $.ajax({
- url: baseUrl + 'api/v1/' + endpoint + '/selectlist?search=' + value + '&page=1' + (assetStatusType ? '&assetStatusType=' + assetStatusType : ''),
- dataType: 'json',
- headers: {
- "X-Requested-With": 'XMLHttpRequest',
- "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr('content')
- }
- }).done(function (response) {
- var currentlySelected = element.select2('data').map(function (x) {
- return +x.id;
- }).filter(function (x) {
- return x !== 0;
- });
-
- // makes sure we're not selecting the same thing twice for multiples
- var filteredResponse = response.results.filter(function (item) {
- return currentlySelected.indexOf(+item.id) < 0;
- });
- var first = currentlySelected.length > 0 ? filteredResponse[0] : response.results[0];
- if (first && first.id) {
- first.selected = true;
- if ($("option[value='" + first.id + "']", element).length < 1) {
- var option = new Option(first.text, first.id, true, true);
- element.append(option);
- } else {
- var isMultiple = element.attr("multiple") == "multiple";
- element.val(isMultiple ? element.val().concat(first.id) : element.val(first.id));
- }
- element.trigger('change');
- element.trigger({
- type: 'select2:select',
- params: {
- data: first
- }
- });
- }
- });
- }
- });
- function formatDatalist(datalist) {
- var loading_markup = ' Loading...';
- if (datalist.loading) {
- return loading_markup;
- }
- var markup = '
';
- markup += '
';
- if (datalist.image) {
- markup += "
";
- } else {
- markup += '';
- }
- markup += "
" + datalist.text + "
";
- markup += "
";
- return markup;
- }
- function formatDatalistSafe(datalist) {
- // console.warn("What in the hell is going on with Select2?!?!!?!?");
- // console.warn($.select2);
- if (datalist.loading) {
- return $(' Loading...');
- }
- var root_div = $("
");
- var left_pull = $("
");
- if (datalist.image) {
- var inner_div = $("
");
- /******************************************************************
- *
- * We are specifically chosing empty alt-text below, because this
- * image conveys no additional information, relative to the text
- * that will *always* be there in any select2 list that is in use
- * in Snipe-IT. If that changes, we would probably want to change
- * some signatures of some functions, but right now, we don't want
- * screen readers to say "HP SuperJet 5000, .... picture of HP
- * SuperJet 5000..." and so on, for every single row in a list of
- * assets or models or whatever.
- *
- *******************************************************************/
- var img = $("");
- // console.warn("Img is: ");
- // console.dir(img);
- // console.warn("Strigularly, that's: ");
- // console.log(img);
- img.attr("src", datalist.image);
- inner_div.append(img);
- } else {
- var inner_div = $("");
- }
- left_pull.append(inner_div);
- root_div.append(left_pull);
- var name_div = $("
");
- name_div.text(datalist.text);
- root_div.append(name_div);
- var safe_html = root_div.get(0).outerHTML;
- var old_html = formatDatalist(datalist);
- if (safe_html != old_html) {
- //console.log("HTML MISMATCH: ");
- //console.log("FormatDatalistSafe: ");
- // console.dir(root_div.get(0));
- //console.log(safe_html);
- //console.log("FormatDataList: ");
- //console.log(old_html);
- }
- return root_div;
- }
- function formatDataSelection(datalist) {
- // This a heinous workaround for a known bug in Select2.
- // Without this, the rich selectlists are vulnerable to XSS.
- // Many thanks to @uberbrady for this fix. It ain't pretty,
- // but it resolves the issue until Select2 addresses it on their end.
- //
- // Bug was reported in 2016 :{
- // https://github.com/select2/select2/issues/4587
-
- return datalist.text.replace(/>/g, '>').replace(/Click me
- $('a[data-toggle="tab"]').click(function (e) {
- var href = $(this).attr("href");
- history.pushState(null, null, href);
- e.preventDefault();
- $('a[href="' + $(this).attr('href') + '"]').tab('show');
- });
-
- // ------------------------------------------------
- // End Deep Linking for Bootstrap tabs
- // ------------------------------------------------
-
- // Image preview
- function readURL(input, $preview) {
- if (input.files && input.files[0]) {
- var reader = new FileReader();
- reader.onload = function (e) {
- $preview.attr('src', e.target.result);
- };
- reader.readAsDataURL(input.files[0]);
- }
- }
- function formatBytes(bytes) {
- if (bytes < 1024) return bytes + " Bytes";else if (bytes < 1048576) return (bytes / 1024).toFixed(2) + " KB";else if (bytes < 1073741824) return (bytes / 1048576).toFixed(2) + " MB";else return (bytes / 1073741824).toFixed(2) + " GB";
- }
-
- // File size validation
- $('.js-uploadFile').bind('change', function () {
- var $this = $(this);
- var id = '#' + $this.attr('id');
- var status = id + '-status';
- var $status = $(status);
- var delete_id = $(id + '-deleteCheckbox');
- var preview_container = $(id + '-previewContainer');
- $status.removeClass('text-success').removeClass('text-danger');
- $(status + ' .goodfile').remove();
- $(status + ' .badfile').remove();
- $(status + ' .previewSize').hide();
- preview_container.hide();
- $(id + '-info').html('');
- var max_size = $this.data('maxsize');
- var total_size = 0;
- for (var i = 0; i < this.files.length; i++) {
- total_size += this.files[i].size;
- $(id + '-info').append('' + htmlEntities(this.files[i].name) + ' (' + formatBytes(this.files[i].size) + ') ');
- }
- if (total_size > max_size) {
- $status.addClass('text-danger').removeClass('help-block').prepend(' ').append(' Upload is ' + formatBytes(total_size) + '.');
- } else {
- $status.addClass('text-success').removeClass('help-block').prepend(' ');
- var $preview = $(id + '-imagePreview');
- readURL(this, $preview);
- $preview.fadeIn();
- preview_container.fadeIn();
- delete_id.hide();
- }
- });
-});
-function htmlEntities(str) {
- return String(str).replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"');
-}
-
-/**
- * Toggle disabled
- */
-(function ($) {
- $.fn.toggleDisabled = function (callback) {
- return this.each(function () {
- var disabled,
- $this = $(this);
- if ($this.attr('disabled')) {
- $this.removeAttr('disabled');
- disabled = false;
- } else {
- $this.attr('disabled', 'disabled');
- disabled = true;
- }
- if (callback && typeof callback === 'function') {
- callback(this, disabled);
- }
- });
- };
-})(jQuery);
-
-/**
- * Universal Livewire Select2 integration
- *
- * How to use:
- *
- * 1. Set the class of your select2 elements to 'livewire-select2').
- * 2. Name your element to match a property in your Livewire component
- * 3. Add an attribute called 'data-livewire-component' that points to $this->getId() (via `{{ }}` if you're in a blade,
- * or just $this->getId() if not).
- */
-document.addEventListener('livewire:init', function () {
- $('.livewire-select2').select2();
- $(document).on('select2:select', '.livewire-select2', function (event) {
- var target = $(event.target);
- if (!event.target.name || !target.data('livewire-component')) {
- console.error("You need to set both name (which should match a Livewire property) and data-livewire-component on your Livewire-ed select2 elements!");
- console.error("For data-livewire-component, you probably want to use $this->getId() or {{ $this->getId() }}, as appropriate");
- return false;
- }
- Livewire.find(target.data('livewire-component')).set(event.target.name, this.options[this.selectedIndex].value);
- });
- Livewire.hook('request', function (_ref) {
- var succeed = _ref.succeed;
- succeed(function () {
- queueMicrotask(function () {
- $('.livewire-select2').select2();
- });
- });
- });
-});
-
-/***/ }),
-
-/***/ "./resources/assets/js/snipeit_modals.js":
-/*!***********************************************!*\
- !*** ./resources/assets/js/snipeit_modals.js ***!
- \***********************************************/
-/***/ (() => {
-
-/*
- *
- * Snipe-IT Universal Modal support
- *
- * Enables modal dialogs to create sub-resources throughout Snipe-IT
- *
- */
-
-/*
-HOW TO USE
- Create a Button looking like this:
- New
- If you don't have access to Blade commands (like {{ and }}, etc), you can hard-code a URL as the 'href'
- data-toggle="modal" - required for Bootstrap Modals
-data-target="#createModal" - fixed ID for the modal, do not change
-data-select="assigned_to" - What is the *ID* of the select-dropdown that you're going to be adding to, if the modal-create was a success? Be on the lookout for duplicate ID's, it will confuse this library!
-class="btn btn-sm btn-primary" - makes it look button-ey, feel free to change :)
-
-If you want to pass additional variables to the modal (In the Category Create one, for example, you can pass category_id), you can encode them as URL variables in the href
-
-*/
-
-$(function () {
- var baseUrl = $('meta[name="baseUrl"]').attr('content');
- //handle modal-add-interstitial calls
- var model, select, refreshSelector;
- if ($('#createModal').length == 0) {
- $('body').append('');
- }
- $('#createModal').on("show.bs.modal", function (event) {
- var link = $(event.relatedTarget);
- model = link.data("dependency");
- select = link.data("select");
- refreshSelector = link.data("refresh");
- $('#createModal').load(link.attr('href'), function () {
- // this sets the focus to be the name field
- $('#modal-name').focus();
-
- //do we need to re-select2 this, after load? Probably.
- $('#createModal').find('select.select2').select2();
- // Initialize the ajaxy select2 with images.
- // This is a copy/paste of the code from snipeit.js, would be great to only have this in one place.
-
- $('.js-data-ajax').each(function (i, item) {
- var link = $(item);
- var endpoint = link.data("endpoint");
- var select = link.data("select");
- link.select2({
- ajax: {
- // the baseUrl includes a trailing slash
- url: baseUrl + 'api/v1/' + endpoint + '/selectlist',
- //WARNING - we're hoping that's defined on the page somewhere...
- dataType: 'json',
- delay: 250,
- headers: {
- "X-Requested-With": 'XMLHttpRequest',
- "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr('content')
- },
- data: function data(params) {
- var data = {
- search: params.term,
- page: params.page || 1,
- assetStatusType: link.data("asset-status-type")
- };
- return data;
- },
- /*processResults: function (data, params) {
- params.page = params.page || 1;
- var answer = {
- results: data.items,
- pagination: {
- more: data.pagination.more
- }
- };
- return answer;
- },*/
- cache: true
- },
- //escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
- templateResult: formatDatalistSafe
- //templateSelection: formatDataSelection
- });
- });
- });
- });
- $('#createModal').on('click', '#modal-save', function () {
- $.ajax({
- type: 'POST',
- url: $('.modal-body form').attr('action'),
- headers: {
- "X-Requested-With": 'XMLHttpRequest',
- "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr('content')
- },
- data: $('.modal-body form').serialize(),
- success: function success(result) {
- if (result.status == "error") {
- var error_message = "";
- for (var field in result.messages) {
- error_message += "
Problem(s) with field " + field + ": " + result.messages[field];
- }
- $('#modal_error_msg').html(error_message).show();
- return false;
- }
- var id = result.payload.id;
- var name = result.payload.name || result.payload.first_name + " " + result.payload.last_name;
- if (!id || !name) {
- console.error("Could not find resulting name or ID from modal-create. Name: " + name + ", id: " + id);
- return false;
- }
- $('#createModal').modal('hide');
- $('#createModal').html("");
- var refreshTable = $('#' + refreshSelector);
- if (refreshTable.length > 0) {
- refreshTable.bootstrapTable('refresh');
- }
-
- // "select" is the original drop-down menu that someone
- // clicked 'add' on to add a new 'thing'
- // this code adds the newly created object to that select
- var selector = document.getElementById(select);
- if (!selector) {
- return false;
- }
- selector.options[selector.length] = new Option(name, id);
- selector.selectedIndex = selector.length - 1;
- $(selector).trigger("change");
- if (window.fetchCustomFields) {
- fetchCustomFields();
- }
- },
- error: function error(result) {
- msg = result.responseJSON.messages || result.responseJSON.error;
- $('#modal_error_msg').html("Server Error: " + msg).show();
- }
- });
- });
-});
-function formatDatalistSafe(datalist) {
- // console.warn("What in the hell is going on with Select2?!?!!?!?");
- // console.warn($.select2);
- if (datalist.loading) {
- return $(' Loading...');
- }
- var root_div = $("
");
- var left_pull = $("
");
- if (datalist.image) {
- var inner_div = $("
");
- /******************************************************************
- *
- * We are specifically chosing empty alt-text below, because this
- * image conveys no additional information, relative to the text
- * that will *always* be there in any select2 list that is in use
- * in Snipe-IT. If that changes, we would probably want to change
- * some signatures of some functions, but right now, we don't want
- * screen readers to say "HP SuperJet 5000, .... picture of HP
- * SuperJet 5000..." and so on, for every single row in a list of
- * assets or models or whatever.
- *
- *******************************************************************/
- var img = $("");
- // console.warn("Img is: ");
- // console.dir(img);
- // console.warn("Strigularly, that's: ");
- // console.log(img);
- img.attr("src", datalist.image);
- inner_div.append(img);
- } else {
- var inner_div = $("");
- }
- left_pull.append(inner_div);
- root_div.append(left_pull);
- var name_div = $("
",
+ //String - A tooltip template
+ tooltipTemplate: "<%=value %> <%=label%> "
+};
+
+//-----------------
+//- END PIE CHART -
+//-----------------
+
+var baseUrl = $('meta[name="baseUrl"]').attr('content');
+$(function () {
+ var $el = $('table');
+
+ // confirm restore modal
+
+ $el.on('click', '.restore-asset', function (evnt) {
+ var $context = $(this);
+ var $restoreConfirmModal = $('#restoreConfirmModal');
+ var href = $context.attr('href');
+ var message = $context.attr('data-content');
+ var title = $context.attr('data-title');
+ $('#confirmModalLabel').text(title);
+ $restoreConfirmModal.find('.modal-body').text(message);
+ $('#restoreForm').attr('action', href);
+ $restoreConfirmModal.modal({
+ show: true
+ });
+ return false;
+ });
+
+ // confirm delete modal
+
+ $el.on('click', '.delete-asset', function (evnt) {
+ var $context = $(this);
+ var $dataConfirmModal = $('#dataConfirmModal');
+ var href = $context.attr('href');
+ var message = $context.attr('data-content');
+ var title = $context.attr('data-title');
+ $('#myModalLabel').text(title);
+ $dataConfirmModal.find('.modal-body').text(message);
+ $('#deleteForm').attr('action', href);
+ $dataConfirmModal.modal({
+ show: true
+ });
+ return false;
+ });
+
+ /*
+ * Slideout help menu
+ */
+ $('.slideout-menu-toggle').on('click', function (event) {
+ event.preventDefault();
+ // create menu variables
+ var slideoutMenu = $('.slideout-menu');
+ var slideoutMenuWidth = $('.slideout-menu').width();
+
+ // toggle open class
+ slideoutMenu.toggleClass("open");
+
+ // slide menu
+ if (slideoutMenu.hasClass("open")) {
+ slideoutMenu.show();
+ slideoutMenu.animate({
+ right: "0px"
+ });
+ } else {
+ slideoutMenu.animate({
+ right: -slideoutMenuWidth
+ }, "-350px");
+ slideoutMenu.fadeOut();
+ }
+ });
+
+ /*
+ * Select2
+ */
+
+ $('select.select2:not(".select2-hidden-accessible")').each(function (i, obj) {
+ {
+ $(obj).select2();
+ }
+ });
+
+ // $('.datepicker').datepicker();
+ // var datepicker = $.fn.datepicker.noConflict(); // return $.fn.datepicker to previously assigned value
+ // $.fn.bootstrapDP = datepicker;
+ // $('.datepicker').datepicker();
+
+ // Crazy select2 rich dropdowns with images!
+ $('.js-data-ajax').each(function (i, item) {
+ var link = $(item);
+ var endpoint = link.data("endpoint");
+ var select = link.data("select");
+ link.select2({
+ /**
+ * Adds an empty placeholder, allowing every select2 instance to be cleared.
+ * This placeholder can be overridden with the "data-placeholder" attribute.
+ */
+ placeholder: '',
+ allowClear: true,
+ language: $('meta[name="language"]').attr('content'),
+ dir: $('meta[name="language-direction"]').attr('content'),
+ ajax: {
+ // the baseUrl includes a trailing slash
+ url: baseUrl + 'api/v1/' + endpoint + '/selectlist',
+ dataType: 'json',
+ delay: 250,
+ headers: {
+ "X-Requested-With": 'XMLHttpRequest',
+ "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr('content')
+ },
+ data: function data(params) {
+ var data = {
+ search: params.term,
+ page: params.page || 1,
+ assetStatusType: link.data("asset-status-type")
+ };
+ return data;
+ },
+ /* processResults: function (data, params) {
+ params.page = params.page || 1;
+ var answer = {
+ results: data.items,
+ pagination: {
+ more: data.pagination.more
+ }
+ };
+ return answer;
+ }, */
+ cache: true
+ },
+ //escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
+ templateResult: formatDatalistSafe
+ //templateSelection: formatDataSelection
+ });
+ });
+ function getSelect2Value(element) {
+ // if the passed object is not a jquery object, assuming 'element' is a selector
+ if (!(element instanceof jQuery)) element = $(element);
+ var select = element.data("select2");
+
+ // There's two different locations where the select2-generated input element can be.
+ searchElement = select.dropdown.$search || select.$container.find(".select2-search__field");
+ var value = searchElement.val();
+ return value;
+ }
+ $(".select2-hidden-accessible").on('select2:selecting', function (e) {
+ var data = e.params.args.data;
+ var isMouseUp = false;
+ var element = $(this);
+ var value = getSelect2Value(element);
+ if (e.params.args.originalEvent) isMouseUp = e.params.args.originalEvent.type == "mouseup";
+
+ // if selected item does not match typed text, do not allow it to pass - force close for ajax.
+ if (!isMouseUp) {
+ if (value.toLowerCase() && data.text.toLowerCase().indexOf(value) < 0) {
+ e.preventDefault();
+ element.select2('close');
+
+ // if it does match, we set a flag in the event (which gets passed to subsequent events), telling it not to worry about the ajax
+ } else if (value.toLowerCase() && data.text.toLowerCase().indexOf(value) > -1) {
+ e.params.args.noForceAjax = true;
+ }
+ }
+ });
+ $(".select2-hidden-accessible").on('select2:closing', function (e) {
+ var element = $(this);
+ var value = getSelect2Value(element);
+ var noForceAjax = false;
+ var isMouseUp = false;
+ if (e.params.args.originalSelect2Event) noForceAjax = e.params.args.originalSelect2Event.noForceAjax;
+ if (e.params.args.originalEvent) isMouseUp = e.params.args.originalEvent.type == "mouseup";
+ if (value && !noForceAjax && !isMouseUp) {
+ var endpoint = element.data("endpoint");
+ var assetStatusType = element.data("asset-status-type");
+ $.ajax({
+ url: baseUrl + 'api/v1/' + endpoint + '/selectlist?search=' + value + '&page=1' + (assetStatusType ? '&assetStatusType=' + assetStatusType : ''),
+ dataType: 'json',
+ headers: {
+ "X-Requested-With": 'XMLHttpRequest',
+ "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr('content')
+ }
+ }).done(function (response) {
+ var currentlySelected = element.select2('data').map(function (x) {
+ return +x.id;
+ }).filter(function (x) {
+ return x !== 0;
+ });
+
+ // makes sure we're not selecting the same thing twice for multiples
+ var filteredResponse = response.results.filter(function (item) {
+ return currentlySelected.indexOf(+item.id) < 0;
+ });
+ var first = currentlySelected.length > 0 ? filteredResponse[0] : response.results[0];
+ if (first && first.id) {
+ first.selected = true;
+ if ($("option[value='" + first.id + "']", element).length < 1) {
+ var option = new Option(first.text, first.id, true, true);
+ element.append(option);
+ } else {
+ var isMultiple = element.attr("multiple") == "multiple";
+ element.val(isMultiple ? element.val().concat(first.id) : element.val(first.id));
+ }
+ element.trigger('change');
+ element.trigger({
+ type: 'select2:select',
+ params: {
+ data: first
+ }
+ });
+ }
+ });
+ }
+ });
+ function formatDatalist(datalist) {
+ var loading_markup = ' Loading...';
+ if (datalist.loading) {
+ return loading_markup;
+ }
+ var markup = '
';
+ markup += '
';
+ if (datalist.image) {
+ markup += "
";
+ } else {
+ markup += '';
+ }
+ markup += "
" + datalist.text + "
";
+ markup += "
";
+ return markup;
+ }
+ function formatDatalistSafe(datalist) {
+ // console.warn("What in the hell is going on with Select2?!?!!?!?");
+ // console.warn($.select2);
+ if (datalist.loading) {
+ return $(' Loading...');
+ }
+ var root_div = $("
");
+ var left_pull = $("
");
+ if (datalist.image) {
+ var inner_div = $("
");
+ /******************************************************************
+ *
+ * We are specifically chosing empty alt-text below, because this
+ * image conveys no additional information, relative to the text
+ * that will *always* be there in any select2 list that is in use
+ * in Snipe-IT. If that changes, we would probably want to change
+ * some signatures of some functions, but right now, we don't want
+ * screen readers to say "HP SuperJet 5000, .... picture of HP
+ * SuperJet 5000..." and so on, for every single row in a list of
+ * assets or models or whatever.
+ *
+ *******************************************************************/
+ var img = $("");
+ // console.warn("Img is: ");
+ // console.dir(img);
+ // console.warn("Strigularly, that's: ");
+ // console.log(img);
+ img.attr("src", datalist.image);
+ inner_div.append(img);
+ } else {
+ var inner_div = $("");
+ }
+ left_pull.append(inner_div);
+ root_div.append(left_pull);
+ var name_div = $("
");
+ name_div.text(datalist.text);
+ root_div.append(name_div);
+ var safe_html = root_div.get(0).outerHTML;
+ var old_html = formatDatalist(datalist);
+ if (safe_html != old_html) {
+ //console.log("HTML MISMATCH: ");
+ //console.log("FormatDatalistSafe: ");
+ // console.dir(root_div.get(0));
+ //console.log(safe_html);
+ //console.log("FormatDataList: ");
+ //console.log(old_html);
+ }
+ return root_div;
+ }
+ function formatDataSelection(datalist) {
+ // This a heinous workaround for a known bug in Select2.
+ // Without this, the rich selectlists are vulnerable to XSS.
+ // Many thanks to @uberbrady for this fix. It ain't pretty,
+ // but it resolves the issue until Select2 addresses it on their end.
+ //
+ // Bug was reported in 2016 :{
+ // https://github.com/select2/select2/issues/4587
+
+ return datalist.text.replace(/>/g, '>').replace(/Click me
+ $('a[data-toggle="tab"]').click(function (e) {
+ var href = $(this).attr("href");
+ history.pushState(null, null, href);
+ e.preventDefault();
+ $('a[href="' + $(this).attr('href') + '"]').tab('show');
+ });
+
+ // ------------------------------------------------
+ // End Deep Linking for Bootstrap tabs
+ // ------------------------------------------------
+
+ // Image preview
+ function readURL(input, $preview) {
+ if (input.files && input.files[0]) {
+ var reader = new FileReader();
+ reader.onload = function (e) {
+ $preview.attr('src', e.target.result);
+ };
+ reader.readAsDataURL(input.files[0]);
+ }
+ }
+ function formatBytes(bytes) {
+ if (bytes < 1024) return bytes + " Bytes";else if (bytes < 1048576) return (bytes / 1024).toFixed(2) + " KB";else if (bytes < 1073741824) return (bytes / 1048576).toFixed(2) + " MB";else return (bytes / 1073741824).toFixed(2) + " GB";
+ }
+
+ // File size validation
+ $('.js-uploadFile').bind('change', function () {
+ var $this = $(this);
+ var id = '#' + $this.attr('id');
+ var status = id + '-status';
+ var $status = $(status);
+ var delete_id = $(id + '-deleteCheckbox');
+ var preview_container = $(id + '-previewContainer');
+ $status.removeClass('text-success').removeClass('text-danger');
+ $(status + ' .goodfile').remove();
+ $(status + ' .badfile').remove();
+ $(status + ' .previewSize').hide();
+ preview_container.hide();
+ $(id + '-info').html('');
+ var max_size = $this.data('maxsize');
+ var total_size = 0;
+ for (var i = 0; i < this.files.length; i++) {
+ total_size += this.files[i].size;
+ $(id + '-info').append('' + htmlEntities(this.files[i].name) + ' (' + formatBytes(this.files[i].size) + ') ');
+ }
+ if (total_size > max_size) {
+ $status.addClass('text-danger').removeClass('help-block').prepend(' ').append(' Upload is ' + formatBytes(total_size) + '.');
+ } else {
+ $status.addClass('text-success').removeClass('help-block').prepend(' ');
+ var $preview = $(id + '-imagePreview');
+ readURL(this, $preview);
+ $preview.fadeIn();
+ preview_container.fadeIn();
+ delete_id.hide();
+ }
+ });
+});
+function htmlEntities(str) {
+ return String(str).replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"');
+}
+
+/**
+ * Toggle disabled
+ */
+(function ($) {
+ $.fn.toggleDisabled = function (callback) {
+ return this.each(function () {
+ var disabled,
+ $this = $(this);
+ if ($this.attr('disabled')) {
+ $this.removeAttr('disabled');
+ disabled = false;
+ } else {
+ $this.attr('disabled', 'disabled');
+ disabled = true;
+ }
+ if (callback && typeof callback === 'function') {
+ callback(this, disabled);
+ }
+ });
+ };
+})(jQuery);
+
+/**
+ * Universal Livewire Select2 integration
+ *
+ * How to use:
+ *
+ * 1. Set the class of your select2 elements to 'livewire-select2').
+ * 2. Name your element to match a property in your Livewire component
+ * 3. Add an attribute called 'data-livewire-component' that points to $this->getId() (via `{{ }}` if you're in a blade,
+ * or just $this->getId() if not).
+ */
+document.addEventListener('livewire:init', function () {
+ $('.livewire-select2').select2();
+ $(document).on('select2:select', '.livewire-select2', function (event) {
+ var target = $(event.target);
+ if (!event.target.name || !target.data('livewire-component')) {
+ console.error("You need to set both name (which should match a Livewire property) and data-livewire-component on your Livewire-ed select2 elements!");
+ console.error("For data-livewire-component, you probably want to use $this->getId() or {{ $this->getId() }}, as appropriate");
+ return false;
+ }
+ Livewire.find(target.data('livewire-component')).set(event.target.name, this.options[this.selectedIndex].value);
+ });
+ Livewire.hook('request', function (_ref) {
+ var succeed = _ref.succeed;
+ succeed(function () {
+ queueMicrotask(function () {
+ $('.livewire-select2').select2();
+ });
+ });
+ });
+});
+
+/***/ }),
+
+/***/ "./resources/assets/js/snipeit_modals.js":
+/*!***********************************************!*\
+ !*** ./resources/assets/js/snipeit_modals.js ***!
+ \***********************************************/
+/***/ (() => {
+
+/*
+ *
+ * Snipe-IT Universal Modal support
+ *
+ * Enables modal dialogs to create sub-resources throughout Snipe-IT
+ *
+ */
+
+/*
+HOW TO USE
+ Create a Button looking like this:
+ New
+ If you don't have access to Blade commands (like {{ and }}, etc), you can hard-code a URL as the 'href'
+ data-toggle="modal" - required for Bootstrap Modals
+data-target="#createModal" - fixed ID for the modal, do not change
+data-select="assigned_to" - What is the *ID* of the select-dropdown that you're going to be adding to, if the modal-create was a success? Be on the lookout for duplicate ID's, it will confuse this library!
+class="btn btn-sm btn-primary" - makes it look button-ey, feel free to change :)
+
+If you want to pass additional variables to the modal (In the Category Create one, for example, you can pass category_id), you can encode them as URL variables in the href
+
+*/
+
+$(function () {
+ var baseUrl = $('meta[name="baseUrl"]').attr('content');
+ //handle modal-add-interstitial calls
+ var model, select, refreshSelector;
+ if ($('#createModal').length == 0) {
+ $('body').append('');
+ }
+ $('#createModal').on("show.bs.modal", function (event) {
+ var link = $(event.relatedTarget);
+ model = link.data("dependency");
+ select = link.data("select");
+ refreshSelector = link.data("refresh");
+ $('#createModal').load(link.attr('href'), function () {
+ // this sets the focus to be the name field
+ $('#modal-name').focus();
+
+ //do we need to re-select2 this, after load? Probably.
+ $('#createModal').find('select.select2').select2();
+ // Initialize the ajaxy select2 with images.
+ // This is a copy/paste of the code from snipeit.js, would be great to only have this in one place.
+
+ $('.js-data-ajax').each(function (i, item) {
+ var link = $(item);
+ var endpoint = link.data("endpoint");
+ var select = link.data("select");
+ link.select2({
+ ajax: {
+ // the baseUrl includes a trailing slash
+ url: baseUrl + 'api/v1/' + endpoint + '/selectlist',
+ //WARNING - we're hoping that's defined on the page somewhere...
+ dataType: 'json',
+ delay: 250,
+ headers: {
+ "X-Requested-With": 'XMLHttpRequest',
+ "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr('content')
+ },
+ data: function data(params) {
+ var data = {
+ search: params.term,
+ page: params.page || 1,
+ assetStatusType: link.data("asset-status-type")
+ };
+ return data;
+ },
+ /*processResults: function (data, params) {
+ params.page = params.page || 1;
+ var answer = {
+ results: data.items,
+ pagination: {
+ more: data.pagination.more
+ }
+ };
+ return answer;
+ },*/
+ cache: true
+ },
+ //escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
+ templateResult: formatDatalistSafe
+ //templateSelection: formatDataSelection
+ });
+ });
+ });
+ });
+ $('#createModal').on('click', '#modal-save', function () {
+ $.ajax({
+ type: 'POST',
+ url: $('.modal-body form').attr('action'),
+ headers: {
+ "X-Requested-With": 'XMLHttpRequest',
+ "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr('content')
+ },
+ data: $('.modal-body form').serialize(),
+ success: function success(result) {
+ if (result.status == "error") {
+ var error_message = "";
+ for (var field in result.messages) {
+ error_message += "
Problem(s) with field " + field + ": " + result.messages[field];
+ }
+ $('#modal_error_msg').html(error_message).show();
+ return false;
+ }
+ var id = result.payload.id;
+ var name = result.payload.name || result.payload.first_name + " " + result.payload.last_name;
+ if (!id || !name) {
+ console.error("Could not find resulting name or ID from modal-create. Name: " + name + ", id: " + id);
+ return false;
+ }
+ $('#createModal').modal('hide');
+ $('#createModal').html("");
+ var refreshTable = $('#' + refreshSelector);
+ if (refreshTable.length > 0) {
+ refreshTable.bootstrapTable('refresh');
+ }
+
+ // "select" is the original drop-down menu that someone
+ // clicked 'add' on to add a new 'thing'
+ // this code adds the newly created object to that select
+ var selector = document.getElementById(select);
+ if (!selector) {
+ return false;
+ }
+ selector.options[selector.length] = new Option(name, id);
+ selector.selectedIndex = selector.length - 1;
+ $(selector).trigger("change");
+ if (window.fetchCustomFields) {
+ fetchCustomFields();
+ }
+ },
+ error: function error(result) {
+ msg = result.responseJSON.messages || result.responseJSON.error;
+ $('#modal_error_msg').html("Server Error: " + msg).show();
+ }
+ });
+ });
+});
+function formatDatalistSafe(datalist) {
+ // console.warn("What in the hell is going on with Select2?!?!!?!?");
+ // console.warn($.select2);
+ if (datalist.loading) {
+ return $(' Loading...');
+ }
+ var root_div = $("
");
+ var left_pull = $("
");
+ if (datalist.image) {
+ var inner_div = $("
");
+ /******************************************************************
+ *
+ * We are specifically chosing empty alt-text below, because this
+ * image conveys no additional information, relative to the text
+ * that will *always* be there in any select2 list that is in use
+ * in Snipe-IT. If that changes, we would probably want to change
+ * some signatures of some functions, but right now, we don't want
+ * screen readers to say "HP SuperJet 5000, .... picture of HP
+ * SuperJet 5000..." and so on, for every single row in a list of
+ * assets or models or whatever.
+ *
+ *******************************************************************/
+ var img = $("");
+ // console.warn("Img is: ");
+ // console.dir(img);
+ // console.warn("Strigularly, that's: ");
+ // console.log(img);
+ img.attr("src", datalist.image);
+ inner_div.append(img);
+ } else {
+ var inner_div = $("");
+ }
+ left_pull.append(inner_div);
+ root_div.append(left_pull);
+ var name_div = $("
",
- //String - A tooltip template
- tooltipTemplate: "<%=value %> <%=label%> "
-};
-
-//-----------------
-//- END PIE CHART -
-//-----------------
-
-var baseUrl = $('meta[name="baseUrl"]').attr('content');
-$(function () {
- var $el = $('table');
-
- // confirm restore modal
-
- $el.on('click', '.restore-asset', function (evnt) {
- var $context = $(this);
- var $restoreConfirmModal = $('#restoreConfirmModal');
- var href = $context.attr('href');
- var message = $context.attr('data-content');
- var title = $context.attr('data-title');
- $('#confirmModalLabel').text(title);
- $restoreConfirmModal.find('.modal-body').text(message);
- $('#restoreForm').attr('action', href);
- $restoreConfirmModal.modal({
- show: true
- });
- return false;
- });
-
- // confirm delete modal
-
- $el.on('click', '.delete-asset', function (evnt) {
- var $context = $(this);
- var $dataConfirmModal = $('#dataConfirmModal');
- var href = $context.attr('href');
- var message = $context.attr('data-content');
- var title = $context.attr('data-title');
- $('#myModalLabel').text(title);
- $dataConfirmModal.find('.modal-body').text(message);
- $('#deleteForm').attr('action', href);
- $dataConfirmModal.modal({
- show: true
- });
- return false;
- });
-
- /*
- * Slideout help menu
- */
- $('.slideout-menu-toggle').on('click', function (event) {
- event.preventDefault();
- // create menu variables
- var slideoutMenu = $('.slideout-menu');
- var slideoutMenuWidth = $('.slideout-menu').width();
-
- // toggle open class
- slideoutMenu.toggleClass("open");
-
- // slide menu
- if (slideoutMenu.hasClass("open")) {
- slideoutMenu.show();
- slideoutMenu.animate({
- right: "0px"
- });
- } else {
- slideoutMenu.animate({
- right: -slideoutMenuWidth
- }, "-350px");
- slideoutMenu.fadeOut();
- }
- });
-
- /*
- * Select2
- */
-
- $('select.select2:not(".select2-hidden-accessible")').each(function (i, obj) {
- {
- $(obj).select2();
- }
- });
-
- // $('.datepicker').datepicker();
- // var datepicker = $.fn.datepicker.noConflict(); // return $.fn.datepicker to previously assigned value
- // $.fn.bootstrapDP = datepicker;
- // $('.datepicker').datepicker();
-
- // Crazy select2 rich dropdowns with images!
- $('.js-data-ajax').each(function (i, item) {
- var link = $(item);
- var endpoint = link.data("endpoint");
- var select = link.data("select");
- link.select2({
- /**
- * Adds an empty placeholder, allowing every select2 instance to be cleared.
- * This placeholder can be overridden with the "data-placeholder" attribute.
- */
- placeholder: '',
- allowClear: true,
- language: $('meta[name="language"]').attr('content'),
- dir: $('meta[name="language-direction"]').attr('content'),
- ajax: {
- // the baseUrl includes a trailing slash
- url: baseUrl + 'api/v1/' + endpoint + '/selectlist',
- dataType: 'json',
- delay: 250,
- headers: {
- "X-Requested-With": 'XMLHttpRequest',
- "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr('content')
- },
- data: function data(params) {
- var data = {
- search: params.term,
- page: params.page || 1,
- assetStatusType: link.data("asset-status-type")
- };
- return data;
- },
- /* processResults: function (data, params) {
- params.page = params.page || 1;
- var answer = {
- results: data.items,
- pagination: {
- more: data.pagination.more
- }
- };
- return answer;
- }, */
- cache: true
- },
- //escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
- templateResult: formatDatalistSafe
- //templateSelection: formatDataSelection
- });
- });
- function getSelect2Value(element) {
- // if the passed object is not a jquery object, assuming 'element' is a selector
- if (!(element instanceof jQuery)) element = $(element);
- var select = element.data("select2");
-
- // There's two different locations where the select2-generated input element can be.
- searchElement = select.dropdown.$search || select.$container.find(".select2-search__field");
- var value = searchElement.val();
- return value;
- }
- $(".select2-hidden-accessible").on('select2:selecting', function (e) {
- var data = e.params.args.data;
- var isMouseUp = false;
- var element = $(this);
- var value = getSelect2Value(element);
- if (e.params.args.originalEvent) isMouseUp = e.params.args.originalEvent.type == "mouseup";
-
- // if selected item does not match typed text, do not allow it to pass - force close for ajax.
- if (!isMouseUp) {
- if (value.toLowerCase() && data.text.toLowerCase().indexOf(value) < 0) {
- e.preventDefault();
- element.select2('close');
-
- // if it does match, we set a flag in the event (which gets passed to subsequent events), telling it not to worry about the ajax
- } else if (value.toLowerCase() && data.text.toLowerCase().indexOf(value) > -1) {
- e.params.args.noForceAjax = true;
- }
- }
- });
- $(".select2-hidden-accessible").on('select2:closing', function (e) {
- var element = $(this);
- var value = getSelect2Value(element);
- var noForceAjax = false;
- var isMouseUp = false;
- if (e.params.args.originalSelect2Event) noForceAjax = e.params.args.originalSelect2Event.noForceAjax;
- if (e.params.args.originalEvent) isMouseUp = e.params.args.originalEvent.type == "mouseup";
- if (value && !noForceAjax && !isMouseUp) {
- var endpoint = element.data("endpoint");
- var assetStatusType = element.data("asset-status-type");
- $.ajax({
- url: baseUrl + 'api/v1/' + endpoint + '/selectlist?search=' + value + '&page=1' + (assetStatusType ? '&assetStatusType=' + assetStatusType : ''),
- dataType: 'json',
- headers: {
- "X-Requested-With": 'XMLHttpRequest',
- "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr('content')
- }
- }).done(function (response) {
- var currentlySelected = element.select2('data').map(function (x) {
- return +x.id;
- }).filter(function (x) {
- return x !== 0;
- });
-
- // makes sure we're not selecting the same thing twice for multiples
- var filteredResponse = response.results.filter(function (item) {
- return currentlySelected.indexOf(+item.id) < 0;
- });
- var first = currentlySelected.length > 0 ? filteredResponse[0] : response.results[0];
- if (first && first.id) {
- first.selected = true;
- if ($("option[value='" + first.id + "']", element).length < 1) {
- var option = new Option(first.text, first.id, true, true);
- element.append(option);
- } else {
- var isMultiple = element.attr("multiple") == "multiple";
- element.val(isMultiple ? element.val().concat(first.id) : element.val(first.id));
- }
- element.trigger('change');
- element.trigger({
- type: 'select2:select',
- params: {
- data: first
- }
- });
- }
- });
- }
- });
- function formatDatalist(datalist) {
- var loading_markup = ' Loading...';
- if (datalist.loading) {
- return loading_markup;
- }
- var markup = '
';
- markup += '
';
- if (datalist.image) {
- markup += "
";
- } else {
- markup += '';
- }
- markup += "
" + datalist.text + "
";
- markup += "
";
- return markup;
- }
- function formatDatalistSafe(datalist) {
- // console.warn("What in the hell is going on with Select2?!?!!?!?");
- // console.warn($.select2);
- if (datalist.loading) {
- return $(' Loading...');
- }
- var root_div = $("
");
- var left_pull = $("
");
- if (datalist.image) {
- var inner_div = $("
");
- /******************************************************************
- *
- * We are specifically chosing empty alt-text below, because this
- * image conveys no additional information, relative to the text
- * that will *always* be there in any select2 list that is in use
- * in Snipe-IT. If that changes, we would probably want to change
- * some signatures of some functions, but right now, we don't want
- * screen readers to say "HP SuperJet 5000, .... picture of HP
- * SuperJet 5000..." and so on, for every single row in a list of
- * assets or models or whatever.
- *
- *******************************************************************/
- var img = $("");
- // console.warn("Img is: ");
- // console.dir(img);
- // console.warn("Strigularly, that's: ");
- // console.log(img);
- img.attr("src", datalist.image);
- inner_div.append(img);
- } else {
- var inner_div = $("");
- }
- left_pull.append(inner_div);
- root_div.append(left_pull);
- var name_div = $("
");
- name_div.text(datalist.text);
- root_div.append(name_div);
- var safe_html = root_div.get(0).outerHTML;
- var old_html = formatDatalist(datalist);
- if (safe_html != old_html) {
- //console.log("HTML MISMATCH: ");
- //console.log("FormatDatalistSafe: ");
- // console.dir(root_div.get(0));
- //console.log(safe_html);
- //console.log("FormatDataList: ");
- //console.log(old_html);
- }
- return root_div;
- }
- function formatDataSelection(datalist) {
- // This a heinous workaround for a known bug in Select2.
- // Without this, the rich selectlists are vulnerable to XSS.
- // Many thanks to @uberbrady for this fix. It ain't pretty,
- // but it resolves the issue until Select2 addresses it on their end.
- //
- // Bug was reported in 2016 :{
- // https://github.com/select2/select2/issues/4587
-
- return datalist.text.replace(/>/g, '>').replace(/Click me
- $('a[data-toggle="tab"]').click(function (e) {
- var href = $(this).attr("href");
- history.pushState(null, null, href);
- e.preventDefault();
- $('a[href="' + $(this).attr('href') + '"]').tab('show');
- });
-
- // ------------------------------------------------
- // End Deep Linking for Bootstrap tabs
- // ------------------------------------------------
-
- // Image preview
- function readURL(input, $preview) {
- if (input.files && input.files[0]) {
- var reader = new FileReader();
- reader.onload = function (e) {
- $preview.attr('src', e.target.result);
- };
- reader.readAsDataURL(input.files[0]);
- }
- }
- function formatBytes(bytes) {
- if (bytes < 1024) return bytes + " Bytes";else if (bytes < 1048576) return (bytes / 1024).toFixed(2) + " KB";else if (bytes < 1073741824) return (bytes / 1048576).toFixed(2) + " MB";else return (bytes / 1073741824).toFixed(2) + " GB";
- }
-
- // File size validation
- $('.js-uploadFile').bind('change', function () {
- var $this = $(this);
- var id = '#' + $this.attr('id');
- var status = id + '-status';
- var $status = $(status);
- var delete_id = $(id + '-deleteCheckbox');
- var preview_container = $(id + '-previewContainer');
- $status.removeClass('text-success').removeClass('text-danger');
- $(status + ' .goodfile').remove();
- $(status + ' .badfile').remove();
- $(status + ' .previewSize').hide();
- preview_container.hide();
- $(id + '-info').html('');
- var max_size = $this.data('maxsize');
- var total_size = 0;
- for (var i = 0; i < this.files.length; i++) {
- total_size += this.files[i].size;
- $(id + '-info').append('' + htmlEntities(this.files[i].name) + ' (' + formatBytes(this.files[i].size) + ') ');
- }
- if (total_size > max_size) {
- $status.addClass('text-danger').removeClass('help-block').prepend(' ').append(' Upload is ' + formatBytes(total_size) + '.');
- } else {
- $status.addClass('text-success').removeClass('help-block').prepend(' ');
- var $preview = $(id + '-imagePreview');
- readURL(this, $preview);
- $preview.fadeIn();
- preview_container.fadeIn();
- delete_id.hide();
- }
- });
-});
-function htmlEntities(str) {
- return String(str).replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"');
-}
-
-/**
- * Toggle disabled
- */
-(function ($) {
- $.fn.toggleDisabled = function (callback) {
- return this.each(function () {
- var disabled,
- $this = $(this);
- if ($this.attr('disabled')) {
- $this.removeAttr('disabled');
- disabled = false;
- } else {
- $this.attr('disabled', 'disabled');
- disabled = true;
- }
- if (callback && typeof callback === 'function') {
- callback(this, disabled);
- }
- });
- };
-})(jQuery);
-
-/**
- * Universal Livewire Select2 integration
- *
- * How to use:
- *
- * 1. Set the class of your select2 elements to 'livewire-select2').
- * 2. Name your element to match a property in your Livewire component
- * 3. Add an attribute called 'data-livewire-component' that points to $this->getId() (via `{{ }}` if you're in a blade,
- * or just $this->getId() if not).
- */
-document.addEventListener('livewire:init', function () {
- $('.livewire-select2').select2();
- $(document).on('select2:select', '.livewire-select2', function (event) {
- var target = $(event.target);
- if (!event.target.name || !target.data('livewire-component')) {
- console.error("You need to set both name (which should match a Livewire property) and data-livewire-component on your Livewire-ed select2 elements!");
- console.error("For data-livewire-component, you probably want to use $this->getId() or {{ $this->getId() }}, as appropriate");
- return false;
- }
- Livewire.find(target.data('livewire-component')).set(event.target.name, this.options[this.selectedIndex].value);
- });
- Livewire.hook('request', function (_ref) {
- var succeed = _ref.succeed;
- succeed(function () {
- queueMicrotask(function () {
- $('.livewire-select2').select2();
- });
- });
- });
-});
-
-/***/ }),
-
-/***/ "./resources/assets/js/snipeit_modals.js":
-/*!***********************************************!*\
- !*** ./resources/assets/js/snipeit_modals.js ***!
- \***********************************************/
-/***/ (() => {
-
-/*
- *
- * Snipe-IT Universal Modal support
- *
- * Enables modal dialogs to create sub-resources throughout Snipe-IT
- *
- */
-
-/*
-HOW TO USE
- Create a Button looking like this:
- New
- If you don't have access to Blade commands (like {{ and }}, etc), you can hard-code a URL as the 'href'
- data-toggle="modal" - required for Bootstrap Modals
-data-target="#createModal" - fixed ID for the modal, do not change
-data-select="assigned_to" - What is the *ID* of the select-dropdown that you're going to be adding to, if the modal-create was a success? Be on the lookout for duplicate ID's, it will confuse this library!
-class="btn btn-sm btn-primary" - makes it look button-ey, feel free to change :)
-
-If you want to pass additional variables to the modal (In the Category Create one, for example, you can pass category_id), you can encode them as URL variables in the href
-
-*/
-
-$(function () {
- var baseUrl = $('meta[name="baseUrl"]').attr('content');
- //handle modal-add-interstitial calls
- var model, select, refreshSelector;
- if ($('#createModal').length == 0) {
- $('body').append('');
- }
- $('#createModal').on("show.bs.modal", function (event) {
- var link = $(event.relatedTarget);
- model = link.data("dependency");
- select = link.data("select");
- refreshSelector = link.data("refresh");
- $('#createModal').load(link.attr('href'), function () {
- // this sets the focus to be the name field
- $('#modal-name').focus();
-
- //do we need to re-select2 this, after load? Probably.
- $('#createModal').find('select.select2').select2();
- // Initialize the ajaxy select2 with images.
- // This is a copy/paste of the code from snipeit.js, would be great to only have this in one place.
-
- $('.js-data-ajax').each(function (i, item) {
- var link = $(item);
- var endpoint = link.data("endpoint");
- var select = link.data("select");
- link.select2({
- ajax: {
- // the baseUrl includes a trailing slash
- url: baseUrl + 'api/v1/' + endpoint + '/selectlist',
- //WARNING - we're hoping that's defined on the page somewhere...
- dataType: 'json',
- delay: 250,
- headers: {
- "X-Requested-With": 'XMLHttpRequest',
- "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr('content')
- },
- data: function data(params) {
- var data = {
- search: params.term,
- page: params.page || 1,
- assetStatusType: link.data("asset-status-type")
- };
- return data;
- },
- /*processResults: function (data, params) {
- params.page = params.page || 1;
- var answer = {
- results: data.items,
- pagination: {
- more: data.pagination.more
- }
- };
- return answer;
- },*/
- cache: true
- },
- //escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
- templateResult: formatDatalistSafe
- //templateSelection: formatDataSelection
- });
- });
- });
- });
- $('#createModal').on('click', '#modal-save', function () {
- $.ajax({
- type: 'POST',
- url: $('.modal-body form').attr('action'),
- headers: {
- "X-Requested-With": 'XMLHttpRequest',
- "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr('content')
- },
- data: $('.modal-body form').serialize(),
- success: function success(result) {
- if (result.status == "error") {
- var error_message = "";
- for (var field in result.messages) {
- error_message += "
Problem(s) with field " + field + ": " + result.messages[field];
- }
- $('#modal_error_msg').html(error_message).show();
- return false;
- }
- var id = result.payload.id;
- var name = result.payload.name || result.payload.first_name + " " + result.payload.last_name;
- if (!id || !name) {
- console.error("Could not find resulting name or ID from modal-create. Name: " + name + ", id: " + id);
- return false;
- }
- $('#createModal').modal('hide');
- $('#createModal').html("");
- var refreshTable = $('#' + refreshSelector);
- if (refreshTable.length > 0) {
- refreshTable.bootstrapTable('refresh');
- }
-
- // "select" is the original drop-down menu that someone
- // clicked 'add' on to add a new 'thing'
- // this code adds the newly created object to that select
- var selector = document.getElementById(select);
- if (!selector) {
- return false;
- }
- selector.options[selector.length] = new Option(name, id);
- selector.selectedIndex = selector.length - 1;
- $(selector).trigger("change");
- if (window.fetchCustomFields) {
- fetchCustomFields();
- }
- },
- error: function error(result) {
- msg = result.responseJSON.messages || result.responseJSON.error;
- $('#modal_error_msg').html("Server Error: " + msg).show();
- }
- });
- });
-});
-function formatDatalistSafe(datalist) {
- // console.warn("What in the hell is going on with Select2?!?!!?!?");
- // console.warn($.select2);
- if (datalist.loading) {
- return $(' Loading...');
- }
- var root_div = $("
");
- var left_pull = $("
");
- if (datalist.image) {
- var inner_div = $("
");
- /******************************************************************
- *
- * We are specifically chosing empty alt-text below, because this
- * image conveys no additional information, relative to the text
- * that will *always* be there in any select2 list that is in use
- * in Snipe-IT. If that changes, we would probably want to change
- * some signatures of some functions, but right now, we don't want
- * screen readers to say "HP SuperJet 5000, .... picture of HP
- * SuperJet 5000..." and so on, for every single row in a list of
- * assets or models or whatever.
- *
- *******************************************************************/
- var img = $("");
- // console.warn("Img is: ");
- // console.dir(img);
- // console.warn("Strigularly, that's: ");
- // console.log(img);
- img.attr("src", datalist.image);
- inner_div.append(img);
- } else {
- var inner_div = $("");
- }
- left_pull.append(inner_div);
- root_div.append(left_pull);
- var name_div = $("
",
+ //String - A tooltip template
+ tooltipTemplate: "<%=value %> <%=label%> "
+};
+
+//-----------------
+//- END PIE CHART -
+//-----------------
+
+var baseUrl = $('meta[name="baseUrl"]').attr('content');
+$(function () {
+ var $el = $('table');
+
+ // confirm restore modal
+
+ $el.on('click', '.restore-asset', function (evnt) {
+ var $context = $(this);
+ var $restoreConfirmModal = $('#restoreConfirmModal');
+ var href = $context.attr('href');
+ var message = $context.attr('data-content');
+ var title = $context.attr('data-title');
+ $('#confirmModalLabel').text(title);
+ $restoreConfirmModal.find('.modal-body').text(message);
+ $('#restoreForm').attr('action', href);
+ $restoreConfirmModal.modal({
+ show: true
+ });
+ return false;
+ });
+
+ // confirm delete modal
+
+ $el.on('click', '.delete-asset', function (evnt) {
+ var $context = $(this);
+ var $dataConfirmModal = $('#dataConfirmModal');
+ var href = $context.attr('href');
+ var message = $context.attr('data-content');
+ var title = $context.attr('data-title');
+ $('#myModalLabel').text(title);
+ $dataConfirmModal.find('.modal-body').text(message);
+ $('#deleteForm').attr('action', href);
+ $dataConfirmModal.modal({
+ show: true
+ });
+ return false;
+ });
+
+ /*
+ * Slideout help menu
+ */
+ $('.slideout-menu-toggle').on('click', function (event) {
+ event.preventDefault();
+ // create menu variables
+ var slideoutMenu = $('.slideout-menu');
+ var slideoutMenuWidth = $('.slideout-menu').width();
+
+ // toggle open class
+ slideoutMenu.toggleClass("open");
+
+ // slide menu
+ if (slideoutMenu.hasClass("open")) {
+ slideoutMenu.show();
+ slideoutMenu.animate({
+ right: "0px"
+ });
+ } else {
+ slideoutMenu.animate({
+ right: -slideoutMenuWidth
+ }, "-350px");
+ slideoutMenu.fadeOut();
+ }
+ });
+
+ /*
+ * Select2
+ */
+
+ $('select.select2:not(".select2-hidden-accessible")').each(function (i, obj) {
+ {
+ $(obj).select2();
+ }
+ });
+
+ // $('.datepicker').datepicker();
+ // var datepicker = $.fn.datepicker.noConflict(); // return $.fn.datepicker to previously assigned value
+ // $.fn.bootstrapDP = datepicker;
+ // $('.datepicker').datepicker();
+
+ // Crazy select2 rich dropdowns with images!
+ $('.js-data-ajax').each(function (i, item) {
+ var link = $(item);
+ var endpoint = link.data("endpoint");
+ var select = link.data("select");
+ link.select2({
+ /**
+ * Adds an empty placeholder, allowing every select2 instance to be cleared.
+ * This placeholder can be overridden with the "data-placeholder" attribute.
+ */
+ placeholder: '',
+ allowClear: true,
+ language: $('meta[name="language"]').attr('content'),
+ dir: $('meta[name="language-direction"]').attr('content'),
+ ajax: {
+ // the baseUrl includes a trailing slash
+ url: baseUrl + 'api/v1/' + endpoint + '/selectlist',
+ dataType: 'json',
+ delay: 250,
+ headers: {
+ "X-Requested-With": 'XMLHttpRequest',
+ "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr('content')
+ },
+ data: function data(params) {
+ var data = {
+ search: params.term,
+ page: params.page || 1,
+ assetStatusType: link.data("asset-status-type")
+ };
+ return data;
+ },
+ /* processResults: function (data, params) {
+ params.page = params.page || 1;
+ var answer = {
+ results: data.items,
+ pagination: {
+ more: data.pagination.more
+ }
+ };
+ return answer;
+ }, */
+ cache: true
+ },
+ //escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
+ templateResult: formatDatalistSafe
+ //templateSelection: formatDataSelection
+ });
+ });
+ function getSelect2Value(element) {
+ // if the passed object is not a jquery object, assuming 'element' is a selector
+ if (!(element instanceof jQuery)) element = $(element);
+ var select = element.data("select2");
+
+ // There's two different locations where the select2-generated input element can be.
+ searchElement = select.dropdown.$search || select.$container.find(".select2-search__field");
+ var value = searchElement.val();
+ return value;
+ }
+ $(".select2-hidden-accessible").on('select2:selecting', function (e) {
+ var data = e.params.args.data;
+ var isMouseUp = false;
+ var element = $(this);
+ var value = getSelect2Value(element);
+ if (e.params.args.originalEvent) isMouseUp = e.params.args.originalEvent.type == "mouseup";
+
+ // if selected item does not match typed text, do not allow it to pass - force close for ajax.
+ if (!isMouseUp) {
+ if (value.toLowerCase() && data.text.toLowerCase().indexOf(value) < 0) {
+ e.preventDefault();
+ element.select2('close');
+
+ // if it does match, we set a flag in the event (which gets passed to subsequent events), telling it not to worry about the ajax
+ } else if (value.toLowerCase() && data.text.toLowerCase().indexOf(value) > -1) {
+ e.params.args.noForceAjax = true;
+ }
+ }
+ });
+ $(".select2-hidden-accessible").on('select2:closing', function (e) {
+ var element = $(this);
+ var value = getSelect2Value(element);
+ var noForceAjax = false;
+ var isMouseUp = false;
+ if (e.params.args.originalSelect2Event) noForceAjax = e.params.args.originalSelect2Event.noForceAjax;
+ if (e.params.args.originalEvent) isMouseUp = e.params.args.originalEvent.type == "mouseup";
+ if (value && !noForceAjax && !isMouseUp) {
+ var endpoint = element.data("endpoint");
+ var assetStatusType = element.data("asset-status-type");
+ $.ajax({
+ url: baseUrl + 'api/v1/' + endpoint + '/selectlist?search=' + value + '&page=1' + (assetStatusType ? '&assetStatusType=' + assetStatusType : ''),
+ dataType: 'json',
+ headers: {
+ "X-Requested-With": 'XMLHttpRequest',
+ "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr('content')
+ }
+ }).done(function (response) {
+ var currentlySelected = element.select2('data').map(function (x) {
+ return +x.id;
+ }).filter(function (x) {
+ return x !== 0;
+ });
+
+ // makes sure we're not selecting the same thing twice for multiples
+ var filteredResponse = response.results.filter(function (item) {
+ return currentlySelected.indexOf(+item.id) < 0;
+ });
+ var first = currentlySelected.length > 0 ? filteredResponse[0] : response.results[0];
+ if (first && first.id) {
+ first.selected = true;
+ if ($("option[value='" + first.id + "']", element).length < 1) {
+ var option = new Option(first.text, first.id, true, true);
+ element.append(option);
+ } else {
+ var isMultiple = element.attr("multiple") == "multiple";
+ element.val(isMultiple ? element.val().concat(first.id) : element.val(first.id));
+ }
+ element.trigger('change');
+ element.trigger({
+ type: 'select2:select',
+ params: {
+ data: first
+ }
+ });
+ }
+ });
+ }
+ });
+ function formatDatalist(datalist) {
+ var loading_markup = ' Loading...';
+ if (datalist.loading) {
+ return loading_markup;
+ }
+ var markup = '
';
+ markup += '
';
+ if (datalist.image) {
+ markup += "
";
+ } else {
+ markup += '';
+ }
+ markup += "
" + datalist.text + "
";
+ markup += "
";
+ return markup;
+ }
+ function formatDatalistSafe(datalist) {
+ // console.warn("What in the hell is going on with Select2?!?!!?!?");
+ // console.warn($.select2);
+ if (datalist.loading) {
+ return $(' Loading...');
+ }
+ var root_div = $("
");
+ var left_pull = $("
");
+ if (datalist.image) {
+ var inner_div = $("
");
+ /******************************************************************
+ *
+ * We are specifically chosing empty alt-text below, because this
+ * image conveys no additional information, relative to the text
+ * that will *always* be there in any select2 list that is in use
+ * in Snipe-IT. If that changes, we would probably want to change
+ * some signatures of some functions, but right now, we don't want
+ * screen readers to say "HP SuperJet 5000, .... picture of HP
+ * SuperJet 5000..." and so on, for every single row in a list of
+ * assets or models or whatever.
+ *
+ *******************************************************************/
+ var img = $("");
+ // console.warn("Img is: ");
+ // console.dir(img);
+ // console.warn("Strigularly, that's: ");
+ // console.log(img);
+ img.attr("src", datalist.image);
+ inner_div.append(img);
+ } else {
+ var inner_div = $("");
+ }
+ left_pull.append(inner_div);
+ root_div.append(left_pull);
+ var name_div = $("
");
+ name_div.text(datalist.text);
+ root_div.append(name_div);
+ var safe_html = root_div.get(0).outerHTML;
+ var old_html = formatDatalist(datalist);
+ if (safe_html != old_html) {
+ //console.log("HTML MISMATCH: ");
+ //console.log("FormatDatalistSafe: ");
+ // console.dir(root_div.get(0));
+ //console.log(safe_html);
+ //console.log("FormatDataList: ");
+ //console.log(old_html);
+ }
+ return root_div;
+ }
+ function formatDataSelection(datalist) {
+ // This a heinous workaround for a known bug in Select2.
+ // Without this, the rich selectlists are vulnerable to XSS.
+ // Many thanks to @uberbrady for this fix. It ain't pretty,
+ // but it resolves the issue until Select2 addresses it on their end.
+ //
+ // Bug was reported in 2016 :{
+ // https://github.com/select2/select2/issues/4587
+
+ return datalist.text.replace(/>/g, '>').replace(/Click me
+ $('a[data-toggle="tab"]').click(function (e) {
+ var href = $(this).attr("href");
+ history.pushState(null, null, href);
+ e.preventDefault();
+ $('a[href="' + $(this).attr('href') + '"]').tab('show');
+ });
+
+ // ------------------------------------------------
+ // End Deep Linking for Bootstrap tabs
+ // ------------------------------------------------
+
+ // Image preview
+ function readURL(input, $preview) {
+ if (input.files && input.files[0]) {
+ var reader = new FileReader();
+ reader.onload = function (e) {
+ $preview.attr('src', e.target.result);
+ };
+ reader.readAsDataURL(input.files[0]);
+ }
+ }
+ function formatBytes(bytes) {
+ if (bytes < 1024) return bytes + " Bytes";else if (bytes < 1048576) return (bytes / 1024).toFixed(2) + " KB";else if (bytes < 1073741824) return (bytes / 1048576).toFixed(2) + " MB";else return (bytes / 1073741824).toFixed(2) + " GB";
+ }
+
+ // File size validation
+ $('.js-uploadFile').bind('change', function () {
+ var $this = $(this);
+ var id = '#' + $this.attr('id');
+ var status = id + '-status';
+ var $status = $(status);
+ var delete_id = $(id + '-deleteCheckbox');
+ var preview_container = $(id + '-previewContainer');
+ $status.removeClass('text-success').removeClass('text-danger');
+ $(status + ' .goodfile').remove();
+ $(status + ' .badfile').remove();
+ $(status + ' .previewSize').hide();
+ preview_container.hide();
+ $(id + '-info').html('');
+ var max_size = $this.data('maxsize');
+ var total_size = 0;
+ for (var i = 0; i < this.files.length; i++) {
+ total_size += this.files[i].size;
+ $(id + '-info').append('' + htmlEntities(this.files[i].name) + ' (' + formatBytes(this.files[i].size) + ') ');
+ }
+ if (total_size > max_size) {
+ $status.addClass('text-danger').removeClass('help-block').prepend(' ').append(' Upload is ' + formatBytes(total_size) + '.');
+ } else {
+ $status.addClass('text-success').removeClass('help-block').prepend(' ');
+ var $preview = $(id + '-imagePreview');
+ readURL(this, $preview);
+ $preview.fadeIn();
+ preview_container.fadeIn();
+ delete_id.hide();
+ }
+ });
+});
+function htmlEntities(str) {
+ return String(str).replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"');
+}
+
+/**
+ * Toggle disabled
+ */
+(function ($) {
+ $.fn.toggleDisabled = function (callback) {
+ return this.each(function () {
+ var disabled,
+ $this = $(this);
+ if ($this.attr('disabled')) {
+ $this.removeAttr('disabled');
+ disabled = false;
+ } else {
+ $this.attr('disabled', 'disabled');
+ disabled = true;
+ }
+ if (callback && typeof callback === 'function') {
+ callback(this, disabled);
+ }
+ });
+ };
+})(jQuery);
+
+/**
+ * Universal Livewire Select2 integration
+ *
+ * How to use:
+ *
+ * 1. Set the class of your select2 elements to 'livewire-select2').
+ * 2. Name your element to match a property in your Livewire component
+ * 3. Add an attribute called 'data-livewire-component' that points to $this->getId() (via `{{ }}` if you're in a blade,
+ * or just $this->getId() if not).
+ */
+document.addEventListener('livewire:init', function () {
+ $('.livewire-select2').select2();
+ $(document).on('select2:select', '.livewire-select2', function (event) {
+ var target = $(event.target);
+ if (!event.target.name || !target.data('livewire-component')) {
+ console.error("You need to set both name (which should match a Livewire property) and data-livewire-component on your Livewire-ed select2 elements!");
+ console.error("For data-livewire-component, you probably want to use $this->getId() or {{ $this->getId() }}, as appropriate");
+ return false;
+ }
+ Livewire.find(target.data('livewire-component')).set(event.target.name, this.options[this.selectedIndex].value);
+ });
+ Livewire.hook('request', function (_ref) {
+ var succeed = _ref.succeed;
+ succeed(function () {
+ queueMicrotask(function () {
+ $('.livewire-select2').select2();
+ });
+ });
+ });
+});
+
+/***/ }),
+
+/***/ "./resources/assets/js/snipeit_modals.js":
+/*!***********************************************!*\
+ !*** ./resources/assets/js/snipeit_modals.js ***!
+ \***********************************************/
+/***/ (() => {
+
+/*
+ *
+ * Snipe-IT Universal Modal support
+ *
+ * Enables modal dialogs to create sub-resources throughout Snipe-IT
+ *
+ */
+
+/*
+HOW TO USE
+ Create a Button looking like this:
+ New
+ If you don't have access to Blade commands (like {{ and }}, etc), you can hard-code a URL as the 'href'
+ data-toggle="modal" - required for Bootstrap Modals
+data-target="#createModal" - fixed ID for the modal, do not change
+data-select="assigned_to" - What is the *ID* of the select-dropdown that you're going to be adding to, if the modal-create was a success? Be on the lookout for duplicate ID's, it will confuse this library!
+class="btn btn-sm btn-primary" - makes it look button-ey, feel free to change :)
+
+If you want to pass additional variables to the modal (In the Category Create one, for example, you can pass category_id), you can encode them as URL variables in the href
+
+*/
+
+$(function () {
+ var baseUrl = $('meta[name="baseUrl"]').attr('content');
+ //handle modal-add-interstitial calls
+ var model, select, refreshSelector;
+ if ($('#createModal').length == 0) {
+ $('body').append('');
+ }
+ $('#createModal').on("show.bs.modal", function (event) {
+ var link = $(event.relatedTarget);
+ model = link.data("dependency");
+ select = link.data("select");
+ refreshSelector = link.data("refresh");
+ $('#createModal').load(link.attr('href'), function () {
+ // this sets the focus to be the name field
+ $('#modal-name').focus();
+
+ //do we need to re-select2 this, after load? Probably.
+ $('#createModal').find('select.select2').select2();
+ // Initialize the ajaxy select2 with images.
+ // This is a copy/paste of the code from snipeit.js, would be great to only have this in one place.
+
+ $('.js-data-ajax').each(function (i, item) {
+ var link = $(item);
+ var endpoint = link.data("endpoint");
+ var select = link.data("select");
+ link.select2({
+ ajax: {
+ // the baseUrl includes a trailing slash
+ url: baseUrl + 'api/v1/' + endpoint + '/selectlist',
+ //WARNING - we're hoping that's defined on the page somewhere...
+ dataType: 'json',
+ delay: 250,
+ headers: {
+ "X-Requested-With": 'XMLHttpRequest',
+ "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr('content')
+ },
+ data: function data(params) {
+ var data = {
+ search: params.term,
+ page: params.page || 1,
+ assetStatusType: link.data("asset-status-type")
+ };
+ return data;
+ },
+ /*processResults: function (data, params) {
+ params.page = params.page || 1;
+ var answer = {
+ results: data.items,
+ pagination: {
+ more: data.pagination.more
+ }
+ };
+ return answer;
+ },*/
+ cache: true
+ },
+ //escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
+ templateResult: formatDatalistSafe
+ //templateSelection: formatDataSelection
+ });
+ });
+ });
+ });
+ $('#createModal').on('click', '#modal-save', function () {
+ $.ajax({
+ type: 'POST',
+ url: $('.modal-body form').attr('action'),
+ headers: {
+ "X-Requested-With": 'XMLHttpRequest',
+ "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr('content')
+ },
+ data: $('.modal-body form').serialize(),
+ success: function success(result) {
+ if (result.status == "error") {
+ var error_message = "";
+ for (var field in result.messages) {
+ error_message += "
Problem(s) with field " + field + ": " + result.messages[field];
+ }
+ $('#modal_error_msg').html(error_message).show();
+ return false;
+ }
+ var id = result.payload.id;
+ var name = result.payload.name || result.payload.first_name + " " + result.payload.last_name;
+ if (!id || !name) {
+ console.error("Could not find resulting name or ID from modal-create. Name: " + name + ", id: " + id);
+ return false;
+ }
+ $('#createModal').modal('hide');
+ $('#createModal').html("");
+ var refreshTable = $('#' + refreshSelector);
+ if (refreshTable.length > 0) {
+ refreshTable.bootstrapTable('refresh');
+ }
+
+ // "select" is the original drop-down menu that someone
+ // clicked 'add' on to add a new 'thing'
+ // this code adds the newly created object to that select
+ var selector = document.getElementById(select);
+ if (!selector) {
+ return false;
+ }
+ selector.options[selector.length] = new Option(name, id);
+ selector.selectedIndex = selector.length - 1;
+ $(selector).trigger("change");
+ if (window.fetchCustomFields) {
+ fetchCustomFields();
+ }
+ },
+ error: function error(result) {
+ msg = result.responseJSON.messages || result.responseJSON.error;
+ $('#modal_error_msg').html("Server Error: " + msg).show();
+ }
+ });
+ });
+});
+function formatDatalistSafe(datalist) {
+ // console.warn("What in the hell is going on with Select2?!?!!?!?");
+ // console.warn($.select2);
+ if (datalist.loading) {
+ return $(' Loading...');
+ }
+ var root_div = $("
");
+ var left_pull = $("
");
+ if (datalist.image) {
+ var inner_div = $("
");
+ /******************************************************************
+ *
+ * We are specifically chosing empty alt-text below, because this
+ * image conveys no additional information, relative to the text
+ * that will *always* be there in any select2 list that is in use
+ * in Snipe-IT. If that changes, we would probably want to change
+ * some signatures of some functions, but right now, we don't want
+ * screen readers to say "HP SuperJet 5000, .... picture of HP
+ * SuperJet 5000..." and so on, for every single row in a list of
+ * assets or models or whatever.
+ *
+ *******************************************************************/
+ var img = $("");
+ // console.warn("Img is: ");
+ // console.dir(img);
+ // console.warn("Strigularly, that's: ");
+ // console.log(img);
+ img.attr("src", datalist.image);
+ inner_div.append(img);
+ } else {
+ var inner_div = $("");
+ }
+ left_pull.append(inner_div);
+ root_div.append(left_pull);
+ var name_div = $("
- {{ Form::select('typeOfImport', $importTypes, $typeOfImport, [
- 'id' => 'import_type',
- 'class' => 'livewire-select2',
- 'style' => 'min-width: 350px',
- 'data-placeholder' => trans('general.select_var', ['thing' => trans('general.import_type')]),
- 'placeholder' => '', //needed so that the form-helper will put an empty option first
- 'data-minimum-results-for-search' => '-1', // Remove this if the list gets long enough that we need to search
- 'data-livewire-component' => $this->getId()
- ]) }}
+
@if ($typeOfImport === 'asset' && $snipeSettings->auto_increment_assets == 0)