1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* KumbiaPHP web & app Framework |
4
|
|
|
* |
5
|
|
|
* LICENSE |
6
|
|
|
* |
7
|
|
|
* This source file is subject to the new BSD license that is bundled |
8
|
|
|
* with this package in the file LICENSE.txt. |
9
|
|
|
* It is also available through the world-wide-web at this URL: |
10
|
|
|
* http://wiki.kumbiaphp.com/Licencia |
11
|
|
|
* If you did not receive a copy of the license and are unable to |
12
|
|
|
* obtain it through the world-wide-web, please send an email |
13
|
|
|
* to [email protected] so we can send you a copy immediately. |
14
|
|
|
* |
15
|
|
|
* @category KumbiaPHP |
16
|
|
|
* @package Helpers |
17
|
|
|
* @copyright Copyright (c) 2005 - 2016 KumbiaPHP Team (http://www.kumbiaphp.com) |
18
|
|
|
* @license http://wiki.kumbiaphp.com/Licencia New BSD License |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Helper que utiliza Javascript |
23
|
|
|
* |
24
|
|
|
* @category KumbiaPHP |
25
|
|
|
* @package Helpers |
26
|
|
|
*/ |
27
|
|
|
class Js |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* Javascripts que son requisito de otros |
31
|
|
|
* |
32
|
|
|
* @var array |
33
|
|
|
* */ |
34
|
|
|
protected static $_dependencies = array(); |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Javascript |
38
|
|
|
* |
39
|
|
|
* @var array |
40
|
|
|
* */ |
41
|
|
|
protected static $_js = array(); |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Directorio Javascript |
45
|
|
|
* |
46
|
|
|
* @var array |
47
|
|
|
* */ |
48
|
|
|
protected static $js_dir = 'javascript/'; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Crea un enlace en una Aplicacion con mensaje de confirmacion respetando |
52
|
|
|
* las convenciones de Kumbia |
53
|
|
|
* |
54
|
|
|
* @param string $action ruta a la accion |
55
|
|
|
* @param string $text texto a mostrar |
56
|
|
|
* @param string $confirm mensaje de confirmacion |
57
|
|
|
* @param string $class clases adicionales para el link |
58
|
|
|
* @param string|array $attrs atributos adicionales |
59
|
|
|
* @return string |
60
|
|
|
*/ |
61
|
|
|
public static function link($action, $text, $confirm = '¿Está Seguro?', $class = '', $attrs = '') |
62
|
|
|
{ |
63
|
|
|
$attrs = Tag::getAttrs($attrs); |
64
|
|
|
return '<a href="' . PUBLIC_PATH . "$action\" data-msg=\"$confirm\" class=\"js-confirm $class\" $attrs>$text</a>"; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Crea un enlace a una accion con mensaje de confirmacion respetando |
69
|
|
|
* las convenciones de Kumbia |
70
|
|
|
* |
71
|
|
|
* @param string $action accion |
72
|
|
|
* @param string $text texto a mostrar |
73
|
|
|
* @param string $confirm mensaje de confirmacion |
74
|
|
|
* @param string $class clases adicionales para el link |
75
|
|
|
* @param string|array $attrs atributos adicionales |
76
|
|
|
* @return string |
77
|
|
|
*/ |
78
|
|
|
public static function linkAction($action, $text, $confirm = '¿Está Seguro?', $class = '', $attrs = '') |
79
|
|
|
{ |
80
|
|
|
$attrs = Tag::getAttrs($attrs); |
81
|
|
|
return '<a href="' . PUBLIC_PATH . Router::get('controller_path') . "/$action\" data-msg=\"$confirm\" class=\"js-confirm $class\" $attrs>$text</a>"; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Crea un boton submit con mensaje de confirmacion respetando |
86
|
|
|
* las convenciones de Kumbia |
87
|
|
|
* |
88
|
|
|
* @param string $text texto a mostrar |
89
|
|
|
* @param string $confirm mensaje de confirmacion |
90
|
|
|
* @param string $class clases adicionales para el link |
91
|
|
|
* @param string|array $attrs atributos adicionales |
92
|
|
|
* @return string |
93
|
|
|
*/ |
94
|
|
|
public static function submit($text, $confirm = '¿Está Seguro?', $class = '', $attrs = '') |
95
|
|
|
{ |
96
|
|
|
$attrs = Tag::getAttrs($attrs); |
97
|
|
|
return "<input type=\"submit\" value=\"$text\" data-msg=\"$confirm\" class=\"js-confirm $class\" $attrs/>"; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Crea un boton de tipo imagen |
102
|
|
|
* |
103
|
|
|
* @param string $img |
104
|
|
|
* @param string $class clases adicionales para el link |
105
|
|
|
* @param string|array $attrs atributos adicionales |
106
|
|
|
* @return string |
107
|
|
|
*/ |
108
|
|
|
public static function submitImage($img, $confirm = '¿Está Seguro?', $class = '', $attrs = '') |
109
|
|
|
{ |
110
|
|
|
$attrs = Tag::getAttrs($attrs); |
111
|
|
|
return "<input type=\"image\" data-msg=\"$confirm\" src=\"" . PUBLIC_PATH . "img/$img\" class=\"js-confirm $class\" $attrs/>"; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Añade un archivo Javascript para ser incluido en el template |
116
|
|
|
* |
117
|
|
|
* @param string $file nombre del archivo a añadir |
118
|
|
|
* @param array $dependencies archivos que son requisito del archivo a añadir |
119
|
|
|
*/ |
120
|
|
|
public static function add( $file, $dependencies=array() ) |
121
|
|
|
{ |
122
|
|
|
self::$_js[$file] = $file; |
123
|
|
|
foreach ($dependencies as $file) self::$_dependencies[$file] = $file; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Incluye todos los archivo Javascript en el template añadidos con el metodo add |
128
|
|
|
* |
129
|
|
|
* @return string |
130
|
|
|
*/ |
131
|
|
|
public static function inc() |
132
|
|
|
{ |
133
|
|
|
$js = self::$_dependencies + self::$_js; |
134
|
|
|
$html = ''; |
135
|
|
|
foreach ($js as $file) |
136
|
|
|
{ |
137
|
|
|
$a = strstr($file, '?') ? explode('?', $file, 2) : array($file, ''); |
138
|
|
|
$q = ($a[1]) ? "?$a[1]" : ''; |
139
|
|
|
$html .= '<script type="text/javascript" src="' . PUBLIC_PATH . self::$js_dir . "$a[0].js$q" . '"></script>'; |
140
|
|
|
} |
141
|
|
|
return $html; |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
|