Unverified Commit cd8fd8b9 authored by Viral Solani's avatar Viral Solani Committed by GitHub

Merge pull request #148 from indranshastri/master

Changes for admin pannel javascript 
parents 26ec1dc7 ffa83bfd
This source diff could not be displayed because it is too large. You can view the blob instead.
//common functionalities for all the javascript featueres //common functionalities for all the javascript featueres
var Backend = {}; // common variable used in all the files of the backend var Backend = {}; // common variable used in all the files of the backend
(function() (function () {
{
Backend = { Backend = {
Utils:{ Utils: {
toggleClass :function(element,className){ csrf: document.querySelector('meta[name="csrf-token"]').getAttribute('content'),
if (element.classList) { toggleClass: function (element, className) {
element.classList.toggle(className); if (element.classList) {
} else { element.classList.toggle(className);
var classes = element.className.split(' '); } else {
var existingIndex = classes.indexOf(className); var classes = element.className.split(' ');
var existingIndex = classes.indexOf(className);
if (existingIndex >= 0)
classes.splice(existingIndex, 1); if (existingIndex >= 0)
classes.splice(existingIndex, 1);
else
classes.push(className);
element.className = classes.join(' ');
}
},
addClass: function (element, className) {
if (element.classList)
element.classList.add(className);
else else
classes.push(className); element.className += ' ' + className;
},
element.className = classes.join(' '); removeClass: function (el, className) {
} if (el.classList)
}, el.classList.remove(className);
documentReady : function(callback){ else
if (document.attachEvent ? document.readyState === "complete" : document.readyState !== "loading"){ el.className = el.className.replace(new RegExp('(^|\\b)' + className.split(' ').join('|') + '(\\b|$)', 'gi'), ' ');
callback(); },
} else {
document.addEventListener('DOMContentLoaded', callback);
}
},
ajaxrequest:function(url,method,data,csrf,callback){ documentReady: function (callback) {
var request = new XMLHttpRequest(); if (document.attachEvent ? document.readyState === "complete" : document.readyState !== "loading") {
if (window.XMLHttpRequest) { callback();
// code for modern browsers } else {
request = new XMLHttpRequest(); document.addEventListener('DOMContentLoaded', callback);
} else { }
// code for old IE browsers },
request = new ActiveXObject("Microsoft.XMLHTTP");
}
request.open(method, url, true);
request.setRequestHeader('X-CSRF-TOKEN', csrf);
request.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
if("post" === method.toLowerCase()){
request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
data = this.jsontoformdata(data);
}
// when request is in the ready state change the details or perform success function ajaxrequest: function (url, method, data, csrf, callback) {
request.onreadystatechange = function() var request = new XMLHttpRequest();
{ if (window.XMLHttpRequest) {
if (request.readyState === XMLHttpRequest.DONE) { // code for modern browsers
// Everything is good, the response was received. request = new XMLHttpRequest();
request.onload = callback.success(request); } else {
} // code for old IE browsers
}; request = new ActiveXObject("Microsoft.XMLHTTP");
}
request.onerror = callback.error; request.open(method, url, true);
request.setRequestHeader('X-CSRF-TOKEN', csrf);
request.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
if ("post" === method.toLowerCase() || "patch" === method.toLowerCase()) {
request.send(data); request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
}, data = this.jsontoformdata(data);
}
// This should probably only be used if all JSON elements are strings // when request is in the ready state change the details or perform success function
jsontoformdata:function (srcjson){ request.onreadystatechange = function () {
if(typeof srcjson !== "object") if (request.readyState === XMLHttpRequest.DONE) {
if(typeof console !== "undefined"){ // Everything is good, the response was received.
console.log("\"srcjson\" is not a JSON object"); request.onload = callback.success(request);
return null; }
} };
u = encodeURIComponent; request.onerror = callback.error;
var urljson = ""; request.send(data);
var keys = Object.keys(srcjson); },
for(var i=0; i <keys.length; i++){
urljson += u(keys[i]) + "=" + u(srcjson[keys[i]]);
if(i < (keys.length-1))urljson+="&";
}
return urljson;
},
removeClass:function(el,className){ // This should probably only be used if all JSON elements are strings
if (el.classList) jsontoformdata: function (srcjson) {
el.classList.remove(className); if (typeof srcjson !== "object")
else if (typeof console !== "undefined") {
el.className = el.className.replace(new RegExp('(^|\\b)' + className.split(' ').join('|') + '(\\b|$)', 'gi'), ' '); console.log("\"srcjson\" is not a JSON object");
} return null;
}
u = encodeURIComponent;
var urljson = "";
var keys = Object.keys(srcjson);
for (var i = 0; i < keys.length; i++) {
urljson += u(keys[i]) + "=" + u(srcjson[keys[i]]);
if (i < (keys.length - 1)) urljson += "&";
}
return urljson;
},
},
/**
* Pages
*
*/
Pages:
{
init: function()
{
Backend.tinyMCE.init();
},
},
/**
* Access management
*
*/
Access:
{
selectors: {
select2: $(".select2"),
getPremissionURL:"",
Areyousure:"",
delete_user_confirm:"",
continue:"",
cancel:"",
restore_user_confirm:"",
},
init: function (page)
{
this.setSelectors();
this.addHandlers(page);
}, },
setSelectors:function(){
this.selectors.select2 = $(".select2"); /**
* Pages
*
*/
Pages:
{
init: function () {
Backend.tinyMCE.init();
},
},
/**
* Roles management
*/
Roles: {
selectors: {
associated: document.querySelector("select[name='associated_permissions']"),
associated_container: document.getElementById("#available-permissions"),
},
init(page) {
this.setSelectors();
this.setRolepermission(page);
this.addHandlers();
},
setSelectors: function () {
this.selectors.associated = document.querySelector("select[name='associated_permissions']");
this.selectors.associated_container = document.getElementById("available-permissions");
},
addHandlers: function () {
var associated = this.selectors.associated;
var associated_container = this.selectors.associated_container;
if (associated_container != null)
if (associated.value == "custom")
Backend.Utils.removeClass(associated_container, "hidden");
else
Backend.Utils.addClass(associated_container, 'hidden');
associated.onchange = function (event) {
if (associated_container != null)
if (associated.value == "custom")
Backend.Utils.removeClass(associated_container, "hidden");
else
Backend.Utils.addClass(associated_container, 'hidden');
};
},
setRolepermission: function (page) {
Backend.Users.setSelectors();
Backend.Users.addHandlers(page);
}
}, },
addHandlers: function (page) /**
{ * Users management
/** *
* This function is used to get clicked element role id and return required result */
*/ Users:
document.querySelectorAll(".get-role-for-permissions").forEach(function(element){ {
element.onclick =function(event){ selectors: {
callback = { select2: $(".select2"),
success:function(request){ getPremissionURL: "",
console.log("request",request,request.status); showPermission: document.querySelectorAll(".show-permissions")
if (request.status >= 200 && request.status < 400) { },
// Success! init: function (page) {
var response = JSON.parse(request.responseText); this.setSelectors();
var p = response.permissions; this.addHandlers(page);
var q = response.rolePermissions; },
var qAll = response.allPermissions; setSelectors: function () {
this.selectors.select2 = $(".select2");
this.selectors.getRoleForPermissions = document.querySelectorAll(".get-role-for-permissions");
document.querySelector(".get-available-permissions").innerHTML = ""; this.selectors.getAvailabelPermissions = document.querySelector(".get-available-permissions");
htmlstring = ""; this.selectors.Role3 = document.getElementById("role-3");
if (p.length == 0) { this.showPermission = document.querySelectorAll(".show-permissions");
document.querySelector(".get-available-permissions").innerHTML = '<p>There are no available permissions.</p>'; },
} else { addHandlers: function (page) {
for (var key in p) { /**
var addChecked = ''; * This function is used to get clicked element role id and return required result
if (qAll == 1 && q.length == 0) { */
addChecked = 'checked="checked"';
this.selectors.getRoleForPermissions.forEach(function (element) {
element.onclick = function (event) {
callback = {
success: function (request) {
if (request.status >= 200 && request.status < 400) {
// Success!
var response = JSON.parse(request.responseText);
var permissions = response.permissions;
var rolePermissions = response.rolePermissions;
var allPermisssions = response.allPermissions;
Backend.Users.selectors.getAvailabelPermissions.innerHTML = "";
htmlstring = "";
if (permissions.length == 0) {
Backend.Users.selectors.getAvailabelPermissions.innerHTML = '<p>There are no available permissions.</p>';
} else { } else {
if (typeof q[key] !== "undefined") { for (var key in permissions) {
addChecked = 'checked="checked"'; var addChecked = '';
if (allPermisssions == 1 && rolePermissions.length == 0) {
addChecked = 'checked="checked"';
} else {
if (typeof rolePermissions[key] !== "undefined") {
addChecked = 'checked="checked"';
}
}
htmlstring += '<label class="control control--checkbox"> <input type="checkbox" name="permissions[' + key + ']" value="' + key + '" id="perm_' + key + '" ' + addChecked + ' /> <label for="perm_' + key + '">' + permissions[key] + '</label> <div class="control__indicator"></div> </label> <br>';
} }
} }
htmlstring += '<label class="control control--checkbox"> <input type="checkbox" name="permissions[' + key + ']" value="' + key + '" id="perm_' + key + '" ' + addChecked + ' /> <label for="perm_' + key + '">' + p[key] + '</label> <div class="control__indicator"></div> </label> <br>'; Backend.Users.selectors.getAvailabelPermissions.innerHTML = htmlstring;
Backend.Utils.removeClass(document.getElementById("available-permissions"), 'hidden');
} else {
// We reached our target server, but it returned an error
Backend.Users.selectors.getAvailabelPermissions.innerHTML = '<p>There are no available permissions.</p>';
} }
},
error: function () {
Backend.Users.selectors.getAvailabelPermissions.innerHTML = '<p>There are no available permissions.</p>';
} }
document.querySelector(".get-available-permissions").innerHTML = htmlstring; };
Backend.Utils.removeClass(document.getElementById("available-permissions"),'hidden');
} else { Backend.Utils.ajaxrequest(Backend.Users.selectors.getPremissionURL, "post", { role_id: event.target.value }, Backend.Utils.csrf, callback);
// We reached our target server, but it returned an error
console.log("errror in request");
document.querySelector(".get-available-permissions").innerHTML = '<p>There are no available permissions.</p>';
}
},
error:function(){
console.log("errror");
document.querySelector(".get-available-permissions").innerHTML = '<p>There are no available permissions.</p>';
} }
}; });
if (page == "create") {
Backend.Utils.ajaxrequest(Backend.Access.selectors.getPremissionURL,"post",{role_id: event.target.value},csrf,callback); Backend.Users.selectors.Role3.click();
} }
});
if(page=="create"){
document.getElementById("role-3").click();
}
this.selectors.select2.select2(); this.selectors.select2.select2();
}, },
windowloadhandler:function(){ windowloadhandler: function () {
/*
deleted page showing the swal when click on peremenenant delition
*/
document.querySelectorAll("a[name='delete_user_perm']").forEach(function(element){
element.onclick = function(event){
event.preventDefault();
var linkURL = event.target.getAttribute("href");
swal({
title: Backend.Access.selectors.Areyousure,
text: Backend.Access.selectors.delete_user_confirm,
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: Backend.Access.selectors.continue,
cancelButtonText: Backend.Access.selectors.cancel,
closeOnConfirm: false
}, function(isConfirmed){
if (isConfirmed){
window.location.href = linkURL;
}
});
};
});
/**
* deleted user page handeler for user restore
*/
document.querySelectorAll("a[name='restore_user']").forEach(function(element){
element.onclick = function(event){
event.preventDefault();
var linkURL = event.target.getAttribute("href");
swal({ // scripts to be handeled on user create and edit when window is laoaded
title: Backend.Access.selectors.Areyousure, Backend.Users.selectors.showPermission.forEach(function (element) {
text: Backend.Access.selectors.restore_user_confirm, element.onclick = function (event) {
type: "warning", event.preventDefault();
showCancelButton: true, var $this = this;
confirmButtonColor: "#DD6B55", var role = $this.getAttribute("data-role");
confirmButtonText: Backend.Access.selectors.continue,
cancelButtonText: Backend.Access.selectors.cancel, var permissions = document.querySelector(".permission-list[data-role='" + role + "']");
closeOnConfirm: false var hideText = $this.querySelector('.hide-text');
}, function(isConfirmed){ var showText = $this.querySelector('.show-text');
if (isConfirmed){
window.location.href = linkURL; // show permission list
} Backend.Utils.toggleClass(permissions, 'hidden');
// toggle the text Show/Hide for the link
Backend.Utils.toggleClass(hideText, 'hidden');
Backend.Utils.toggleClass(showText, 'hidden');
};
}); });
}; }
}); },
} /**
}, * Users delete page
*
*/
UserDeleted: {
selectors: {
AlldeletePerms: document.querySelectorAll("a[name='delete_user_perm']"),
AllrestorePerms: document.querySelectorAll("a[name='restore_user']"),
Areyousure: "",
delete_user_confirm: "",
continue: "",
cancel: "",
restore_user_confirm: "",
},
setSelectors: function () {
this.selectors.AlldeletePerms = document.querySelectorAll("a[name='delete_user_perm']");
this.selectors.AllrestorePerms = document.querySelectorAll("a[name='restore_user']");
},
windowloadhandler: function () {
this.setSelectors();
/*
deleted page showing the swal when click on peremenenant delition
*/
this.selectors.AlldeletePerms.forEach(function (element) {
element.onclick = function (event) {
event.preventDefault();
var linkURL = this.getAttribute("href");
swal({
title: Backend.UserDeleted.selectors.Areyousure,
text: Backend.UserDeleted.selectors.delete_user_confirm,
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: Backend.UserDeleted.selectors.continue,
cancelButtonText: Backend.UserDeleted.selectors.cancel,
closeOnConfirm: false
}, function (isConfirmed) {
if (isConfirmed) {
window.location.href = linkURL;
}
});
};
});
/**
* deleted user page handeler for user restore
*/
this.selectors.AllrestorePerms.forEach(function (element) {
element.onclick = function (event, element) {
event.preventDefault();
var linkURL = this.getAttribute("href");
swal({
title: Backend.UserDeleted.selectors.Areyousure,
text: Backend.UserDeleted.selectors.restore_user_confirm,
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: Backend.UserDeleted.selectors.continue,
cancelButtonText: Backend.UserDeleted.selectors.cancel,
closeOnConfirm: false
}, function (isConfirmed) {
if (isConfirmed) {
window.location.href = linkURL;
}
});
};
});
}
},
/** /**
* Blog * Blog
* *
*/ */
Blog: Blog:
{ {
selectors: { selectors: {
tags: jQuery(".tags"), tags: jQuery(".tags"),
categories: jQuery(".categories"), categories: jQuery(".categories"),
toDisplay: jQuery(".toDisplay"), toDisplay: jQuery(".toDisplay"),
status: jQuery(".status"), status: jQuery(".status"),
datetimepicker1: jQuery("#datetimepicker1"),
GenerateSlugUrl: "",
name: document.getElementById("name"),
SlugUrl: "",
slug: document.getElementById("slug"),
},
init: function () {
this.addHandlers();
Backend.tinyMCE.init();
},
addHandlers: function () {
this.selectors.tags.select2({
tags: true,
});
this.selectors.categories.select2();
this.selectors.toDisplay.select2();
this.selectors.status.select2();
//For Blog datetimepicker for publish_datetime
this.selectors.datetimepicker1.datetimepicker();
// For generating the Slug //changing slug on blur event
this.selectors.name.onblur = function (event) {
url = event.target.value;
if (url !== '') {
callback = {
success: function (request) {
if (request.status >= 200 && request.status < 400) {
// Success!
response = request.responseText;
Backend.Blog.selectors.slug.value = Backend.Blog.selectors.SlugUrl + '/' + response;
}
},
error: function (request) {
}
};
Backend.Utils.ajaxrequest(Backend.Blog.selectors.GenerateSlugUrl, "post", { text: url }, Backend.Utils.csrf, callback);
}
};
}
}, },
/**
* Tiny MCE
*/
tinyMCE: {
init: function () { init: function () {
this.addHandlers(); tinymce.init({
Backend.tinyMCE.init(); path_absolute: "/",
}, selector: 'textarea',
height: 200,
width: 725,
theme: 'modern',
plugins: [
'advlist autolink lists link image charmap print preview hr anchor pagebreak',
'searchreplace wordcount visualblocks visualchars code fullscreen',
'insertdatetime nonbreaking save table contextmenu directionality',
'emoticons template paste textcolor colorpicker textpattern imagetools codesample toc'
],
toolbar1: 'undo redo | insert | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image',
// toolbar2: 'print preview media | forecolor backcolor emoticons | codesample',
image_advtab: true,
relative_urls: false,
file_browser_callback: function (field_name, url, type, win) {
var x = window.innerWidth || document.documentElement.clientWidth || document.getElementsByTagName('body')[0].clientWidth;
var y = window.innerHeight || document.documentElement.clientHeight || document.getElementsByTagName('body')[0].clientHeight;
var cmsURL = "/" + 'laravel-filemanager?field_name=' + field_name;
if (type == 'image') {
cmsURL = cmsURL + "&type=Images";
} else {
cmsURL = cmsURL + "&type=Files";
}
addHandlers: function () { tinyMCE.activeEditor.windowManager.open({
this.selectors.tags.select2({ file: cmsURL,
tags: true, title: 'Filemanager',
width: x * 0.8,
height: y * 0.8,
resizable: "yes",
close_previous: "no"
});
},
content_css: [
'//fonts.googleapis.com/css?family=Lato:300,300i,400,400i',
'//www.tinymce.com/css/codepen.min.css'
]
}); });
this.selectors.categories.select2();
this.selectors.toDisplay.select2();
this.selectors.status.select2();
} }
}, },
emailTemplate: {
/** selectors: {
* Tiny MCE emailtemplateSelection: document.querySelector(".select2")
*/ },
tinyMCE: {
init: function () {
tinymce.init({
path_absolute : "/",
selector: 'textarea',
height: 200,
width: 725,
theme: 'modern',
plugins: [
'advlist autolink lists link image charmap print preview hr anchor pagebreak',
'searchreplace wordcount visualblocks visualchars code fullscreen',
'insertdatetime nonbreaking save table contextmenu directionality',
'emoticons template paste textcolor colorpicker textpattern imagetools codesample toc'
],
toolbar1: 'undo redo | insert | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image',
// toolbar2: 'print preview media | forecolor backcolor emoticons | codesample',
image_advtab: true,
relative_urls : false,
file_browser_callback : function(field_name, url, type, win) {
var x = window.innerWidth || document.documentElement.clientWidth || document.getElementsByTagName('body')[0].clientWidth;
var y = window.innerHeight|| document.documentElement.clientHeight|| document.getElementsByTagName('body')[0].clientHeight;
var cmsURL = "/" + 'laravel-filemanager?field_name=' + field_name;
if (type == 'image') {
cmsURL = cmsURL + "&type=Images";
} else {
cmsURL = cmsURL + "&type=Files";
}
tinyMCE.activeEditor.windowManager.open({ init: function () {
file : cmsURL, Backend.emailTemplate.addHandlers();
title : 'Filemanager', Backend.tinyMCE.init();
width : x * 0.8, },
height : y * 0.8,
resizable : "yes",
close_previous : "no"
});
},
content_css: [
'//fonts.googleapis.com/css?family=Lato:300,300i,400,400i',
'//www.tinymce.com/css/codepen.min.css'
]
});
}
},
emailTemplate: { // ! Backend.emailTemplate.addHandlers
addHandlers: function () {
$(".select2").select2();
// to add placeholder in to active textarea
document.getElementById("addPlaceHolder").onclick = function (event) {
Backend.emailTemplate.addPlaceHolder(event);
};
document.getElementById("showPreview").onclick = function (event) {
Backend.emailTemplate.showPreview(event);
};
selectors: { },
emailtemplateSelection: document.querySelector(".select2")
},
init: function () { // ! Backend.emailTemplate.addPlaceHolder
Backend.emailTemplate.addHandlers(); addPlaceHolder: function (event) {
Backend.tinyMCE.init(); var placeHolder = document.getElementById('placeHolder').value;
}, if (placeHolder != '') {
tinymce.activeEditor.execCommand('mceInsertContent', false, "[" + $('#placeHolder :selected').text() + "]");
}
},
// ! Backend.emailTemplate.addHandlers // ! Backend.emailTemplate.showPreview
addHandlers: function () { showPreview: function (event) {
$(".select2").select2(); document.querySelector(".modal-body").innerHTML = tinyMCE.get('txtBody').getContent();
// to add placeholder in to active textarea //jQuery( ".modal-body" ).html(tinyMCE.get('txtBody').getContent());
document.getElementById("addPlaceHolder").onclick = function(event){ $(".model-wrapper").modal('show');
Backend.emailTemplate.addPlaceHolder(event);
};
document.getElementById("showPreview").onclick = function(event){
Backend.emailTemplate.showPreview(event);
};
},
// ! Backend.emailTemplate.addPlaceHolder },
addPlaceHolder: function (event) {
var placeHolder = document.getElementById('placeHolder').value;
if (placeHolder != '') {
tinymce.activeEditor.execCommand('mceInsertContent', false, "[" + $('#placeHolder :selected').text() + "]");
}
}, },
// ! Backend.emailTemplate.showPreview /**
showPreview: function (event) { * Faq
document.querySelector(".modal-body").innerHTML = tinyMCE.get('txtBody').getContent(); *
//jQuery( ".modal-body" ).html(tinyMCE.get('txtBody').getContent()); */
$(".model-wrapper").modal('show'); Faq:
{
}, selectors:
}, {
},
/**
* Faq
*
*/
Faq:
{
selectors:
{
},
init: function () init: function () {
{ // this.addHandlers();
// this.addHandlers(); Backend.tinyMCE.init();
Backend.tinyMCE.init(); },
},
addHandlers: function () addHandlers: function () {
{ }
} },
},
/** /**
...@@ -382,47 +492,45 @@ var Backend = {}; // common variable used in all the files of the backend ...@@ -382,47 +492,45 @@ var Backend = {}; // common variable used in all the files of the backend
* *
*/ */
Profile: Profile:
{
selectors:{
},
init: function ()
{
this.setSelectors();
this.addHandlers();
},
setSelectors:function(){
this.selectors.state = document.querySelector(".st");
this.selectors.cities = document.querySelector(".ct");
},
addHandlers: function ()
{ {
if(this.selectors.state!=null){ selectors: {
this.selectors.state.select2();
} },
if(this.selectors.cities!=null){ init: function () {
this.selectors.cities.select2(); this.setSelectors();
this.addHandlers();
},
setSelectors: function () {
this.selectors.state = document.querySelector(".st");
this.selectors.cities = document.querySelector(".ct");
},
addHandlers: function () {
if (this.selectors.state != null) {
this.selectors.state.select2();
}
if (this.selectors.cities != null) {
this.selectors.cities.select2();
}
} }
},
}
},
/** /**
* for all datatables * for all datatables
* *
*/ */
DataTableSearch: { //functionalities related to datable search at all the places DataTableSearch: { //functionalities related to datable search at all the places
selector:{ selector: {
}, },
init: function (dataTable) { init: function (dataTable) {
this.setSelectors(); this.setSelectors();
this.addHandlers(dataTable); this.addHandlers(dataTable);
}, },
setSelectors:function(){ setSelectors: function () {
this.selector.searchInput = document.querySelector("div.dataTables_filter input"); this.selector.searchInput = document.querySelector("div.dataTables_filter input");
this.selector.columnSearchInput = document.querySelectorAll(".search-input-text"); this.selector.columnSearchInput = document.querySelectorAll(".search-input-text");
this.selector.columnSelectInput = document.querySelectorAll('search-input-select'); this.selector.columnSelectInput = document.querySelectorAll('search-input-select');
...@@ -432,9 +540,9 @@ var Backend = {}; // common variable used in all the files of the backend ...@@ -432,9 +540,9 @@ var Backend = {}; // common variable used in all the files of the backend
this.setSelectors.excelButton = document.getElementById("excelButton"); this.setSelectors.excelButton = document.getElementById("excelButton");
this.setSelectors.pdfButton = document.getElementById("pdfButton"); this.setSelectors.pdfButton = document.getElementById("pdfButton");
this.setSelectors.printButton = document.getElementById("printButton"); this.setSelectors.printButton = document.getElementById("printButton");
}, },
cloneElement:function(element,callback){ cloneElement: function (element, callback) {
var clone = element.cloneNode(); var clone = element.cloneNode();
while (element.firstChild) { while (element.firstChild) {
clone.appendChild(element.lastChild); clone.appendChild(element.lastChild);
...@@ -443,47 +551,47 @@ var Backend = {}; // common variable used in all the files of the backend ...@@ -443,47 +551,47 @@ var Backend = {}; // common variable used in all the files of the backend
Backend.DataTableSearch.setSelectors(); Backend.DataTableSearch.setSelectors();
callback(this.selector.searchInput); callback(this.selector.searchInput);
}, },
addHandlers:function(dataTable){ addHandlers: function (dataTable) {
// get the datatable search input and on its key press check if we hit enter then search with datatable // get the datatable search input and on its key press check if we hit enter then search with datatable
this.cloneElement(this.selector.searchInput,function(element){ //cloning done to remove any binding of the events this.cloneElement(this.selector.searchInput, function (element) { //cloning done to remove any binding of the events
element.onkeypress = function(event){ element.onkeypress = function (event) {
if(event.keyCode==13){ if (event.keyCode == 13) {
dataTable.fnFilter( this.value ); dataTable.fnFilter(this.value);
} }
}; };
}); // to remove all the listinerers }); // to remove all the listinerers
// for text boxes // for text boxes
//column input search if search box on the column of the datatable given with enter then search with datatable //column input search if search box on the column of the datatable given with enter then search with datatable
if(this.selector.columnSearchInput.length>0){ if (this.selector.columnSearchInput.length > 0) {
this.selector.columnSearchInput.forEach(function(element){ this.selector.columnSearchInput.forEach(function (element) {
element.onkeypress = function(event){ element.onkeypress = function (event) {
if (event.keyCode == 13){ if (event.keyCode == 13) {
var i =element.getAttribute("data-column") // getting column index var i = element.getAttribute("data-column") // getting column index
var v =element.value; // getting search input value var v = element.value; // getting search input value
dataTable.api().columns(i).search(v).draw(); dataTable.api().columns(i).search(v).draw();
} }
}; };
}); });
} }
// Individual columns search // Individual columns search
if(this.selector.columnSelectInput.length>>0){ if (this.selector.columnSelectInput.length >> 0) {
this.selector.columnSelectInput.forEach(function(element){ this.selector.columnSelectInput.forEach(function (element) {
element.onchange = function(event){ element.onchange = function (event) {
var i =element.getAttribute("data-column"); // getting column index var i = element.getAttribute("data-column"); // getting column index
var v =element.value; // getting search input value var v = element.value; // getting search input value
dataTable.api().columns(i).search(v).draw(); dataTable.api().columns(i).search(v).draw();
}; };
}); });
} }
// Individual columns reset // Individual columns reset
if(this.selector.restButton.length>>0){ if (this.selector.restButton.length >> 0) {
this.selector.restButton.forEach(function(element){ this.selector.restButton.forEach(function (element) {
element.onclick = function(event){ element.onclick = function (event) {
var inputelement = this.previousElementSibling; var inputelement = this.previousElementSibling;
var i = inputelement.getAttribute("data-column"); var i = inputelement.getAttribute("data-column");
inputelement.value = ""; inputelement.value = "";
dataTable.api().columns(i).search("").draw(); dataTable.api().columns(i).search("").draw();
...@@ -491,25 +599,91 @@ var Backend = {}; // common variable used in all the files of the backend ...@@ -491,25 +599,91 @@ var Backend = {}; // common variable used in all the files of the backend
}); });
} }
this.setSelectors.copyButton.onclick = function(element){ this.setSelectors.copyButton.onclick = function (element) {
document.querySelector(".copyButton").click(); document.querySelector(".copyButton").click();
}; };
this.setSelectors.csvButton.onclick = function(element){ this.setSelectors.csvButton.onclick = function (element) {
document.querySelector(".csvButton").click(); document.querySelector(".csvButton").click();
}; };
this.setSelectors.excelButton.onclick = function(element){ this.setSelectors.excelButton.onclick = function (element) {
document.querySelector(".excelButton").click(); document.querySelector(".excelButton").click();
}; };
this.setSelectors.pdfButton.onclick = function(element){ this.setSelectors.pdfButton.onclick = function (element) {
document.querySelector(".pdfButton").click(); document.querySelector(".pdfButton").click();
}; };
this.setSelectors.printButton.onclick = function(element){ this.setSelectors.printButton.onclick = function (element) {
document.querySelector(".printButton").click(); document.querySelector(".printButton").click();
}; };
} }
} },
Settings: {
selectors: {
RouteURL: "",
setting: document.getElementById("setting")
},
init: function () {
this.setSelectors();
this.addHandlers();
},
setSelectors: function () {
this.selectors.setting = document.getElementById("setting");
this.selectors.removeLogo = document.querySelector(".remove-logo");
this.selectors.imageRemoveLogo = document.querySelector(".img-remove-logo");
this.selectors.imageRemoveFavicon = document.querySelector(".img-remove-favicon");
},
addHandlers: function () {
var route = this.selectors.RouteURL;
var data_id = this.selectors.setting.getAttribute("data-id");
route = route.replace('-1', data_id);
this.selectors.removeLogo.onclick = function (event) {
var data = event.target.getAttribute("data-id");
swal({
title: "Warning",
text: "Are you sure you want to remove?",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes",
closeOnConfirm: true
}, function (confirmed) {
if (confirmed) {
if (data == 'logo') {
value = 'logo';
Backend.Utils.addClass(Backend.Settings.selectors.imageRemoveLogo, 'hidden');
}
else {
value = 'favicon';
Backend.Utils.addClass(Backend.Settings.selectors.imageRemoveFavicon, 'hidden');
}
callback = {
success: function (request) {
if (request.status >= 200 && request.status < 400) {
// Success!
}
},
error: function (request) {
}
};
Backend.Utils.ajaxrequest(route, "POST", { data: value, _token: Backend.Utils.csrf }, Backend.Utils.csrf, callback);
}
});
};
}
}
}; };
})(); })();
......
...@@ -89,8 +89,8 @@ ...@@ -89,8 +89,8 @@
@section('after-scripts') @section('after-scripts')
{{ Html::script('js/backend/access/roles/script.js') }} {{ Html::script('js/backend/access/roles/script.js') }}
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function() { Backend.Utils.documentReady(function(){
Backend.Access.init(); Backend.Roles.init("rolecreate")
}); });
</script> </script>
@endsection @endsection
...@@ -74,10 +74,10 @@ ...@@ -74,10 +74,10 @@
@endsection @endsection
@section('after-scripts') @section('after-scripts')
{{ Html::script('js/backend/access/roles/script.js') }}
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function() { Backend.Utils.documentReady(function(){
Backend.Access.init(); Backend.Roles.init("edit")
}); });
</script> </script>
@endsection @endsection
\ No newline at end of file
...@@ -179,15 +179,18 @@ ...@@ -179,15 +179,18 @@
@endsection @endsection
@section('after-scripts') @section('after-scripts')
{{ Html::script('js/backend/access/users/script.js') }}
<script type="text/javascript"> <script type="text/javascript">
Backend.Utils.documentReady(function(){ Backend.Utils.documentReady(function(){
csrf = document.querySelector('meta[name="csrf-token"]').getAttribute('content'); Backend.Users.selectors.getPremissionURL = "{{ route('admin.get.permission') }}";
Backend.Access.selectors.getPremissionURL = "{{ route('admin.get.permission') }}"; Backend.Users.init("create");
Backend.Access.init("create");
}); });
window.onload = function () {
Backend.Users.windowloadhandler();
};
</script> </script>
@endsection @endsection
...@@ -109,18 +109,19 @@ ...@@ -109,18 +109,19 @@
Backend.DataTableSearch.init(dataTable); Backend.DataTableSearch.init(dataTable);
Backend.Access.selectors.Areyousure = "{{ trans('strings.backend.general.are_you_sure') }}"; Backend.UserDeleted.selectors.Areyousure = "{{ trans('strings.backend.general.are_you_sure') }}";
Backend.Access.selectors.delete_user_confirm = "{{ trans('strings.backend.access.users.delete_user_confirm') }}"; Backend.UserDeleted.selectors.delete_user_confirm = "{{ trans('strings.backend.access.users.delete_user_confirm') }}";
Backend.Access.selectors.continue = "{{ trans('strings.backend.general.continue') }}"; Backend.UserDeleted.selectors.continue = "{{ trans('strings.backend.general.continue') }}";
Backend.Access.selectors.cancel ="{{ trans('buttons.general.cancel') }}"; Backend.UserDeleted.selectors.cancel ="{{ trans('buttons.general.cancel') }}";
Backend.Access.selectors.restore_user_confirm ="{{ trans('strings.backend.access.users.restore_user_confirm') }}"; Backend.UserDeleted.selectors.restore_user_confirm ="{{ trans('strings.backend.access.users.restore_user_confirm') }}";
})(); })();
window.onload = function(){ window.onload = function(){
Backend.Access.windowloadhandler();
Backend.UserDeleted.windowloadhandler();
} }
</script> </script>
......
...@@ -104,7 +104,7 @@ ...@@ -104,7 +104,7 @@
@if (count($role->permissions) > 0) @if (count($role->permissions) > 0)
<blockquote class="small"> <blockquote class="small">
@foreach ($role->permissions as $perm) @foreach ($role->permissions as $perm)
{{$perm->display_name}} {{$perm->display_name}}<br/>
@endforeach @endforeach
</blockquote> </blockquote>
@else @else
...@@ -164,114 +164,15 @@ ...@@ -164,114 +164,15 @@
@endsection @endsection
@section('after-scripts') @section('after-scripts')
{{ Html::script('js/backend/access/users/script.js') }}
<script type="text/javascript"> <script type="text/javascript">
/*
jQuery(document).ready(function() {
Backend.Access.init();
/**
* This function is used to get clicked element role id and return required result
*/
/* jQuery('.get-role-for-permissions').click(function () {
$.ajax({
type: "POST",
url: "{{ route('admin.get.permission') }}",
dataType: "JSON",
data: {role_id: $(this).val()},
success: function (response) {
var p = response.permissions;
var q = response.rolePermissions;
var qAll = response.allPermissions;
$('.get-available-permissions').html('');
if (p.length == 0) {
('.get-available-permissions').html('<p>There are no available permissions.</p>');
} else {
for (var key in p) {
var addChecked = '';
if (qAll == 1 && q.length == 0) {
addChecked = 'checked="checked"';
} else {
if (typeof q[key] !== "undefined") {
addChecked = 'checked="checked"';
}
}
$('<label class="control control--checkbox"> <input type="checkbox" name="permissions[' + key + ']" value="' + key + '" id="perm_' + key + '" ' + addChecked + ' /> <label for="perm_' + key + '">' + p[key] + '</label> <div class="control__indicator"></div> </label><br>').appendTo('.get-available-permissions');
}
}
$('#available-permissions').removeClass('hidden');
}
});
});
});
*/
Backend.Utils.documentReady(function(){ Backend.Utils.documentReady(function(){
csrf = document.querySelector('meta[name="csrf-token"]').getAttribute('content'); csrf = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
Backend.Access.selectors.getPremissionURL = "{{ route('admin.get.permission') }}"; Backend.Users.selectors.getPremissionURL = "{{ route('admin.get.permission') }}";
Backend.Access.init("edit"); Backend.Users.init("edit");
/*
Backend.Access.init();
csrf = $('meta[name="csrf-token"]').attr('content');
/**
* This function is used to get clicked element role id and return required result
*/
/* document.querySelectorAll(".get-role-for-permissions").forEach(function(element){
element.onclick =function(event){
callback = {
success:function(request){
console.log("request",request,request.status);
if (request.status >= 200 && request.status < 400) {
// Success!
var response = JSON.parse(request.responseText);
var p = response.permissions;
var q = response.rolePermissions;
var qAll = response.allPermissions;
document.querySelector(".get-available-permissions").innerHTML = "";
htmlstring = "";
if (p.length == 0) {
document.querySelector(".get-available-permissions").innerHTML = '<p>There are no available permissions.</p>';
} else {
for (var key in p) {
var addChecked = '';
if (qAll == 1 && q.length == 0) {
addChecked = 'checked="checked"';
} else {
if (typeof q[key] !== "undefined") {
addChecked = 'checked="checked"';
}
}
htmlstring += '<label class="control control--checkbox"> <input type="checkbox" name="permissions[' + key + ']" value="' + key + '" id="perm_' + key + '" ' + addChecked + ' /> <label for="perm_' + key + '">' + p[key] + '</label> <div class="control__indicator"></div> </label> <br>';
}
}
document.querySelector(".get-available-permissions").innerHTML = htmlstring;
Backend.Utils.removeClass(document.getElementById("available-permissions"),'hidden');
} else {
// We reached our target server, but it returned an error
console.log("errror in request");
document.querySelector(".get-available-permissions").innerHTML = '<p>There are no available permissions.</p>';
}
},
error:function(){
console.log("errror");
document.querySelector(".get-available-permissions").innerHTML = '<p>There are no available permissions.</p>';
}
};
Backend.Utils.ajaxrequest("{{ route('admin.get.permission') }}","post",{role_id: event.target.value ,"_tocken":csrf},csrf,callback);
}
});
*/
}); });
window.onload = function () {
Backend.Users.windowloadhandler();
};
</script> </script>
@endsection @endsection
...@@ -125,27 +125,10 @@ ...@@ -125,27 +125,10 @@
@section("after-scripts") @section("after-scripts")
<script type="text/javascript"> <script type="text/javascript">
Backend.Blog.init();
//For Blog datetimepicker for publish_datetime Backend.Blog.selectors.GenerateSlugUrl = "{{route('admin.generate.slug')}}";
$('#datetimepicker1').datetimepicker(); Backend.Blog.selectors.SlugUrl = "{{url('/')}}";
Backend.Blog.init();
//changing slug on blur event
$("#name").on('blur',function()
{
url = $(this).val();
console.log(url);
if(url !== '')
{
$.ajax({
type:"POST",
url : "{{route('admin.generate.slug')}}",
data : {text:url },
success : function(data) {
$('#slug').val( "{{url('/')}}" + '/' + data);
}
});
}
});
</script> </script>
@endsection @endsection
\ No newline at end of file
...@@ -243,6 +243,17 @@ ...@@ -243,6 +243,17 @@
@section('after-scripts') @section('after-scripts')
<script src='/js/backend/bootstrap-tabcollapse.js'></script> <script src='/js/backend/bootstrap-tabcollapse.js'></script>
<script> <script>
(function(){
Backend.Utils.csrf = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
Backend.Settings.selectors.RouteURL = "{{ route('admin.removeIcon', -1) }}";
Backend.Settings.init();
})();
window.load = function(){
}
/*
var route = "{{ route('admin.removeIcon', -1) }}"; var route = "{{ route('admin.removeIcon', -1) }}";
var data_id = $('#setting').data('id'); var data_id = $('#setting').data('id');
...@@ -281,7 +292,8 @@ ...@@ -281,7 +292,8 @@
} }
}); });
}); });
*/
$('#myTab').tabCollapse({ $('#myTab').tabCollapse({
tabsClass: 'hidden-sm hidden-xs', tabsClass: 'hidden-sm hidden-xs',
accordionClass: 'visible-sm visible-xs' accordionClass: 'visible-sm visible-xs'
......
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment