Partialize forms (#2884)
* Consolidate edit form elements into reusable partials.
This is a large code change that doesn't do much immediately. It
refactors all of the various edit.blade.php files to reference
standardized partials, so that they all reference the same base html
layout. This has the side effect of moving everything to the new fancy
"required" indicators, and making things look consistent.
In addition, I've gone ahead and renamed a few database fields. We had
Assetmodel::modelno and Consumable::model_no, I've renamed both to
model_number. We had items using ::note and ::notes, I've standardized
on ::notes. Component used total_qty where consumables and accessories
used qty, so I've moved everything to qty (And fixed a few bugs in the
helper file in the process.
TODO includes looking at how/where to place the modal javascripts to
allow for on the fly creation from all places, rather than just the
asset page.
Rename assetmodel::modelno to model_number for clarity and consistency
Rename consumable::model_no to model_number for clarity and consistency
Rename assetmodel::note to notes for clarity and consistency
Port asset and assetmodel to new partials layout. Adapt all code to the renamed model_number and notes database changes. Fix some stying.
* Share a settings variable with all views.
* Allow editing the per_page setting. We showed the value, but we never showed it on the edit page..
* use snipeSettings in all views instead of the long ugly path.
* War on partials. Centralize all bootstrap table javascript
* Use model_number instead of modelno in importer
* Codacy fix.
* More unification/deduplication. Create an edit form template layout that we use as the base for all edit forms. This gives the same interface for editing everything and makes the edit.blade.* files much easier to read.
* Use a ViewComposer instead of sharing the variable directly. Fixes artisan optimize trying to hit the db--which ruins new installs
* Fix DB seeder.
* Base sql dump and csv's to import data from for tests.
* Start some functional tests for creating items.
* Add functional tests for all create methods. Still need to do tests for edits, deletes, and lots of other things
* Improvements to functional tests.
Use the built in DB seeding mechanism instead of doing it ourselves.
Break the tests into multiple units, rather than testing everything in
each function.
* Some improvements to acceptance tests.
Make sure we're only looking at the "trs" within the bootstrap table.
Creation of assets is now tested at the functional level (and is faster)
so ignore it here.
I'm testing acceptance tests with the
IMPORT_{ASSETS,ACCESSORIES,CONSUMABLES}.csv in the tests/_data folder
imported.
* A few things to make acceptance tests work. Add a name to the companies table, and make the locations table have the correct name
* Use a .env.tests file for testing functional and unit to allow a separate database.
* Add functional tests for compoents, groups, and licenses.
* Now that the config is in the functional.yml, this just confuses things.
* Start some functional tests for creating items.
* Add functional tests for all create methods. Still need to do tests for edits, deletes, and lots of other things
* Improvements to functional tests.
Use the built in DB seeding mechanism instead of doing it ourselves.
Break the tests into multiple units, rather than testing everything in
each function.
* Some improvements to acceptance tests.
Make sure we're only looking at the "trs" within the bootstrap table.
Creation of assets is now tested at the functional level (and is faster)
so ignore it here.
I'm testing acceptance tests with the
IMPORT_{ASSETS,ACCESSORIES,CONSUMABLES}.csv in the tests/_data folder
imported.
* update db dump
* Update tests to new reality
* env for the test setup
* only load the database at beginning of tests, not between each Functional test.
* Fix a miss from renaming note to notes.
* Set Termination date when creating an asset. It was only set on edit.
* Rename serial_number to serial in components for consistency.
* Update validation rules to match limits in database. Currently we just accepted the values and they were truncated when adding to DB.
* Much more detailed functional testing of creating items. This checks to make sure all values on form have been successfully persisted to database.
2016-11-16 16:56:57 -08:00
{{ -- This Will load our default bootstrap - table settings on any table with a class of " snipe-table " and export it to the passed 'exportFile' name -- }}
2017-05-31 12:34:05 -07:00
< script src = " { { asset('js/bootstrap-table.js') }} " ></ script >
< script src = " { { asset('js/extensions/mobile/bootstrap-table-mobile.js') }} " ></ script >
2018-01-10 20:04:41 -08:00
< script src = " { { asset('js/extensions/cookie/bootstrap-table-cookie.min.js?v=1') }} " ></ script >
2017-05-23 14:32:58 -07:00
@ if ( ! isset ( $simple_view ))
2017-05-31 12:34:05 -07:00
< script src = " { { asset('js/extensions/export/bootstrap-table-export.js?v=1') }} " ></ script >
< script src = " { { asset('js/extensions/export/tableExport.js') }} " ></ script >
< script src = " { { asset('js/FileSaver.min.js') }} " ></ script >
< script src = " { { asset('js/jspdf.min.js') }} " ></ script >
< script src = " { { asset('js/jspdf.plugin.autotable.js') }} " ></ script >
< script src = " { { asset('js/extensions/export/jquery.base64.js') }} " ></ script >
< script src = " { { asset('js/extensions/toolbar/bootstrap-table-toolbar.js') }} " ></ script >
2017-10-24 05:22:26 -07:00
< script src = " { { asset('js/extensions/sticky-header/bootstrap-table-sticky-header.js') }} " ></ script >
2017-05-23 14:32:58 -07:00
@ endif
2017-02-08 08:48:41 -08:00
2017-09-28 19:45:15 -07:00
< script nonce = " { { csrf_token() }} " >
2017-10-24 05:22:26 -07:00
var $table = $ ( '.snipe-table' );
$ ( function () {
buildTable ( $table , 20 , 50 );
});
function buildTable ( $el ) {
var stickyHeaderOffsetY = 0 ;
if ( $ ( '.navbar-fixed-top' ) . css ( 'height' ) ) {
stickyHeaderOffsetY = + $ ( '.navbar-fixed-top' ) . css ( 'height' ) . replace ( 'px' , '' );
}
if ( $ ( '.navbar-fixed-top' ) . css ( 'margin-bottom' ) ) {
stickyHeaderOffsetY += + $ ( '.navbar-fixed-top' ) . css ( 'margin-bottom' ) . replace ( 'px' , '' );
}
2017-11-02 11:19:34 -07:00
$ ( '.snipe-table' ) . bootstrapTable ( 'destroy' ) . bootstrapTable ({
2018-01-10 20:34:36 -08:00
classes : 'table table-responsive table-no-bordered' ,
undefinedText : '' ,
iconsPrefix : 'fa' ,
search : {{ ( isset ( $search )) ? 'true' : 'false' }},
paginationVAlign : 'both' ,
sidePagination : '{{ (isset($clientSearch)) ? ' client ' : ' server ' }}' ,
sortable : true ,
pageSize : 20 ,
pagination : true ,
cookie : true ,
cookieExpire : '2y' ,
cookieIdTable : '{{ Route::currentRouteName() }}' ,
@ if ( isset ( $columns ))
columns : { !! $columns !! },
2017-05-23 09:25:20 -07:00
@ endif
2018-01-10 20:34:36 -08:00
mobileResponsive : true ,
maintainSelected : true ,
paginationFirstText : " { { trans('general.first') }} " ,
paginationLastText : " { { trans('general.last') }} " ,
paginationPreText : " { { trans('general.previous') }} " ,
paginationNextText : " { { trans('general.next') }} " ,
formatLoadingMessage : function () {
return '<h4><i class="fa fa-spinner fa-spin" aria-hidden="true"></i> Loading... please wait.... </h4>' ;
},
icons : {
advancedSearchIcon : 'fa fa-search-plus' ,
paginationSwitchDown : 'fa-caret-square-o-down' ,
paginationSwitchUp : 'fa-caret-square-o-up' ,
columns : 'fa-columns' ,
@ if ( isset ( $multiSort ))
sort : 'fa fa-sort-amount-desc' ,
plus : 'fa fa-plus' ,
minus : 'fa fa-minus' ,
@ endif
refresh : 'fa-refresh'
},
@ if ( ! isset ( $simple_view ))
showRefresh : true ,
showExport : true ,
stickyHeader : true ,
stickyHeaderOffsetY : stickyHeaderOffsetY + 'px' ,
@ if ( isset ( $showFooter ))
showFooter : true ,
@ endif
showColumns : true ,
trimOnSearch : false ,
@ if ( isset ( $multiSort ))
showMultiSort : true ,
@ endif
@ if ( isset ( $exportFile ))
exportDataType : 'all' ,
exportTypes : [ 'csv' , 'excel' , 'doc' , 'txt' , 'json' , 'xml' , 'pdf' ],
exportOptions : {
fileName : '{{ $exportFile . "-" }}' + ( new Date ()) . toISOString () . slice ( 0 , 10 ),
ignoreColumn : [ 'actions' , 'change' , 'checkbox' , 'checkincheckout' , 'icon' ],
worksheetName : " Snipe-IT Export " ,
jspdf : {
orientation : 'l' ,
autotable : {
styles : {
rowHeight : 20 ,
fontSize : 10 ,
overflow : 'linebreak' ,
},
headerStyles : { fillColor : 255 , textColor : 0 },
//alternateRowStyles: {fillColor: [60, 69, 79], textColor: 255}
}
}
},
@ endif
@ endif
pageList : [ '20' , '30' , '50' , '100' , '150' , '200' ]
2017-03-11 04:26:01 -08:00
2018-01-10 20:34:36 -08:00
});
2017-10-24 05:22:26 -07:00
}
2017-01-18 19:28:35 -08:00
2017-08-25 18:40:20 -07:00
function dateRowCheckStyle ( value ) {
2017-08-26 15:27:50 -07:00
if (( value . days_to_next_audit ) && ( value . days_to_next_audit < {{ $snipeSettings -> audit_warning_days ? : 0 }})) {
2017-08-25 18:40:20 -07:00
return { classes : " danger " }
}
return {};
}
2017-01-18 19:28:35 -08:00
// Handle whether or not the edit button should be disabled
$ ( '.snipe-table' ) . on ( 'check.bs.table' , function () {
$ ( '#bulkEdit' ) . removeAttr ( 'disabled' );
});
$ ( '.snipe-table' ) . on ( 'check-all.bs.table' , function () {
$ ( '#bulkEdit' ) . removeAttr ( 'disabled' );
});
$ ( '.snipe-table' ) . on ( 'uncheck.bs.table' , function () {
if ( $ ( '.snipe-table' ) . bootstrapTable ( 'getSelections' ) . length == 0 ) {
$ ( '#bulkEdit' ) . attr ( 'disabled' , 'disabled' );
}
});
$ ( '.snipe-table' ) . on ( 'uncheck-all.bs.table' , function ( e , row ) {
$ ( '#bulkEdit' ) . attr ( 'disabled' , 'disabled' );
});
2017-01-24 21:04:38 -08:00
// This only works for model index pages because it uses the row's model ID
function genericRowLinkFormatter ( destination ) {
return function ( value , row ) {
if ( value ) {
return '<a href="{{ url(' / ') }}/' + destination + '/' + row . id + '"> ' + value + '</a>' ;
}
};
2017-01-18 19:28:35 -08:00
}
2017-01-24 21:04:38 -08:00
// Use this when we're introspecting into a column object and need to link
function genericColumnObjLinkFormatter ( destination ) {
return function ( value , row ) {
2017-09-29 12:03:02 -07:00
if (( value ) && ( value . status_meta )) {
2017-09-29 15:24:33 -07:00
var text_color ;
var icon_style ;
switch ( value . status_meta ) {
case 'deployed' :
text_color = 'blue' ;
icon_style = 'fa-circle' ;
break ;
case 'deployable' :
text_color = 'green' ;
icon_style = 'fa-circle' ;
break ;
case 'pending' :
text_color = 'orange' ;
icon_style = 'fa-circle' ;
break ;
default :
text_color = 'red' ;
icon_style = 'fa-times' ;
}
2017-10-28 07:12:47 -07:00
return '<nobr><a href="{{ url(' / ') }}/' + destination + '/' + value . id + '" data-tooltip="true" title="' + value . status_meta + '"> <i class="fa ' + icon_style + ' text-' + text_color + '"></i> ' + value . name + '</a></nobr>' ;
2017-09-28 21:18:00 -07:00
} else if (( value ) && ( value . name )) {
2017-10-28 07:12:47 -07:00
return '<nobr><a href="{{ url(' / ') }}/' + destination + '/' + value . id + '"> ' + value . name + '</a></span>' ;
2017-01-24 21:04:38 -08:00
}
};
2017-01-18 19:28:35 -08:00
}
2017-01-24 22:25:17 -08:00
// Make the edit/delete buttons
2017-01-24 21:04:38 -08:00
function genericActionsFormatter ( destination ) {
return function ( value , row ) {
2017-02-08 18:21:03 -08:00
var actions = '<nobr>' ;
2017-10-19 02:22:05 -07:00
var dest = destination ;
if ( destination == 'groups' ) {
var dest = 'admin/groups' ;
}
2017-07-07 18:45:49 -07:00
if (( row . available_actions ) && ( row . available_actions . clone === true )) {
2017-10-19 02:22:05 -07:00
actions += '<a href="{{ url(' / ') }}/' + dest + '/' + row . id + '/clone" class="btn btn-sm btn-info" data-tooltip="true" title="Clone"><i class="fa fa-copy"></i></a> ' ;
2017-07-07 18:45:49 -07:00
}
2017-02-21 15:40:25 -08:00
if (( row . available_actions ) && ( row . available_actions . update === true )) {
2017-10-19 02:22:05 -07:00
actions += '<a href="{{ url(' / ') }}/' + dest + '/' + row . id + '/edit" class="btn btn-sm btn-warning" data-tooltip="true" title="Update"><i class="fa fa-pencil"></i></a> ' ;
2017-02-08 18:21:03 -08:00
}
2017-02-21 15:40:25 -08:00
if (( row . available_actions ) && ( row . available_actions . delete === true )) {
2017-10-19 02:22:05 -07:00
actions += '<a href="{{ url(' / ') }}/' + dest + '/' + row . id + '" '
2017-07-08 13:21:13 -07:00
+ ' class="btn btn-danger btn-sm delete-asset" data-tooltip="true" '
2017-02-15 23:04:49 -08:00
+ ' data-toggle="modal" '
2017-05-23 14:32:58 -07:00
+ ' data-content="{{ trans(' general . sure_to_delete ') }} ' + row . name + '?" '
2017-07-08 13:36:25 -07:00
+ ' data-title="{{ trans(' general . delete ') }}" onClick="return false;">'
2017-10-19 11:29:58 -07:00
+ '<i class="fa fa-trash"></i></a> ' ;
} else {
actions += '<a class="btn btn-danger btn-sm delete-asset disabled" onClick="return false;"><i class="fa fa-trash"></i></a> ' ;
2017-02-08 18:21:03 -08:00
}
2017-09-06 17:11:43 -07:00
if (( row . available_actions ) && ( row . available_actions . restore === true )) {
2017-10-19 02:22:05 -07:00
actions += '<a href="{{ url(' / ') }}/' + dest + '/' + row . id + '/restore" class="btn btn-sm btn-warning" data-tooltip="true" title="Restore"><i class="fa fa-retweet"></i></a> ' ;
2017-09-06 17:11:43 -07:00
}
2017-10-19 11:29:58 -07:00
actions += '</nobr>' ;
2017-02-08 18:21:03 -08:00
return actions ;
2017-01-24 21:04:38 -08:00
};
2017-01-18 19:28:35 -08:00
}
2017-05-23 14:32:58 -07:00
2017-10-18 06:24:36 -07:00
// This handles the icons and display of polymorphic entries
2017-05-23 14:32:58 -07:00
function polymorphicItemFormatter ( value ) {
var item_destination = '' ;
2017-09-29 17:32:16 -07:00
var item_icon ;
2017-05-23 14:32:58 -07:00
if (( value ) && ( value . type )) {
if ( value . type == 'asset' ) {
item_destination = 'hardware' ;
2017-09-29 17:32:16 -07:00
item_icon = 'fa-barcode' ;
2017-05-23 14:32:58 -07:00
} else if ( value . type == 'accessory' ) {
item_destination = 'accessories' ;
2017-09-29 17:32:16 -07:00
item_icon = 'fa-keyboard-o' ;
2017-05-23 14:32:58 -07:00
} else if ( value . type == 'component' ) {
item_destination = 'components' ;
2017-09-29 17:32:16 -07:00
item_icon = 'fa-hdd-o' ;
2017-05-23 14:32:58 -07:00
} else if ( value . type == 'consumable' ) {
item_destination = 'consumables' ;
2017-09-29 17:32:16 -07:00
item_icon = 'fa-tint' ;
2017-05-23 14:32:58 -07:00
} else if ( value . type == 'license' ) {
item_destination = 'licenses' ;
2017-09-29 17:32:16 -07:00
item_icon = 'fa-floppy-o' ;
2017-05-23 14:32:58 -07:00
} else if ( value . type == 'user' ) {
item_destination = 'users' ;
2017-09-29 17:32:16 -07:00
item_icon = 'fa-user' ;
2017-09-05 17:54:58 -07:00
} else if ( value . type == 'location' ) {
item_destination = 'locations'
2017-09-29 17:32:16 -07:00
item_icon = 'fa-map-marker' ;
2017-05-23 14:32:58 -07:00
}
2017-10-28 07:12:47 -07:00
return '<nobr><a href="{{ url(' / ') }}/' + item_destination + '/' + value . id + '" data-tooltip="true" title="' + value . type + '"><i class="fa ' + item_icon + ' text-blue"></i> ' + value . name + '</a></nobr>' ;
2017-05-23 14:32:58 -07:00
} else {
2017-05-23 15:06:43 -07:00
return '' ;
2017-05-23 14:32:58 -07:00
}
}
2017-11-22 06:20:28 -08:00
// This just prints out the item type in the activity report
function itemTypeFormatter ( value , row ) {
if (( row ) && ( row . item ) && ( row . item . type )) {
return row . item . type ;
}
}
2017-05-23 14:32:58 -07:00
2018-01-10 18:58:55 -08:00
// We need a special formatter for license seats, since they don't work exactly the same
2018-01-10 20:34:36 -08:00
// Checkouts need the license ID, checkins need the specific seat ID
2018-01-10 18:58:55 -08:00
2018-01-10 20:34:36 -08:00
function licenseSeatInOutFormatter ( value , row ) {
// The user is allowed to check the license seat out and it's available
if (( row . available_actions . checkout == true ) && ( row . user_can_checkout == true ) && (( ! row . asset_id ) && ( ! row . assigned_to ))) {
return '<a href="{{ url(' / ') }}/licenses/' + row . license_id + '/checkout" class="btn btn-sm bg-maroon" data-tooltip="true" title="Check this item out">{{ trans(' general . checkout ') }}</a>' ;
} else {
return '<a href="{{ url(' / ') }}/licenses/' + row . id + '/checkin" class="btn btn-sm bg-purple" data-tooltip="true" title="Check in this license seat.">{{ trans(' general . checkin ') }}</a>' ;
}
2018-01-10 18:58:55 -08:00
}
2017-01-24 22:25:17 -08:00
function genericCheckinCheckoutFormatter ( destination ) {
2017-01-24 21:04:38 -08:00
return function ( value , row ) {
2017-02-08 18:21:03 -08:00
// The user is allowed to check items out, AND the item is deployable
2018-01-10 18:58:55 -08:00
if (( row . available_actions . checkout == true ) && ( row . user_can_checkout == true ) && (( ! row . asset_id ) && ( ! row . assigned_to ))) {
return '<a href="{{ url(' / ') }}/' + destination + '/' + row . id + '/checkout" class="btn btn-sm bg-maroon" data-tooltip="true" title="Check this item out">{{ trans(' general . checkout ') }}</a>' ;
2017-02-08 18:21:03 -08:00
// The user is allowed to check items out, but the item is not deployable
2017-03-11 12:11:24 -08:00
} else if ((( row . user_can_checkout == false )) && ( row . available_actions . checkout == true ) && ( ! row . assigned_to )) {
2017-10-17 11:32:09 -07:00
return '<div data-tooltip="true" title="This item has a status label that is undeployable and cannot be checked out at this time."><a class="btn btn-sm bg-maroon disabled">{{ trans(' general . checkout ') }}</a></div>' ;
2017-02-08 18:21:03 -08:00
// The user is allowed to check items in
2017-09-28 21:18:00 -07:00
} else if ( row . available_actions . checkin == true ) {
if ( row . assigned_to ) {
2018-01-10 20:34:36 -08:00
return '<a href="{{ url(' / ') }}/' + destination + '/' + row . id + '/checkin" class="btn btn-sm bg-purple" data-tooltip="true" title="Check this item in so it is available for re-imaging, re-issue, etc.">{{ trans(' general . checkin ') }}</a>' ;
2017-09-28 21:18:00 -07:00
} else if ( row . assigned_pivot_id ) {
2018-01-10 20:34:36 -08:00
return '<a href="{{ url(' / ') }}/' + destination + '/' + row . assigned_pivot_id + '/checkin" class="btn btn-sm bg-purple" data-tooltip="true" title="Check this item in so it is available for re-imaging, re-issue, etc.">{{ trans(' general . checkin ') }}</a>' ;
2017-09-28 21:18:00 -07:00
}
2017-10-17 11:32:09 -07:00
}
2017-02-08 18:21:03 -08:00
2017-02-08 08:48:41 -08:00
}
2017-01-24 18:58:07 -08:00
}
2017-01-24 22:46:07 -08:00
2017-01-24 22:25:17 -08:00
var formatters = [
'hardware' ,
2017-01-25 02:19:26 -08:00
'accessories' ,
2017-01-26 18:46:18 -08:00
'consumables' ,
'components' ,
2017-01-24 22:25:17 -08:00
'locations' ,
'users' ,
'manufacturers' ,
'statuslabels' ,
'models' ,
'licenses' ,
'categories' ,
'suppliers' ,
2017-05-23 02:50:51 -07:00
'departments' ,
2017-01-24 22:25:17 -08:00
'companies' ,
'depreciations' ,
2017-02-01 18:50:28 -08:00
'fieldsets' ,
'groups'
2017-01-24 22:25:17 -08:00
];
2017-01-18 19:46:43 -08:00
2017-01-24 21:04:38 -08:00
for ( var i in formatters ) {
window [ formatters [ i ] + 'LinkFormatter' ] = genericRowLinkFormatter ( formatters [ i ]);
window [ formatters [ i ] + 'LinkObjFormatter' ] = genericColumnObjLinkFormatter ( formatters [ i ]);
window [ formatters [ i ] + 'ActionsFormatter' ] = genericActionsFormatter ( formatters [ i ]);
2017-02-08 08:48:41 -08:00
window [ formatters [ i ] + 'InOutFormatter' ] = genericCheckinCheckoutFormatter ( formatters [ i ]);
2017-01-18 19:46:43 -08:00
}
2017-01-24 17:07:00 -08:00
2017-07-08 18:44:28 -07:00
// This is gross, but necessary so that we can package the API response
// for custom fields in a more useful way.
function customFieldsFormatter ( value , row ) {
2017-01-24 18:58:07 -08:00
2017-10-05 22:51:33 -07:00
if (( ! this ) || ( ! this . title )) {
return '' ;
}
2017-07-08 18:44:28 -07:00
var field_column = this . title ;
// Pull out any HTMl that might be passed via the presenter
// (for example, the locked icon for encrypted fields)
var field_column_plain = field_column . replace ( /< ( ? :.| \n ) * ?> ?/gm, '');
2017-08-23 03:28:13 -07:00
if (( row . custom_fields ) && ( row . custom_fields [ field_column_plain ])) {
2017-11-21 22:34:53 -08:00
// If the field type needs special formatting, do that here
if (( row . custom_fields [ field_column_plain ] . field_format ) && ( row . custom_fields [ field_column_plain ] . value )) {
if ( row . custom_fields [ field_column_plain ] . field_format == 'URL' ) {
return '<a href="' + row . custom_fields [ field_column_plain ] . value + '" target="_blank" rel="noopener">' + row . custom_fields [ field_column_plain ] . value + '</a>' ;
} else if ( row . custom_fields [ field_column_plain ] . field_format == 'EMAIL' ) {
return '<a href="mailto:' + row . custom_fields [ field_column_plain ] . value + '">' + row . custom_fields [ field_column_plain ] . value + '</a>' ;
}
}
2017-07-08 18:44:28 -07:00
return row . custom_fields [ field_column_plain ] . value ;
2017-11-21 22:34:53 -08:00
2017-07-08 18:44:28 -07:00
}
}
function createdAtFormatter ( value ) {
2017-01-24 21:04:38 -08:00
if (( value ) && ( value . date )) {
return value . date ;
2017-01-24 17:07:00 -08:00
}
}
2017-10-17 21:43:57 -07:00
function groupsFormatter ( value ) {
if ( value ) {
var groups = '' ;
for ( var index in value . rows ) {
groups += '<a href="{{ url(' / ') }}/admin/groups/' + value . rows [ index ] . id + '" class="label label-default"> ' + value . rows [ index ] . name + '</a> ' ;
}
return groups ;
}
}
2017-12-12 04:59:28 -08:00
function changeLogFormatter ( value ) {
var result = '' ;
for ( var index in value ) {
result += index + ': <del>' + value [ index ] . old + '</del> <i class="fa fa-long-arrow-right" aria-hidden="true"></i> ' + value [ index ] . new + '<br>'
}
return result ;
}
2017-10-19 01:30:40 -07:00
function deployedLocationFormatter ( row , value ) {
if (( row ) && ( row != undefined )) {
return '<a href="{{ url(' / ') }}/locations/' + row . id + '"> ' + row . name + '</a>' ;
} else if ( value . rtd_location ) {
return '<a href="{{ url(' / ') }}/locations/' + value . rtd_location . id + '" data-tooltip="true" title="Default Location"> ' + value . rtd_location . name + '</a>' ;
}
}
2017-10-17 21:43:57 -07:00
function groupsAdminLinkFormatter ( value , row ) {
return '<a href="{{ url(' / ') }}/admin/groups/' + row . id + '"> ' + value + '</a>' ;
}
2017-01-24 21:04:38 -08:00
function trueFalseFormatter ( value , row ) {
if (( value ) && (( value == 'true' ) || ( value == '1' ))) {
2017-02-01 17:48:28 -08:00
return '<i class="fa fa-check text-success"></i>' ;
2017-01-24 21:04:38 -08:00
} else {
2017-02-01 17:48:28 -08:00
return '<i class="fa fa-times text-danger"></i>' ;
2017-01-18 19:28:35 -08:00
}
}
2017-03-03 17:29:41 -08:00
function dateDisplayFormatter ( value , row ) {
if ( value ) {
return value . formatted ;
}
}
2017-05-23 09:25:20 -07:00
function iconFormatter ( value , row ) {
if ( value ) {
return '<i class="' + value + '"></i>' ;
}
}
2017-01-18 19:28:35 -08:00
function emailFormatter ( value , row ) {
if ( value ) {
return '<a href="mailto:' + value + '"> ' + value + '</a>' ;
}
}
2017-03-10 22:08:59 -08:00
function linkFormatter ( value , row ) {
if ( value ) {
return '<a href="' + value + '"> ' + value + '</a>' ;
}
}
2017-02-08 08:48:41 -08:00
function assetCompanyFilterFormatter ( value , row ) {
if ( value ) {
return '<a href="{{ url(' / ') }}/hardware/?company_id=' + row . id + '"> ' + value + '</a>' ;
}
}
function assetCompanyObjFilterFormatter ( value , row ) {
2017-11-22 06:20:51 -08:00
if (( row ) && ( row . company )) {
2017-02-08 08:48:41 -08:00
return '<a href="{{ url(' / ') }}/hardware/?company_id=' + row . company . id + '"> ' + row . company . name + '</a>' ;
}
}
function usersCompanyObjFilterFormatter ( value , row ) {
if ( value ) {
return '<a href="{{ url(' / ') }}/users/?company_id=' + row . id + '"> ' + value + '</a>' ;
} else {
return value ;
}
}
2017-07-26 16:47:47 -07:00
function employeeNumFormatter ( value , row ) {
2017-08-22 21:40:35 -07:00
2017-11-22 06:20:51 -08:00
if (( row ) && ( row . assigned_to ) && (( row . assigned_to . employee_number ))) {
2017-08-22 21:40:35 -07:00
return '<a href="{{ url(' / ') }}/users/' + row . assigned_to . id + '"> ' + row . assigned_to . employee_number + '</a>' ;
2017-07-26 16:47:47 -07:00
}
}
2017-02-08 08:48:41 -08:00
function orderNumberObjFilterFormatter ( value , row ) {
if ( value ) {
return '<a href="{{ url(' / ') }}/hardware/?order_number=' + row . order_number + '"> ' + row . order_number + '</a>' ;
}
}
function imageFormatter ( value , row ) {
2017-01-24 22:46:07 -08:00
if ( value ) {
2017-09-28 15:13:05 -07:00
return '<a href="' + value + '" data-toggle="lightbox" data-type="image"><img src="' + value + '" style="max-height: {{ $snipeSettings->thumbnail_max_h }}px; width: auto;" class="img-responsive"></a>' ;
2017-01-24 22:46:07 -08:00
}
}
2017-10-18 06:24:36 -07:00
function sumFormatter ( data ) {
var field = this . field ;
var total_sum = data . reduce ( function ( sum , row ) {
return ( sum ) + ( parseFloat ( row [ field ]) || 0 );
}, 0 );
return total_sum . toFixed ( 2 );
}
2017-01-18 19:28:35 -08:00
$ ( function () {
$ ( '#bulkEdit' ) . click ( function () {
var selectedIds = $ ( '.snipe-table' ) . bootstrapTable ( 'getSelections' );
$ . each ( selectedIds , function ( key , value ) {
$ ( " #bulkForm " ) . append ( $ ( '<input type="hidden" name="ids[' + value . id + ']" value="' + value . id + '">' ));
});
});
});
2017-02-08 08:48:41 -08:00
2017-10-18 06:24:36 -07:00
// This is necessary to make the bootstrap tooltips work inside of the
// wenzhixin/bootstrap-table formatters
2017-07-08 13:21:13 -07:00
$ ( function () {
$ ( '#table' ) . on ( 'post-body.bs.table' , function () {
$ ( '[data-tooltip="true"]' ) . tooltip ({
container : 'body'
});
});
});
2017-02-08 08:48:41 -08:00
2017-10-18 06:24:36 -07:00
2016-11-23 05:56:08 -08:00
</ script >