Skip to content
This repository has been archived by the owner on Jul 5, 2022. It is now read-only.

Commit

Permalink
Merge pull request #15 from konecta/develop
Browse files Browse the repository at this point in the history
Develop v0.2.3
  • Loading branch information
sirnapa committed Jun 29, 2015
2 parents cf8b2ca + 69e57a0 commit ae25ed2
Show file tree
Hide file tree
Showing 19 changed files with 1,282 additions and 1,052 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kui",
"version": "0.2.2",
"version": "0.2.3",
"dependencies": {
"jquery": "~2.1.4",
"bootstrap": "~3.3.2",
Expand Down
180 changes: 105 additions & 75 deletions dist/jquery.kui.core.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! kui - v0.2.2 - 2015-06-02
/*! kui - v0.2.3 - 2015-06-29
* https://github.com/konecta/kui
* Copyright (c) 2015 Nelson Paez; Licensed MIT */
(function ($) {
Expand Down Expand Up @@ -159,33 +159,35 @@
},
async: false
});
}else if(typeof field.opciones.origen === 'function'){
opciones = field.opciones.origen.call(this,item);
}else{
opciones = field.opciones.origen;
}

var seleccionado = false;

$.each(opciones,function(o,opcion){
var item = $('<option>');
var $opcion = $('<option>');
var id = '';

if(stringOnly){
id = opcion.toString();
item.html(opcion).attr('value',opcion);
$opcion.html(opcion).attr('value',opcion);
}else{
id = opcion[field.opciones.id];
item.attr('value',id)
$opcion.attr('value',id)
.html(
typeof field.opciones.formato==='function'?
field.opciones.formato.call(this,opcion)
: opcion[field.opciones.formato]
);
}

item.appendTo(select);
$opcion.appendTo(select);

if( inputVal && inputVal.toString() === id){
item.attr('selected',true);
$opcion.attr('selected',true);
seleccionado = true;
}
});
Expand All @@ -205,20 +207,20 @@
var confDateTime = {
'fecha': {
icono: 'calendar',
formato: 'dd/MM/yyyy',
formato: $.kui.i18n.dateFormat,
rule: 'date',
constructor: {pickTime: false}
},
'hora': {
icono: 'clock-o',
formato: 'hh:mm:ss',
formato: $.kui.i18n.hourFormat,
rule: 'hour',
constructor: {pickDate: false}
},
'fecha-hora': {
icono: 'calendar-o',
rule: 'datetime',
formato: 'dd/MM/yyyy hh:mm:ss'
formato: $.kui.i18n.datetimeFormat
}
};

Expand Down Expand Up @@ -322,40 +324,40 @@

},

validar: {

reglas: function(){

// Validaciones extras para el formulario

$.validator.methods["date"] = function(value, element) {
var check = false;
var re_con_barras = /^\d{1,2}\/\d{1,2}\/\d{4}$/;
var re_con_guiones = /^\d{1,2}-\d{1,2}-\d{4}$/;
var es_fecha = function(separador){
var adata = value.split(separador);
var gg = parseInt(adata[0],10);
var mm = parseInt(adata[1],10);
var aaaa = parseInt(adata[2],10);
var xdata = new Date(aaaa,mm-1,gg);
if ( ( xdata.getFullYear() === aaaa ) &&
( xdata.getMonth () === mm - 1 ) &&
( xdata.getDate() === gg ) ){
check = true;
} else{
check = false;
}
};

if(re_con_barras.test(value)){
es_fecha('/');
} else if(re_con_guiones.test(value)){
es_fecha('-');
} else{
check = false;
}
return this.optional(element) || check;
};
validate: {

hasRules: false,

rules: function(){

if($.kui.form.validate.hasRules){
return;
}

// var isDate = function(value,separator,iso){
// var check = false;
// var adata = value.split(separator);
// var gg = parseInt(adata[iso? 2 : 0],10);
// var mm = parseInt(adata[1],10);
// var aaaa = parseInt(adata[iso? 0 : 2],10);
// var xdata = new Date(aaaa,mm-1,gg);
// if ( ( xdata.getFullYear() === aaaa ) &&
// ( xdata.getMonth () === mm - 1 ) &&
// ( xdata.getDate() === gg ) ){
// check = true;
// } else{
// check = false;
// }
// return check;
// };

$.validator.methods["date"] = function(value, element) {
var picker = $(element).parent().data('datetimepicker');
var date = picker.getDate();
return this.optional(element) || date !== undefined;
};

$.kui.form.validate.hasRules = true;

},

Expand All @@ -380,28 +382,29 @@
});
},

fecha: function(form){
$(form).find('input[data-rule-date=true]').each(function(i,input){
var fechaVal = $(input).val();
var fechaArray;
var fechaFormato = {
dd: 0,
MM: 1,
yyyy: 2
};
if (fechaVal.indexOf('/') > 0){
fechaArray = fechaVal.split('/');
} else {
fechaArray = fechaVal.split('-');
fechaFormato.yyyy = 0;
fechaFormato.dd = 2;
}
$(input).val(
(fechaArray.length===3)?
(fechaArray[fechaFormato.yyyy] +'-' + fechaArray[fechaFormato.MM] + '-' + fechaArray[fechaFormato.dd])
: ''
);
});
add: function(o){
$(o.form).validate({
showErrors: function(errorMap, errorList) {
$.kui.form.validate.error(this, errorMap, errorList);
},
submitHandler: function(form) {

$(form).find('input[data-rule-date=true]').each(function(i,input){
var picker = $(input).parent().data('datetimepicker');
var date = picker.getDate();
var dateIso = '';
if(date){
var month = date.getMonth()+1;
if(month<10){}
dateIso = date.getFullYear() + '-' + (month<10? '0' : '') + month + '-' + date.getDate();
}
$(input).val(dateIso);
});

o.submit.call(this,form);
return false;
}
});
}

}
Expand Down Expand Up @@ -443,7 +446,7 @@
ajax: 'ajax',
data: 'data',
titles: 'titulos',
pass: 'permisos',
actions: 'permisos',
sourceFormat: 'retorno',
buttons: 'botones',
pager: 'paginador',
Expand Down Expand Up @@ -474,11 +477,17 @@
/* Campos de Wizard */
steps: 'pasos',
indices: 'indices',
validate: 'validacion'
validate: 'validacion',

/* Date & time format */
dateFormat: 'dd/MM/yyyy',
hourFormat: 'hh:mm:ss',
dateTimeFormat: 'dd/MM/yyyy hh:mm:ss',

};

}(jQuery));

(function ($) {

$.kui.list = {
Expand Down Expand Up @@ -631,13 +640,13 @@
todos:false
};

var finalPass = {};
finalPass[$.kui.i18n.add] = null;
finalPass[$.kui.i18n.edit] = null;
finalPass[$.kui.i18n.save] = null;
finalPass[$.kui.i18n.activate] = null;
finalPass[$.kui.i18n.remove] = null;
finalParams[$.kui.i18n.pass] = finalPass;
var finalActions = {};
finalActions[$.kui.i18n.add] = null;
finalActions[$.kui.i18n.edit] = null;
finalActions[$.kui.i18n.save] = null;
finalActions[$.kui.i18n.activate] = null;
finalActions[$.kui.i18n.remove] = null;
finalParams[$.kui.i18n.actions] = finalActions;

if(o.params[$.kui.i18n.pager]===undefined){
o.params[$.kui.i18n.pager] = $('<div>')
Expand Down Expand Up @@ -686,7 +695,7 @@
showTitles : finalParams[$.kui.i18n.titles],
campos : finalParams[$.kui.i18n.fields],
ajax : finalParams[$.kui.i18n.ajax],
permisos : finalParams[$.kui.i18n.pass],
permisos : finalParams[$.kui.i18n.actions],
botones : finalParams[$.kui.i18n.buttons],
estado : finalParams[$.kui.i18n.state],
//retorno : finalParams[$.kui.i18n.sourceFormat],
Expand Down Expand Up @@ -1002,6 +1011,27 @@
return data[level1]? data[level1][level2] :
(data[level1+'.'+level2]?
data[level1+'.'+level2] : '');
},

dateToIso: function(value){
var date;
var format = {
dd: 0,
MM: 1,
yyyy: 2
};

if (value.indexOf('/') > 0){
date = value.split('/');
} else {
date = value.split('-');
format.yyyy = 0;
format.dd = 2;
}

return (date.length===3)?
(date[format.yyyy] +'-' + date[format.MM] + '-' + date[format.dd])
: '';
}

};
Expand Down
Loading

0 comments on commit ae25ed2

Please sign in to comment.