/*=========================================================================================
File Name: app-user-list.js
Description: User List page
--------------------------------------------------------------------------------------
Item Name: Vuexy - Vuejs, HTML & Laravel Admin Dashboard Template
Author: PIXINVENT
Author URL: http://www.themeforest.net/user/pixinvent
==========================================================================================*/
$(function () {
;('use strict')
var dtUserTable = $('.user-list-table'),
newUserSidebar = $('.new-user-modal'),
newUserForm = $('.add-new-user'),
select = $('.select2'),
dtContact = $('.dt-contact'),
statusObj = {
1: { title: 'Pending', class: 'badge-light-warning' },
2: { title: 'Active', class: 'badge-light-success' },
3: { title: 'Inactive', class: 'badge-light-secondary' }
}
var assetPath = '../../../app-assets/',
userView = 'app-user-view-account.html'
if ($('body').attr('data-framework') === 'laravel') {
assetPath = $('body').attr('data-asset-path')
userView = assetPath + 'app/user/view/account'
}
select.each(function () {
var $this = $(this)
$this.wrap('
')
$this.select2({
// the following code is used to disable x-scrollbar when click in select input and
// take 100% width in responsive also
dropdownAutoWidth: true,
width: '100%',
dropdownParent: $this.parent()
})
})
// Users List datatable
if (dtUserTable.length) {
dtUserTable.DataTable({
ajax: assetPath + 'data/user-list.json', // JSON file to add data
columns: [
// columns according to JSON
{ data: '' },
{ data: 'full_name' },
{ data: 'role' },
{ data: 'current_plan' },
{ data: 'billing' },
{ data: 'status' },
{ data: '' }
],
columnDefs: [
{
// For Responsive
className: 'control',
orderable: false,
responsivePriority: 2,
targets: 0,
render: function (data, type, full, meta) {
return ''
}
},
{
// User full name and username
targets: 1,
responsivePriority: 4,
render: function (data, type, full, meta) {
var $name = full['full_name'],
$email = full['email'],
$image = full['avatar']
if ($image) {
// For Avatar image
var $output =
'
'
} else {
// For Avatar badge
var stateNum = Math.floor(Math.random() * 6) + 1
var states = ['success', 'danger', 'warning', 'info', 'dark', 'primary', 'secondary']
var $state = states[stateNum],
$name = full['full_name'],
$initials = $name.match(/\b\w/g) || []
$initials = (($initials.shift() || '') + ($initials.pop() || '')).toUpperCase()
$output = '' + $initials + ''
}
var colorClass = $image === '' ? ' bg-light-' + $state + ' ' : ''
// Creates full output for row
var $row_output =
'' +
'
' +
'
' +
$output +
'
' +
'
' +
'
' +
'
'
return $row_output
}
},
{
// User Role
targets: 2,
render: function (data, type, full, meta) {
var $role = full['role']
var roleBadgeObj = {
Subscriber: feather.icons['user'].toSvg({ class: 'font-medium-3 text-primary me-50' }),
Author: feather.icons['settings'].toSvg({ class: 'font-medium-3 text-warning me-50' }),
Maintainer: feather.icons['database'].toSvg({ class: 'font-medium-3 text-success me-50' }),
Editor: feather.icons['edit-2'].toSvg({ class: 'font-medium-3 text-info me-50' }),
Admin: feather.icons['slack'].toSvg({ class: 'font-medium-3 text-danger me-50' })
}
return "" + roleBadgeObj[$role] + $role + ''
}
},
{
targets: 4,
render: function (data, type, full, meta) {
var $billing = full['billing']
return '' + $billing + ''
}
},
{
// User Status
targets: 5,
render: function (data, type, full, meta) {
var $status = full['status']
return (
'' +
statusObj[$status].title +
''
)
}
},
{
// Actions
targets: -1,
title: 'Actions',
orderable: false,
render: function (data, type, full, meta) {
return (
'' +
''
)
}
}
],
order: [[1, 'desc']],
dom:
'<"d-flex justify-content-between align-items-center header-actions mx-2 row mt-75"' +
'<"col-sm-12 col-lg-4 d-flex justify-content-center justify-content-lg-start" l>' +
'<"col-sm-12 col-lg-8 ps-xl-75 ps-0"<"dt-action-buttons d-flex align-items-center justify-content-center justify-content-lg-end flex-lg-nowrap flex-wrap"<"me-1"f>B>>' +
'>t' +
'<"d-flex justify-content-between mx-2 row mb-1"' +
'<"col-sm-12 col-md-6"i>' +
'<"col-sm-12 col-md-6"p>' +
'>',
language: {
sLengthMenu: 'Show _MENU_',
search: 'Search',
searchPlaceholder: 'Search..'
},
// Buttons with Dropdown
buttons: [
{
extend: 'collection',
className: 'btn btn-outline-secondary dropdown-toggle me-2',
text: feather.icons['external-link'].toSvg({ class: 'font-small-4 me-50' }) + 'Export',
buttons: [
{
extend: 'print',
text: feather.icons['printer'].toSvg({ class: 'font-small-4 me-50' }) + 'Print',
className: 'dropdown-item',
exportOptions: { columns: [1, 2, 3, 4, 5] }
},
{
extend: 'csv',
text: feather.icons['file-text'].toSvg({ class: 'font-small-4 me-50' }) + 'Csv',
className: 'dropdown-item',
exportOptions: { columns: [1, 2, 3, 4, 5] }
},
{
extend: 'excel',
text: feather.icons['file'].toSvg({ class: 'font-small-4 me-50' }) + 'Excel',
className: 'dropdown-item',
exportOptions: { columns: [1, 2, 3, 4, 5] }
},
{
extend: 'pdf',
text: feather.icons['clipboard'].toSvg({ class: 'font-small-4 me-50' }) + 'Pdf',
className: 'dropdown-item',
exportOptions: { columns: [1, 2, 3, 4, 5] }
},
{
extend: 'copy',
text: feather.icons['copy'].toSvg({ class: 'font-small-4 me-50' }) + 'Copy',
className: 'dropdown-item',
exportOptions: { columns: [1, 2, 3, 4, 5] }
}
],
init: function (api, node, config) {
$(node).removeClass('btn-secondary')
$(node).parent().removeClass('btn-group')
setTimeout(function () {
$(node).closest('.dt-buttons').removeClass('btn-group').addClass('d-inline-flex mt-50')
}, 50)
}
},
{
text: 'Add New User',
className: 'add-new btn btn-primary',
attr: {
'data-bs-toggle': 'modal',
'data-bs-target': '#modals-slide-in'
},
init: function (api, node, config) {
$(node).removeClass('btn-secondary')
}
}
],
// For responsive popup
responsive: {
details: {
display: $.fn.dataTable.Responsive.display.modal({
header: function (row) {
var data = row.data()
return 'Details of ' + data['full_name']
}
}),
type: 'column',
renderer: function (api, rowIdx, columns) {
var data = $.map(columns, function (col, i) {
return col.columnIndex !== 6 // ? Do not show row in modal popup if title is blank (for check box)
? '' +
'| ' +
col.title +
':' +
' | ' +
'' +
col.data +
' | ' +
'
'
: ''
}).join('')
return data ? $('').append('' + data + '') : false
}
}
},
language: {
paginate: {
// remove previous & next text from pagination
previous: ' ',
next: ' '
}
},
initComplete: function () {
// Adding role filter once table initialized
this.api()
.columns(2)
.every(function () {
var column = this
var label = $('').appendTo('.user_role')
var select = $(
''
)
.appendTo('.user_role')
.on('change', function () {
var val = $.fn.dataTable.util.escapeRegex($(this).val())
column.search(val ? '^' + val + '$' : '', true, false).draw()
})
column
.data()
.unique()
.sort()
.each(function (d, j) {
select.append('')
})
})
// Adding plan filter once table initialized
this.api()
.columns(3)
.every(function () {
var column = this
var label = $('').appendTo('.user_plan')
var select = $(
''
)
.appendTo('.user_plan')
.on('change', function () {
var val = $.fn.dataTable.util.escapeRegex($(this).val())
column.search(val ? '^' + val + '$' : '', true, false).draw()
})
column
.data()
.unique()
.sort()
.each(function (d, j) {
select.append('')
})
})
// Adding status filter once table initialized
this.api()
.columns(5)
.every(function () {
var column = this
var label = $('').appendTo('.user_status')
var select = $(
''
)
.appendTo('.user_status')
.on('change', function () {
var val = $.fn.dataTable.util.escapeRegex($(this).val())
column.search(val ? '^' + val + '$' : '', true, false).draw()
})
column
.data()
.unique()
.sort()
.each(function (d, j) {
select.append(
''
)
})
})
}
})
}
// Form Validation
if (newUserForm.length) {
newUserForm.validate({
errorClass: 'error',
rules: {
'user-fullname': {
required: true
},
'user-name': {
required: true
},
'user-email': {
required: true
}
}
})
newUserForm.on('submit', function (e) {
var isValid = newUserForm.valid()
e.preventDefault()
if (isValid) {
newUserSidebar.modal('hide')
}
})
}
// Phone Number
if (dtContact.length) {
dtContact.each(function () {
new Cleave($(this), {
phone: true,
phoneRegionCode: 'US'
})
})
}
})