(function ($) {
"use strict";
/*** loader ***/
$( document ).ajaxStart(function() {
$('.main-content').prepend( '
');
});
$( document ).ajaxStop(function() {
$('.loading').remove();
});
//tootltips
$('[data-toggle="tooltips"]').tooltip();
//menu
//var pathactualc = location.pathname.split("/");
//var pathactual = pathactualc[2];
var pathactual = $('body').attr('id');
$('.custom-nav li.'+ pathactual).addClass('active');
$('.menu-list.' + pathactual).addClass('nav-active');
//boton cancelar manda al index en todos lados
$(document).on('click', '#cancel', function () {
document.location.href = 'index.php';
});
/// cuando escondo ventana modal la destruyo
$(document).on('hidden.bs.modal', '#myModal', function () {
$(this).remove();
$("html").css("margin-right", "0px");
});
/************** TERMINA SCRIPTS PERSONALIZADOS *****************************/
// validacion
//metodo agregado
$.validator.addMethod('selec', function (value) {
return value != 'selec';
}, 'Seleccione una opcion');
//metodo agregado
$.validator.addMethod('fecha', function (value) {
return value !== '';
}, 'Seleccione una fecha');
//metodo agregado
$.validator.addMethod('ContainsAtLeastOneDigit', function (value) {
return (/[0-9]/).test(value);
}, 'Su password debe contener al menos un número.');
//metodo agregado
$.validator.addMethod('ContainsAtLeastOneCapitalLetter', function (value) {
return (/[A-Z]/).test(value);
}, 'Su password debe contener al menos una letra mayúscula.');
//metodo agregado
$.validator.addMethod('ContainsAtLeastOneNonCapitalLetter', function (value) {
return (/[a-z]/).test(value);
}, 'Su password debe contener al menos una letra minúscula.');
//Reglas
$.validator.addClassRules({
passn0: { // this is from the name="password" attribute, not id="password-id" attribute
ContainsAtLeastOneDigit: true,
ContainsAtLeastOneCapitalLetter: true,
ContainsAtLeastOneNonCapitalLetter: true
},
passn1: { // this is from the name="password2" attribute, not id="password2-id" attribute
equalTo: '#passn0'
},
pass: {
remote: {
url: 'php/actualpasschk.php',
type: 'post'
}
},
user: {
remote: {
url: 'php/veruser.php',
type: 'post'
}
},
});
//Defaults
$.validator.setDefaults({
messages: {
passn1: {
equalTo: 'La contraseña no coincide con la introducida en el campo anterior'
},
pass: {
remote: 'La contraseña no es correcta'
},
user: {
remote: 'El usuario ingresado ya se encuentra en uso'
}
},
highlight: function (element) { //donde aplico el error
$(element).closest('.form-group').removeClass('has-success').addClass('has-error');
},
success: function (element) { //donde aplico el succes
$(element).closest('.form-group').removeClass('has-error').addClass('has-success');
},
errorClass: 'help-block',
errorPlacement: function(error,element){
var aca = $(element).closest('.input-group');
if(element.hasClass('appendedtext')){
error.insertAfter(aca);
}else{
error.insertAfter(element);
}
}
});
/// Recopilo info de un form a un array json
$.extend({
cosecha: function(elemento, id_registro){
/// armo el array para mandar, empiezo con los archivos y sus descripciones
var archivos = [];
var oRd = 1;
//recorro cada uno
$('.archivosup .itemsUp').each(function(){
var idFile = $(this).attr('id');
var estado = $(this).attr('rel');
var namef = $(this).children('.desc').val();
var row = {}
row ['archivo'] = idFile;
row ['desc'] = namef;
row ['orden'] = oRd;
row ['estado'] = estado;
///meto en el array
archivos.push(row);
oRd = oRd + 1;
});
$(elemento).find('input, textarea, select').not('.desc, :input[type=button], :input[type=submit], :input[type=reset]').each(function(){
var tipoinput = $(this).attr('type');
var idCampo = $(this).attr('id');
var namef = $(this).val();
var row = {}
row ['campo'] = idCampo;
row ['valor'] = namef;
///meto en el array
archivos.push(row);
});
if(id_registro){
//agrego el id del registro
var row = {}
row ['campo'] = 'id_registro';
row ['valor'] = id_registro;
///meto en el array
archivos.push(row);
}
return archivos;
}
});
//alertas y confirms
alertify.defaults = {
// dialogs defaults
modal:true,
basic:false,
frameless:false,
movable:false,
resizable:false,
closable:true,
closableByDimmer:true,
maximizable:false,
startMaximized:false,
pinnable:true,
pinned:true,
padding: true,
overflow:true,
maintainFocus:true,
transition:'slide',
autoReset:true,
// notifier defaults
notifier:{
// auto-dismiss wait time (in seconds)
delay:3,
// default position
position:'top-right'
},
// language resources
glossary:{
// dialogs default title
title:'Atención!',
// ok button text
ok: 'Aceptar',
// cancel button text
cancel: 'Cancelar'
},
// theme settings
theme:{
// class name attached to prompt dialog input textbox.
input:'form-control',
// class name attached to ok button
ok:'btn btn-primary',
// class name attached to cancel button
cancel:'btn btn-danger'
}
};
// custom scrollbar
/*$("html").niceScroll({
styler: "fb",
cursorcolor: "#65cea7",
cursorwidth: '10',
cursorborderradius: '0px',
background: '#424f63',
spacebarenabled: false,
cursorborder: '0',
zindex: '1000'
});
$(".left-side").niceScroll({
styler: "fb",
cursorcolor: "#65cea7",
cursorwidth: '3',
cursorborderradius: '0px',
background: '#424f63',
spacebarenabled: false,
cursorborder: '0'
});
$(".left-side").getNiceScroll();
if ($('body').hasClass('left-side-collapsed')) {
$(".left-side").getNiceScroll().hide();
}*/
// Toggle Left Menu
$('.menu-list > a').click(function () {
var parent = $(this).parent();
var sub = parent.find('> ul');
if (!$('body').hasClass('left-side-collapsed')) {
if (sub.is(':visible')) {
sub.slideUp(200, function () {
parent.removeClass('nav-active');
$('.main-content').css({
height: ''
});
mainContentHeightAdjust();
});
} else {
visibleSubMenuClose();
parent.addClass('nav-active');
sub.slideDown(200, function () {
mainContentHeightAdjust();
});
}
}
return false;
});
function visibleSubMenuClose() {
$('.menu-list').each(function () {
var t = $(this);
if (t.hasClass('nav-active')) {
t.find('> ul').slideUp(200, function () {
t.removeClass('nav-active');
});
}
});
}
function mainContentHeightAdjust() {
// Adjust main content height
var docHeight = $(document).height();
if (docHeight > $('.main-content').height()) $('.main-content').height(docHeight);
}
// class add mouse hover
$('.custom-nav > li').hover(function () {
$(this).addClass('nav-hover');
}, function () {
$(this).removeClass('nav-hover');
});
// Menu Toggle
$('.toggle-btn').click(function () {
$(".left-side").getNiceScroll().hide();
if ($('body').hasClass('left-side-collapsed')) {
$(".left-side").getNiceScroll().hide();
}
var body = $('body');
var bodyposition = body.css('position');
if (bodyposition != 'relative') {
if (!body.hasClass('left-side-collapsed')) {
body.addClass('left-side-collapsed');
$('.custom-nav ul').attr('style', '');
$(this).addClass('menu-collapsed');
} else {
body.removeClass('left-side-collapsed chat-view');
$('.custom-nav li.active ul').css({
display: 'block'
});
$(this).removeClass('menu-collapsed');
}
} else {
if (body.hasClass('left-side-show')) body.removeClass('left-side-show');
else body.addClass('left-side-show');
mainContentHeightAdjust();
}
});
searchform_reposition();
$(window).resize(function () {
if ($('body').css('position') == 'relative') {
$('body').removeClass('left-side-collapsed');
} else {
$('body').css({
left: '',
marginRight: ''
});
}
searchform_reposition();
});
function searchform_reposition() {
if ($('.searchform').css('position') == 'relative') {
$('.searchform').insertBefore('.left-side-inner .logged-user');
} else {
$('.searchform').insertBefore('.menu-right');
}
}
// panel collapsible
$('.panel .tools .fa').click(function () {
var el = $(this).parents(".panel").children(".panel-body");
if ($(this).hasClass("fa-chevron-down")) {
$(this).removeClass("fa-chevron-down").addClass("fa-chevron-up");
el.slideUp(200);
} else {
$(this).removeClass("fa-chevron-up").addClass("fa-chevron-down");
el.slideDown(200);
}
});
$('.todo-check label').click(function () {
$(this).parents('li').children('.todo-title').toggleClass('line-through');
});
$(document).on('click', '.todo-remove', function () {
$(this).closest("li").remove();
return false;
});
//jquery ui se necesita
//$("#sortable-todo").sortable();
// panel close
$('.panel .tools .fa-times').click(function () {
$(this).parents(".panel").parent().remove();
});
// tool tips
$('.tooltips').tooltip();
// popovers
$('.popovers').popover();
}(jQuery));