Author: jaimesuez
Date: 2010-04-13 18:03:48 +0200 (Tue, 13 Apr 2010)
New Revision: 29118
Added:
plugins/sfRutPlugin/LICENSE
plugins/sfRutPlugin/README
plugins/sfRutPlugin/lib/
plugins/sfRutPlugin/lib/validator/
plugins/sfRutPlugin/lib/validator/sfValidatorRut.class.php
plugins/sfRutPlugin/lib/widget/
plugins/sfRutPlugin/lib/widget/sfWidgetFormRut.class.php
plugins/sfRutPlugin/package.xml
plugins/sfRutPlugin/web/
plugins/sfRutPlugin/web/._.DS_Store
plugins/sfRutPlugin/web/js/
plugins/sfRutPlugin/web/js/._jquery.Rut.js
plugins/sfRutPlugin/web/js/jquery.Rut.js
plugins/sfRutPlugin/web/js/jquery.Rut.min.js
Log:
initial import
Added: plugins/sfRutPlugin/LICENSE
===================================================================
--- plugins/sfRutPlugin/LICENSE (rev 0)
+++ plugins/sfRutPlugin/LICENSE 2010-04-13 16:03:48 UTC (rev 29118)
@@ -0,0 +1,5 @@
+Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Added: plugins/sfRutPlugin/README
===================================================================
--- plugins/sfRutPlugin/README (rev 0)
+++ plugins/sfRutPlugin/README 2010-04-13 16:03:48 UTC (rev 29118)
@@ -0,0 +1,12 @@
+sfDoctrineAjaxFormPlugin
+========================
+
+The `sfDoctrineAjaxFormPlugin` is a symfony plugin for Diem CMS for
relationships with
+embedded forms using Ajax.
+
+TODO
+----
+
+ * documentation
+ * many to many relationship
+ * make it work with symfony and not only with Diem
Added: plugins/sfRutPlugin/lib/validator/sfValidatorRut.class.php
===================================================================
--- plugins/sfRutPlugin/lib/validator/sfValidatorRut.class.php
(rev 0)
+++ plugins/sfRutPlugin/lib/validator/sfValidatorRut.class.php 2010-04-13
16:03:48 UTC (rev 29118)
@@ -0,0 +1,53 @@
+<?php
+
+/* Copyright (c) 2008 José Joaquín Núñez ([email protected])
http://joaquinnunez.cl
+ * Licensed under GPL (http://www.opensource.org/licenses/gpl-2.0.php)
+ * Use only for non-commercial usage.
+ *
+ * Version : 0.1
+*/
+class sfValidatorRut extends sfValidatorBase
+{
+
+ protected function configure($options = array(), $messages = array())
+ {
+ $this->setMessage('invalid', 'El rut ingresado es inválido');
+ }
+
+ protected function doClean($values)
+ {
+ $r = strtoupper(str_replace(array(".", "-"), "", $values));
+ $sub_rut = substr($r, 0, strlen($r) - 1);
+ $sub_dv = substr($r, - 1);
+ $x = 2;
+ $s = 0;
+ for ($i = strlen($sub_rut) - 1;$i >= 0;$i--)
+ {
+ if ($x > 7)
+ {
+ $x = 2;
+ }
+ $s += $sub_rut[$i] * $x;
+ $x++;
+ }
+ $dv = 11 - ($s % 11);
+ if ($dv == 10)
+ {
+ $dv = 'K';
+ }
+ if ($dv == 11)
+ {
+ $dv = '0';
+ }
+ if ($dv == $sub_dv)
+ {
+ return $values;
+ }
+ else
+ {
+ throw new sfValidatorError($this, 'invalid', array('values' => $values));
+ }
+ }
+}
+
+
Property changes on: plugins/sfRutPlugin/lib/validator/sfValidatorRut.class.php
___________________________________________________________________
Added: svn:executable
+
Added: plugins/sfRutPlugin/lib/widget/sfWidgetFormRut.class.php
===================================================================
--- plugins/sfRutPlugin/lib/widget/sfWidgetFormRut.class.php
(rev 0)
+++ plugins/sfRutPlugin/lib/widget/sfWidgetFormRut.class.php 2010-04-13
16:03:48 UTC (rev 29118)
@@ -0,0 +1,43 @@
+<?php
+
+/*
+ * This file is part of the symfony package.
+ * (c) Fabien Potencier <[email protected]>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+*/
+/**
+ * sfWidgetFormoctrineJQueryAutocompleter represents an autocompleter input
widget rendered by JQuery
+ * optimized for foreign key lookup.
+ *
+ * @package symfony
+ * @subpackage widget
+ * @author Fabien Potencier <[email protected]>
+ * @version SVN: $Id: sfWidgetFormPropelJQueryAutocompleter.class.php 12130
2008-10-10 14:51:07Z fabien $
+ */
+class sfWidgetFormRut extends sfWidgetFormInput
+{
+
+ public function render($name, $value = null, $attributes = array(), $errors
= array())
+ {
+ dm::getResponse()->addJavascript('/sfRutPlugin/js/jquery.Rut.min.js');
+
+ return $this->renderTag('input', array_merge(array('type' =>
$this->getOption('type'), 'name' => $name, 'value' => $value, "class" =>
"rut_input"), $attributes)) .
+
+<<<EOHTML
+<script type="text/javascript">
+ $(window).load(function(){
+ $("#{$this->generateId($name)}").Rut({
+ on_error: function(){
+ alert('Rut incorrecto');
+ // $("#{$this->generateId($name)}").select();
+ },
+ format_on: 'blur'
+ });
+ $('#{$this->generateId($name)}').trigger('blur');
+ });
+</script>
+EOHTML;
+ }
+}
Property changes on: plugins/sfRutPlugin/lib/widget/sfWidgetFormRut.class.php
___________________________________________________________________
Added: svn:executable
+
Added: plugins/sfRutPlugin/package.xml
===================================================================
--- plugins/sfRutPlugin/package.xml (rev 0)
+++ plugins/sfRutPlugin/package.xml 2010-04-13 16:03:48 UTC (rev 29118)
@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<package packagerversion="1.9.0" version="2.0"
xmlns="http://pear.php.net/dtd/package-2.0"
xmlns:tasks="http://pear.php.net/dtd/tasks-1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0
+ http://pear.php.net/dtd/tasks-1.0.xsd
+ http://pear.php.net/dtd/package-2.0
+ http://pear.php.net/dtd/package-2.0.xsd">
+ <name>sfRutPlugin</name>
+ <uri>.</uri>
+ <summary>Validator and Widget with Jquery for Rut in Chile</summary>
+ <description>Validator and Widget with Jquery for Rut in Chile</description>
+ <lead>
+ <name>Jaime Suez</name>
+ <user>jaimesuez</user>
+ <email>[email protected]</email>
+ <active>yes</active>
+ </lead>
+ <date>2010-04-13</date>
+ <time>11:46:29</time>
+ <version>
+ <release>1</release>
+ <api>1</api>
+ </version>
+ <stability>
+ <release>stable</release>
+ <api>stable</api>
+ </stability>
+ <license
uri="http://www.opensource.org/licenses/mit-license.html">MIT</license>
+ <notes>
+initial
+ </notes>
+ <contents>
+ <dir baseinstalldir="." name="/">
+ <file baseinstalldir="." md5sum="4ac65954019641ddaacd9aca42b15804"
name="lib/validator/sfValidatorRut.class.php" role="php" />
+ <file baseinstalldir="." md5sum="51809cbdd8d5aeb0b4e7754ba63d3ed5"
name="lib/widget/sfWidgetFormRut.class.php" role="php" />
+ <file baseinstalldir="." md5sum="9f0068c287cd48092cce3a60ab4e3700"
name="web/js/jquery.Rut.js" role="data" />
+ <file baseinstalldir="." md5sum="207f2ad4bb0e76eadb38835614e4be06"
name="web/js/jquery.Rut.min.js" role="data" />
+ <file baseinstalldir="." md5sum="1352be76f50e3f0d18a3ca0b3ddd6665"
name="LICENSE" role="data"/>
+ <file baseinstalldir="." md5sum="41266c0910f343c50df2095fa58a1d09"
name="README" role="data"/>
+ </dir>
+ </contents>
+ <dependencies>
+ <required>
+ <php>
+ <min>5</min>
+ </php>
+ <pearinstaller>
+ <min>1.4.0</min>
+ </pearinstaller>
+ <package>
+ <name>symfony</name>
+ <channel>pear.symfony-project.com</channel>
+ <min>1.2.0</min>
+ <max>1.5.0</max>
+ <exclude>1.5.0</exclude>
+ </package>
+ </required>
+ </dependencies>
+ <phprelease />
+ <changelog>
+ <release>
+ <version>
+ <release>1</release>
+ <api>1</api>
+ </version>
+ <stability>
+ <release>stable</release>
+ <api>stable</api>
+ </stability>
+ <date>2010-04-13</date>
+ <license
uri="http://www.opensource.org/licenses/mit-license.html">MIT</license>
+ <notes>
+initial
+ </notes>
+ </release>
+ </changelog>
+</package>
Added: plugins/sfRutPlugin/web/._.DS_Store
===================================================================
(Binary files differ)
Property changes on: plugins/sfRutPlugin/web/._.DS_Store
___________________________________________________________________
Added: svn:executable
+
Added: svn:mime-type
+ application/octet-stream
Added: plugins/sfRutPlugin/web/js/._jquery.Rut.js
===================================================================
(Binary files differ)
Property changes on: plugins/sfRutPlugin/web/js/._jquery.Rut.js
___________________________________________________________________
Added: svn:executable
+
Added: svn:mime-type
+ application/octet-stream
Added: plugins/sfRutPlugin/web/js/jquery.Rut.js
===================================================================
--- plugins/sfRutPlugin/web/js/jquery.Rut.js (rev 0)
+++ plugins/sfRutPlugin/web/js/jquery.Rut.js 2010-04-13 16:03:48 UTC (rev
29118)
@@ -0,0 +1,252 @@
+/* Copyright (c) 2009 Jos� Joaqu�n N��ez ([email protected])
http://joaquinnunez.cl/blog/
+ * Licensed under GPL (http://www.opensource.org/licenses/gpl-2.0.php)
+ * Use only for non-commercial usage.
+ *
+ * Version : 0.5
+ *
+ * Requires: jQuery 1.2+
+ */
+
+(function($)
+{
+ jQuery.fn.Rut = function(options)
+ {
+ var defaults = {
+ digito_verificador: null,
+ on_error: function(){},
+ on_success: function(){},
+ validation: true,
+ format: true,
+ format_on: 'change'
+ };
+
+ var opts = $.extend(defaults, options);
+
+ this.each(function(){
+
+ if(defaults.format)
+ {
+ jQuery(this).bind(defaults.format_on, function(){
+
jQuery(this).val(jQuery.Rut.formatear(jQuery(this).val(),defaults.digito_verificador==null));
+ });
+ }
+ if(defaults.validation)
+ {
+ if(defaults.digito_verificador == null)
+ {
+ jQuery(this).bind('blur', function(){
+ var rut = jQuery(this).val();
+ if(jQuery(this).val() != "" && !jQuery.Rut.validar(rut))
+ {
+ defaults.on_error();
+ }
+ else if(jQuery(this).val() != "")
+ {
+ defaults.on_success();
+ }
+ });
+ }
+ else
+ {
+ var id = jQuery(this).attr("id");
+ jQuery(defaults.digito_verificador).bind('blur', function(){
+ var rut = jQuery("#"+id).val()+"-"+jQuery(this).val();
+ if(jQuery(this).val() != "" && !jQuery.Rut.validar(rut))
+ {
+ defaults.on_error();
+ }
+ else if(jQuery(this).val() != "")
+ {
+ defaults.on_success();
+ }
+ });
+ }
+ }
+ });
+ }
+})(jQuery);
+
+/**
+ Funciones
+*/
+
+
+jQuery.Rut = {
+
+ formatear: function(Rut, digitoVerificador)
+ {
+ var sRut = new String(Rut);
+ var sRutFormateado = '';
+ sRut = jQuery.Rut.quitarFormato(sRut);
+ if(digitoVerificador){
+ var sDV = sRut.charAt(sRut.length-1);
+ sRut = sRut.substring(0, sRut.length-1);
+ }
+ while( sRut.length > 3 )
+ {
+ sRutFormateado = "." + sRut.substr(sRut.length - 3) +
sRutFormateado;
+ sRut = sRut.substring(0, sRut.length - 3);
+ }
+ sRutFormateado = sRut + sRutFormateado;
+ if(sRutFormateado != "" && digitoVerificador)
+ {
+ sRutFormateado += "-"+sDV;
+ }
+ else if(digitoVerificador)
+ {
+ sRutFormateado += sDV;
+ }
+
+ return sRutFormateado;
+ },
+
+ quitarFormato: function(rut)
+ {
+ var strRut = new String(rut);
+ while( strRut.indexOf(".") != -1 )
+ {
+ strRut = strRut.replace(".","");
+ }
+ while( strRut.indexOf("-") != -1 )
+ {
+ strRut = strRut.replace("-","");
+ }
+
+ return strRut;
+ },
+
+ digitoValido: function(dv)
+ {
+ if ( dv != '0' && dv != '1' && dv != '2' && dv != '3' && dv != '4'
+ && dv != '5' && dv != '6' && dv != '7' && dv != '8' && dv != '9'
+ && dv != 'k' && dv != 'K')
+ {
+ return false;
+ }
+ return true;
+ },
+
+ digitoCorrecto: function(crut)
+ {
+ largo = crut.length;
+ if ( largo < 2 )
+ {
+ return false;
+ }
+ if(largo > 2)
+ {
+ rut = crut.substring(0, largo - 1);
+ }
+ else
+ {
+ rut = crut.charAt(0);
+ }
+ dv = crut.charAt(largo-1);
+ jQuery.Rut.digitoValido(dv);
+
+ if(rut == null || dv == null)
+ {
+ return 0;
+ }
+
+ dvr = jQuery.Rut.getDigito(rut);
+
+ if (dvr != dv.toLowerCase())
+ {
+ return false;
+ }
+ return true;
+ },
+
+ getDigito: function(rut)
+ {
+ var dvr = '0';
+ suma = 0;
+ mul = 2;
+ for(i=rut.length -1;i >= 0;i--)
+ {
+ suma = suma + rut.charAt(i) * mul;
+ if (mul == 7)
+ {
+ mul = 2;
+ }
+ else
+ {
+ mul++;
+ }
+ }
+ res = suma % 11;
+ if (res==1)
+ {
+ return 'k';
+ }
+ else if(res==0)
+ {
+ return '0';
+ }
+ else
+ {
+ return 11-res;
+ }
+ },
+
+ validar: function(texto)
+ {
+ texto = jQuery.Rut.quitarFormato(texto);
+ largo = texto.length;
+
+ // rut muy corto
+ if ( largo < 2 )
+ {
+ return false;
+ }
+
+ // verifica que los numeros correspondan a los de rut
+ for (i=0; i < largo ; i++ )
+ {
+ // numero o letra que no corresponda a los del rut
+ if(!jQuery.Rut.digitoValido(texto.charAt(i)))
+ {
+ return false;
+ }
+ }
+
+ var invertido = "";
+ for(i=(largo-1),j=0; i>=0; i--,j++)
+ {
+ invertido = invertido + texto.charAt(i);
+ }
+ var dtexto = "";
+ dtexto = dtexto + invertido.charAt(0);
+ dtexto = dtexto + '-';
+ cnt = 0;
+
+ for ( i=1,j=2; i<largo; i++,j++ )
+ {
+ if ( cnt == 3 )
+ {
+ dtexto = dtexto + '.';
+ j++;
+ dtexto = dtexto + invertido.charAt(i);
+ cnt = 1;
+ }
+ else
+ {
+ dtexto = dtexto + invertido.charAt(i);
+ cnt++;
+ }
+ }
+
+ invertido = "";
+ for (i=(dtexto.length-1),j=0; i>=0; i--,j++)
+ {
+ invertido = invertido + dtexto.charAt(i);
+ }
+
+ if (jQuery.Rut.digitoCorrecto(texto))
+ {
+ return true;
+ }
+ return false;
+ }
+};
Property changes on: plugins/sfRutPlugin/web/js/jquery.Rut.js
___________________________________________________________________
Added: svn:executable
+
Added: plugins/sfRutPlugin/web/js/jquery.Rut.min.js
===================================================================
--- plugins/sfRutPlugin/web/js/jquery.Rut.min.js
(rev 0)
+++ plugins/sfRutPlugin/web/js/jquery.Rut.min.js 2010-04-13 16:03:48 UTC
(rev 29118)
@@ -0,0 +1,6 @@
+(function($){jQuery.fn.Rut=function(options){var
defaults={digito_verificador:null,on_error:function(){},on_success:function(){},validation:true,format:true,format_on:'change'};var
opts=$.extend(defaults,options);this.each(function(){if(defaults.format){jQuery(this).bind(defaults.format_on,function(){jQuery(this).val(jQuery.Rut.formatear(jQuery(this).val(),defaults.digito_verificador==null));});}if(defaults.validation){if(defaults.digito_verificador==null){jQuery(this).bind('blur',function(){var
rut=jQuery(this).val();if(jQuery(this).val()!=""&&!jQuery.Rut.validar(rut)){defaults.on_error();}else
if(jQuery(this).val()!=""){defaults.on_success();}});}else
+{var
id=jQuery(this).attr("id");jQuery(defaults.digito_verificador).bind('blur',function(){var
rut=jQuery("#"+id).val()+"-"+jQuery(this).val();if(jQuery(this).val()!=""&&!jQuery.Rut.validar(rut)){defaults.on_error();}else
if(jQuery(this).val()!=""){defaults.on_success();}});}}});}})(jQuery);jQuery.Rut={formatear:function(Rut,digitoVerificador){var
sRut=new String(Rut);var
sRutFormateado='';sRut=jQuery.Rut.quitarFormato(sRut);if(digitoVerificador){var
sDV=sRut.charAt(sRut.length-1);sRut=sRut.substring(0,sRut.length-1);}while(sRut.length>3){sRutFormateado="."+sRut.substr(sRut.length-3)+sRutFormateado;sRut=sRut.substring(0,sRut.length-3);}sRutFormateado=sRut+sRutFormateado;if(sRutFormateado!=""&&digitoVerificador){sRutFormateado+="-"+sDV;}else
if(digitoVerificador){sRutFormateado+=sDV;}return
sRutFormateado;},quitarFormato:function(rut){var strRut=new
String(rut);while(strRut.indexOf(".")!=-1){strRut=strRut.replace(".","");}while(strRut.indexOf("-")!=-1){strRut=strRut.replace("-","");}return
strRut;},digitoValido:function(dv){if(dv!='0'&&dv!='1'&&dv!='2'&&dv!='3'&&dv!='4'&&dv!='5'&&dv!='6'&&dv!='7'&&dv!='8'&&dv!='9'&&dv!='k'&&dv!='K'){return
false;}return
true;},digitoCorrecto:function(crut){largo=crut.length;if(largo<2){return
false;}if(largo>2){rut=crut.substring(0,largo-1);}else
+{rut=crut.charAt(0);}dv=crut.charAt(largo-1);jQuery.Rut.digitoValido(dv);if(rut==null||dv==null){return
0;}dvr=jQuery.Rut.getDigito(rut);if(dvr!=dv.toLowerCase()){return
false;}return true;},getDigito:function(rut){var
dvr='0';suma=0;mul=2;for(i=rut.length-1;i>=0;i--){suma=suma+rut.charAt(i)*mul;if(mul==7){mul=2;}else
+{mul++;}}res=suma%11;if(res==1){return'k';}else if(res==0){return'0';}else
+{return
11-res;}},validar:function(texto){texto=jQuery.Rut.quitarFormato(texto);largo=texto.length;if(largo<2){return
false;}for(i=0;i<largo;i++){if(!jQuery.Rut.digitoValido(texto.charAt(i))){return
false;}}var
invertido="";for(i=(largo-1),j=0;i>=0;i--,j++){invertido=invertido+texto.charAt(i);}var
dtexto="";dtexto=dtexto+invertido.charAt(0);dtexto=dtexto+'-';cnt=0;for(i=1,j=2;i<largo;i++,j++){if(cnt==3){dtexto=dtexto+'.';j++;dtexto=dtexto+invertido.charAt(i);cnt=1;}else
+{dtexto=dtexto+invertido.charAt(i);cnt++;}}invertido="";for(i=(dtexto.length-1),j=0;i>=0;i--,j++){invertido=invertido+dtexto.charAt(i);}if(jQuery.Rut.digitoCorrecto(texto)){return
true;}return false;}};
\ No newline at end of file
Property changes on: plugins/sfRutPlugin/web/js/jquery.Rut.min.js
___________________________________________________________________
Added: svn:executable
+
--
You received this message because you are subscribed to the Google Groups
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/symfony-svn?hl=en.