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'),
toggleClass: function (element, className) {
if (element.classList) { if (element.classList) {
element.classList.toggle(className); element.classList.toggle(className);
} else { } else {
...@@ -21,15 +21,28 @@ var Backend = {}; // common variable used in all the files of the backend ...@@ -21,15 +21,28 @@ var Backend = {}; // common variable used in all the files of the backend
element.className = classes.join(' '); element.className = classes.join(' ');
} }
}, },
documentReady : function(callback){ addClass: function (element, className) {
if (document.attachEvent ? document.readyState === "complete" : document.readyState !== "loading"){ if (element.classList)
element.classList.add(className);
else
element.className += ' ' + className;
},
removeClass: function (el, className) {
if (el.classList)
el.classList.remove(className);
else
el.className = el.className.replace(new RegExp('(^|\\b)' + className.split(' ').join('|') + '(\\b|$)', 'gi'), ' ');
},
documentReady: function (callback) {
if (document.attachEvent ? document.readyState === "complete" : document.readyState !== "loading") {
callback(); callback();
} else { } else {
document.addEventListener('DOMContentLoaded', callback); document.addEventListener('DOMContentLoaded', callback);
} }
}, },
ajaxrequest:function(url,method,data,csrf,callback){ ajaxrequest: function (url, method, data, csrf, callback) {
var request = new XMLHttpRequest(); var request = new XMLHttpRequest();
if (window.XMLHttpRequest) { if (window.XMLHttpRequest) {
// code for modern browsers // code for modern browsers
...@@ -41,51 +54,39 @@ var Backend = {}; // common variable used in all the files of the backend ...@@ -41,51 +54,39 @@ var Backend = {}; // common variable used in all the files of the backend
request.open(method, url, true); request.open(method, url, true);
request.setRequestHeader('X-CSRF-TOKEN', csrf); request.setRequestHeader('X-CSRF-TOKEN', csrf);
request.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); request.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
if("post" === method.toLowerCase()){ if ("post" === method.toLowerCase() || "patch" === method.toLowerCase()) {
request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8'); request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
data = this.jsontoformdata(data); data = this.jsontoformdata(data);
} }
// when request is in the ready state change the details or perform success function // when request is in the ready state change the details or perform success function
request.onreadystatechange = function() request.onreadystatechange = function () {
{
if (request.readyState === XMLHttpRequest.DONE) { if (request.readyState === XMLHttpRequest.DONE) {
// Everything is good, the response was received. // Everything is good, the response was received.
request.onload = callback.success(request); request.onload = callback.success(request);
} }
}; };
request.onerror = callback.error; request.onerror = callback.error;
request.send(data); request.send(data);
}, },
// This should probably only be used if all JSON elements are strings // This should probably only be used if all JSON elements are strings
jsontoformdata:function (srcjson){ jsontoformdata: function (srcjson) {
if(typeof srcjson !== "object") if (typeof srcjson !== "object")
if(typeof console !== "undefined"){ if (typeof console !== "undefined") {
console.log("\"srcjson\" is not a JSON object"); console.log("\"srcjson\" is not a JSON object");
return null; return null;
} }
u = encodeURIComponent; u = encodeURIComponent;
var urljson = ""; var urljson = "";
var keys = Object.keys(srcjson); var keys = Object.keys(srcjson);
for(var i=0; i <keys.length; i++){ for (var i = 0; i < keys.length; i++) {
urljson += u(keys[i]) + "=" + u(srcjson[keys[i]]); urljson += u(keys[i]) + "=" + u(srcjson[keys[i]]);
if(i < (keys.length-1))urljson+="&"; if (i < (keys.length - 1)) urljson += "&";
} }
return urljson; return urljson;
}, },
removeClass:function(el,className){
if (el.classList)
el.classList.remove(className);
else
el.className = el.className.replace(new RegExp('(^|\\b)' + className.split(' ').join('|') + '(\\b|$)', 'gi'), ' ');
}
}, },
...@@ -95,116 +96,194 @@ var Backend = {}; // common variable used in all the files of the backend ...@@ -95,116 +96,194 @@ var Backend = {}; // common variable used in all the files of the backend
*/ */
Pages: Pages:
{ {
init: function() init: function () {
{
Backend.tinyMCE.init(); Backend.tinyMCE.init();
}, },
}, },
/** /**
* Access management * 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);
}
},
/**
* Users management
* *
*/ */
Access: Users:
{ {
selectors: { selectors: {
select2: $(".select2"), select2: $(".select2"),
getPremissionURL:"", getPremissionURL: "",
Areyousure:"", showPermission: document.querySelectorAll(".show-permissions")
delete_user_confirm:"",
continue:"",
cancel:"",
restore_user_confirm:"",
}, },
init: function (page) {
init: function (page)
{
this.setSelectors(); this.setSelectors();
this.addHandlers(page); this.addHandlers(page);
}, },
setSelectors:function(){ setSelectors: function () {
this.selectors.select2 = $(".select2"); this.selectors.select2 = $(".select2");
this.selectors.getRoleForPermissions = document.querySelectorAll(".get-role-for-permissions");
this.selectors.getAvailabelPermissions = document.querySelector(".get-available-permissions");
this.selectors.Role3 = document.getElementById("role-3");
this.showPermission = document.querySelectorAll(".show-permissions");
}, },
addHandlers: function (page) addHandlers: function (page) {
{
/** /**
* This function is used to get clicked element role id and return required result * 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){ this.selectors.getRoleForPermissions.forEach(function (element) {
element.onclick = function (event) {
callback = { callback = {
success:function(request){ success: function (request) {
console.log("request",request,request.status);
if (request.status >= 200 && request.status < 400) { if (request.status >= 200 && request.status < 400) {
// Success! // Success!
var response = JSON.parse(request.responseText); var response = JSON.parse(request.responseText);
var p = response.permissions; var permissions = response.permissions;
var q = response.rolePermissions; var rolePermissions = response.rolePermissions;
var qAll = response.allPermissions; var allPermisssions = response.allPermissions;
Backend.Users.selectors.getAvailabelPermissions.innerHTML = "";
document.querySelector(".get-available-permissions").innerHTML = "";
htmlstring = ""; htmlstring = "";
if (p.length == 0) { if (permissions.length == 0) {
document.querySelector(".get-available-permissions").innerHTML = '<p>There are no available permissions.</p>'; Backend.Users.selectors.getAvailabelPermissions.innerHTML = '<p>There are no available permissions.</p>';
} else { } else {
for (var key in p) { for (var key in permissions) {
var addChecked = ''; var addChecked = '';
if (qAll == 1 && q.length == 0) { if (allPermisssions == 1 && rolePermissions.length == 0) {
addChecked = 'checked="checked"'; addChecked = 'checked="checked"';
} else { } else {
if (typeof q[key] !== "undefined") { if (typeof rolePermissions[key] !== "undefined") {
addChecked = 'checked="checked"'; 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>'; 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>';
} }
} }
document.querySelector(".get-available-permissions").innerHTML = htmlstring; Backend.Users.selectors.getAvailabelPermissions.innerHTML = htmlstring;
Backend.Utils.removeClass(document.getElementById("available-permissions"),'hidden'); Backend.Utils.removeClass(document.getElementById("available-permissions"), 'hidden');
} else { } else {
// We reached our target server, but it returned an error // We reached our target server, but it returned an error
console.log("errror in request"); Backend.Users.selectors.getAvailabelPermissions.innerHTML = '<p>There are no available permissions.</p>';
document.querySelector(".get-available-permissions").innerHTML = '<p>There are no available permissions.</p>';
} }
}, },
error:function(){ error: function () {
console.log("errror"); Backend.Users.selectors.getAvailabelPermissions.innerHTML = '<p>There are no available permissions.</p>';
document.querySelector(".get-available-permissions").innerHTML = '<p>There are no available permissions.</p>';
} }
}; };
Backend.Utils.ajaxrequest(Backend.Access.selectors.getPremissionURL,"post",{role_id: event.target.value},csrf,callback); Backend.Utils.ajaxrequest(Backend.Users.selectors.getPremissionURL, "post", { role_id: event.target.value }, Backend.Utils.csrf, callback);
} }
}); });
if(page=="create"){ if (page == "create") {
document.getElementById("role-3").click(); Backend.Users.selectors.Role3.click();
} }
this.selectors.select2.select2(); this.selectors.select2.select2();
}, },
windowloadhandler:function(){ windowloadhandler: function () {
// scripts to be handeled on user create and edit when window is laoaded
Backend.Users.selectors.showPermission.forEach(function (element) {
element.onclick = function (event) {
event.preventDefault();
var $this = this;
var role = $this.getAttribute("data-role");
var permissions = document.querySelector(".permission-list[data-role='" + role + "']");
var hideText = $this.querySelector('.hide-text');
var showText = $this.querySelector('.show-text');
// 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 deleted page showing the swal when click on peremenenant delition
*/ */
document.querySelectorAll("a[name='delete_user_perm']").forEach(function(element){ this.selectors.AlldeletePerms.forEach(function (element) {
element.onclick = function(event){ element.onclick = function (event) {
event.preventDefault(); event.preventDefault();
var linkURL = event.target.getAttribute("href"); var linkURL = this.getAttribute("href");
swal({ swal({
title: Backend.Access.selectors.Areyousure, title: Backend.UserDeleted.selectors.Areyousure,
text: Backend.Access.selectors.delete_user_confirm, text: Backend.UserDeleted.selectors.delete_user_confirm,
type: "warning", type: "warning",
showCancelButton: true, showCancelButton: true,
confirmButtonColor: "#DD6B55", confirmButtonColor: "#DD6B55",
confirmButtonText: Backend.Access.selectors.continue, confirmButtonText: Backend.UserDeleted.selectors.continue,
cancelButtonText: Backend.Access.selectors.cancel, cancelButtonText: Backend.UserDeleted.selectors.cancel,
closeOnConfirm: false closeOnConfirm: false
}, function(isConfirmed){ }, function (isConfirmed) {
if (isConfirmed){ if (isConfirmed) {
window.location.href = linkURL; window.location.href = linkURL;
} }
}); });
...@@ -213,22 +292,24 @@ var Backend = {}; // common variable used in all the files of the backend ...@@ -213,22 +292,24 @@ var Backend = {}; // common variable used in all the files of the backend
/** /**
* deleted user page handeler for user restore * deleted user page handeler for user restore
*/ */
document.querySelectorAll("a[name='restore_user']").forEach(function(element){ this.selectors.AllrestorePerms.forEach(function (element) {
element.onclick = function(event){
element.onclick = function (event, element) {
event.preventDefault(); event.preventDefault();
var linkURL = event.target.getAttribute("href");
var linkURL = this.getAttribute("href");
swal({ swal({
title: Backend.Access.selectors.Areyousure, title: Backend.UserDeleted.selectors.Areyousure,
text: Backend.Access.selectors.restore_user_confirm, text: Backend.UserDeleted.selectors.restore_user_confirm,
type: "warning", type: "warning",
showCancelButton: true, showCancelButton: true,
confirmButtonColor: "#DD6B55", confirmButtonColor: "#DD6B55",
confirmButtonText: Backend.Access.selectors.continue, confirmButtonText: Backend.UserDeleted.selectors.continue,
cancelButtonText: Backend.Access.selectors.cancel, cancelButtonText: Backend.UserDeleted.selectors.cancel,
closeOnConfirm: false closeOnConfirm: false
}, function(isConfirmed){ }, function (isConfirmed) {
if (isConfirmed){ if (isConfirmed) {
window.location.href = linkURL; window.location.href = linkURL;
} }
}); });
...@@ -236,6 +317,7 @@ var Backend = {}; // common variable used in all the files of the backend ...@@ -236,6 +317,7 @@ var Backend = {}; // common variable used in all the files of the backend
}); });
} }
}, },
/** /**
* Blog * Blog
* *
...@@ -247,6 +329,11 @@ var Backend = {}; // common variable used in all the files of the backend ...@@ -247,6 +329,11 @@ var Backend = {}; // common variable used in all the files of the backend
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 () { init: function () {
...@@ -255,12 +342,37 @@ var Backend = {}; // common variable used in all the files of the backend ...@@ -255,12 +342,37 @@ var Backend = {}; // common variable used in all the files of the backend
}, },
addHandlers: function () { addHandlers: function () {
this.selectors.tags.select2({ this.selectors.tags.select2({
tags: true, tags: true,
}); });
this.selectors.categories.select2(); this.selectors.categories.select2();
this.selectors.toDisplay.select2(); this.selectors.toDisplay.select2();
this.selectors.status.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);
}
};
} }
}, },
...@@ -271,7 +383,7 @@ var Backend = {}; // common variable used in all the files of the backend ...@@ -271,7 +383,7 @@ var Backend = {}; // common variable used in all the files of the backend
tinyMCE: { tinyMCE: {
init: function () { init: function () {
tinymce.init({ tinymce.init({
path_absolute : "/", path_absolute: "/",
selector: 'textarea', selector: 'textarea',
height: 200, height: 200,
width: 725, width: 725,
...@@ -283,12 +395,12 @@ var Backend = {}; // common variable used in all the files of the backend ...@@ -283,12 +395,12 @@ var Backend = {}; // common variable used in all the files of the backend
'emoticons template paste textcolor colorpicker textpattern imagetools codesample toc' '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', 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', // toolbar2: 'print preview media | forecolor backcolor emoticons | codesample',
image_advtab: true, image_advtab: true,
relative_urls : false, relative_urls: false,
file_browser_callback : function(field_name, url, type, win) { file_browser_callback: function (field_name, url, type, win) {
var x = window.innerWidth || document.documentElement.clientWidth || document.getElementsByTagName('body')[0].clientWidth; 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 y = window.innerHeight || document.documentElement.clientHeight || document.getElementsByTagName('body')[0].clientHeight;
var cmsURL = "/" + 'laravel-filemanager?field_name=' + field_name; var cmsURL = "/" + 'laravel-filemanager?field_name=' + field_name;
if (type == 'image') { if (type == 'image') {
...@@ -298,12 +410,12 @@ var Backend = {}; // common variable used in all the files of the backend ...@@ -298,12 +410,12 @@ var Backend = {}; // common variable used in all the files of the backend
} }
tinyMCE.activeEditor.windowManager.open({ tinyMCE.activeEditor.windowManager.open({
file : cmsURL, file: cmsURL,
title : 'Filemanager', title: 'Filemanager',
width : x * 0.8, width: x * 0.8,
height : y * 0.8, height: y * 0.8,
resizable : "yes", resizable: "yes",
close_previous : "no" close_previous: "no"
}); });
}, },
content_css: [ content_css: [
...@@ -329,10 +441,10 @@ var Backend = {}; // common variable used in all the files of the backend ...@@ -329,10 +441,10 @@ var Backend = {}; // common variable used in all the files of the backend
addHandlers: function () { addHandlers: function () {
$(".select2").select2(); $(".select2").select2();
// to add placeholder in to active textarea // to add placeholder in to active textarea
document.getElementById("addPlaceHolder").onclick = function(event){ document.getElementById("addPlaceHolder").onclick = function (event) {
Backend.emailTemplate.addPlaceHolder(event); Backend.emailTemplate.addPlaceHolder(event);
}; };
document.getElementById("showPreview").onclick = function(event){ document.getElementById("showPreview").onclick = function (event) {
Backend.emailTemplate.showPreview(event); Backend.emailTemplate.showPreview(event);
}; };
...@@ -365,14 +477,12 @@ var Backend = {}; // common variable used in all the files of the backend ...@@ -365,14 +477,12 @@ var Backend = {}; // common variable used in all the files of the backend
{ {
}, },
init: function () init: function () {
{
// this.addHandlers(); // this.addHandlers();
Backend.tinyMCE.init(); Backend.tinyMCE.init();
}, },
addHandlers: function () addHandlers: function () {
{
} }
}, },
...@@ -383,25 +493,23 @@ var Backend = {}; // common variable used in all the files of the backend ...@@ -383,25 +493,23 @@ var Backend = {}; // common variable used in all the files of the backend
*/ */
Profile: Profile:
{ {
selectors:{ selectors: {
}, },
init: function () init: function () {
{
this.setSelectors(); this.setSelectors();
this.addHandlers(); this.addHandlers();
}, },
setSelectors:function(){ setSelectors: function () {
this.selectors.state = document.querySelector(".st"); this.selectors.state = document.querySelector(".st");
this.selectors.cities = document.querySelector(".ct"); this.selectors.cities = document.querySelector(".ct");
}, },
addHandlers: function () addHandlers: function () {
{ if (this.selectors.state != null) {
if(this.selectors.state!=null){
this.selectors.state.select2(); this.selectors.state.select2();
} }
if(this.selectors.cities!=null){ if (this.selectors.cities != null) {
this.selectors.cities.select2(); this.selectors.cities.select2();
} }
...@@ -413,7 +521,7 @@ var Backend = {}; // common variable used in all the files of the backend ...@@ -413,7 +521,7 @@ var Backend = {}; // common variable used in all the files of the backend
* *
*/ */
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) {
...@@ -422,7 +530,7 @@ var Backend = {}; // common variable used in all the files of the backend ...@@ -422,7 +530,7 @@ var Backend = {}; // common variable used in all the files of the backend
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');
...@@ -434,7 +542,7 @@ var Backend = {}; // common variable used in all the files of the backend ...@@ -434,7 +542,7 @@ var Backend = {}; // common variable used in all the files of the backend
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,24 +551,24 @@ var Backend = {}; // common variable used in all the files of the backend ...@@ -443,24 +551,24 @@ 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();
} }
}; };
...@@ -469,20 +577,20 @@ var Backend = {}; // common variable used in all the files of the backend ...@@ -469,20 +577,20 @@ var Backend = {}; // common variable used in all the files of the backend
// 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 = "";
...@@ -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.selectors.GenerateSlugUrl = "{{route('admin.generate.slug')}}";
Backend.Blog.selectors.SlugUrl = "{{url('/')}}";
Backend.Blog.init(); Backend.Blog.init();
//For Blog datetimepicker for publish_datetime
$('#datetimepicker1').datetimepicker();
//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');
...@@ -282,6 +293,7 @@ ...@@ -282,6 +293,7 @@
}); });
}); });
*/
$('#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