示例#1
0
 /**
  * Método que utiliza los atributos de un input o form para aplicar parámetros por defecto
  * @param type $attrs
  * @param type $type
  * @return string
  */
 protected static function _getAttrsClass($attrs, $type)
 {
     if ($type == 'form' or $type == 'form-multipart') {
         $formAjax = APP_AJAX && Session::get('app_ajax') ? TRUE : FALSE;
         if (isset($attrs['class'])) {
             if (preg_match("/\\bno-ajax\\b/i", $attrs['class'])) {
                 $formAjax = false;
             }
             //Verifico si está definida la clase mkc-form
             if (!preg_match("/\\bmkc-form\\b/i", $attrs['class'])) {
                 $attrs['class'] = 'mkc-form ' . $attrs['class'];
             }
             //Verifico si está definida la clase para ajax, pero si no se encuentra el aplicativo para ajax
             if (preg_match("/\\bjs-remote\\b/i", $attrs['class']) && !$formAjax) {
                 $formAjax = TRUE;
             }
             //Verifico si el aplicativo está con ajax
             if ($formAjax) {
                 //Verifico si está definida la clase para ajax
                 if (!preg_match("/\\bjs-remote\\b/i", $attrs['class'])) {
                     $attrs['class'] = 'js-remote ' . $attrs['class'];
                 }
                 if (!preg_match("/\\bmkc-no-validate\\b/i", $attrs['class'])) {
                     $attrs['class'] = 'mkc-validate ' . $attrs['class'];
                 }
             }
         } else {
             //Asigno que pertenece a la clase mkc-form y si utiliza ajax
             $attrs['class'] = $formAjax ? 'mkc-form mkc-validate js-remote' : 'mkc-form';
         }
         if ($formAjax && !isset($attrs['data-to'])) {
             //Si es un form con ajax verifico si está definido el data-div
             $attrs['data-to'] = 'mkc-shell-content';
         }
         if (!isset($attrs['id'])) {
             //Verifico si está definido el id
             $attrs['id'] = 'form-' . self::$_form;
         }
         if (!isset($attrs['name'])) {
             //Verifico si está definido el name
             $attrs['name'] = $attrs['id'];
         }
         self::$_style = isset($attrs['style-form']) ? $attrs['style-form'] : 'form-vertical';
         self::$_show_label = (self::$_style == 'form-search' or self::$_style == 'form-inline') ? false : true;
         self::$_help_block = self::$_style == 'form-search' ? false : true;
         self::$_name['id'] = $attrs['id'];
         self::$_name['name'] = $attrs['name'];
         //asigno el estilo al formulario
         $attrs['class'] = $attrs['class'] . ' ' . self::$_style;
         self::$_form++;
     } else {
         if (isset($attrs['class'])) {
             //Verifico las clases segun el tipo text, select, textarea, file, numeric, date
             if (!preg_match("/\\b{$type}\\b/i", $attrs['class'])) {
                 $attrs['class'] = $type . ' ' . $attrs['class'];
             }
             //Verifico si está la clase field
             if (!preg_match("/\\bfield\\b/i", $attrs['class'])) {
                 $attrs['class'] = 'field ' . $attrs['class'];
             }
             //Verifico si el campo es moneda
             if (preg_match("/\\binput-money\\b/i", $attrs['class'])) {
                 //@see var.js
                 $attrs['onkeyup'] = 'jsMiles(this,this.value.charAt(this.value.length-1))';
             }
         } else {
             //Si no está definida las clases las asigno según el tipo
             $attrs['class'] = $type != 'checkbox' && $type != 'radio' ? "field {$type} input-full " : "field {$type} ";
         }
         //Verifico si se utiliza la mayúscula solo para los text y textarea
         if ($type == 'text' && $type == 'textarea') {
             if (!preg_match("/\\binput-lower\\b/i", $attrs['class']) or preg_match("/\\binput-upper\\b/i", $attrs['class'])) {
                 $attrs['onchange'] = !isset($attrs['onchange']) ? 'this.value=this.value.toUpperCase()' : rtrim($attrs['onchange'], ';') . '; this.value=this.value.toUpperCase()';
             }
         }
         //Reviso si es readonly
         if (preg_match("/\\breadonly\\b/i", $attrs['class'])) {
             $attrs['readonly'] = 'readonly';
         }
         //Reviso si esta deshabilitado
         if (preg_match("/\\bdisabled\\b/i", $attrs['class'])) {
             $attrs['disabled'] = 'disabled';
         }
         //Verifico si es requerido
         if (preg_match("/\\binput-required\\b/i", $attrs['class'])) {
             $attrs['required'] = 'required';
         }
         //Verifico el data-action del input (cuando utiliza ajax)
         if (isset($attrs['data-action'])) {
             $attrs['data-action'] = PUBLIC_PATH . trim($attrs['data-action'], '/') . '/';
         }
     }
     return $attrs;
 }