From 4f13b785ac2f12df5bfed35fce7b1b745becbe4f Mon Sep 17 00:00:00 2001 From: alberto.alvarez Date: Thu, 25 Jun 2020 10:07:46 +0200 Subject: [PATCH] VERSION INICIAL --- AdminInformax.gif | Bin 0 -> 574 bytes ComunesImaxAddCatbyFeature.php | 485 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ FuncionesImaxAddCatbyFeature.php | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ acordeon/acordeon.css | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ acordeon/acordeon.js | 26 ++++++++++++++++++++++++++ acordeon/img/down.png | Bin 0 -> 996 bytes acordeon/img/right.png | Bin 0 -> 767 bytes config.xml | 14 ++++++++++++++ configuration.php | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ controllers/admin/Adminxaddcatbyfeature.php | 16 ++++++++++++++++ css/clock.gif | Bin 0 -> 2017 bytes css/css.css | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ css/custom.css | 7 +++++++ css/down.png | Bin 0 -> 996 bytes css/espera.gif | Bin 0 -> 416 bytes css/estadoLicencia_ausente.png | Bin 0 -> 1750 bytes css/estadoLicencia_correcta.png | Bin 0 -> 2664 bytes css/estadoLicencia_incorrecta.png | Bin 0 -> 2623 bytes css/index.php | 9 +++++++++ css/publi.css | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ css/right.png | Bin 0 -> 767 bytes forms/forms.15.css | 9 +++++++++ forms/forms.css | 5 +++++ forms/forms.js | 7 +++++++ forms/forms_1.css | 5 +++++ forms/forms_1.js | 7 +++++++ forms/jquery.fileupload-image.js | 294 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ forms/jquery.fileupload-image_1.js | 294 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ forms/jquery.fileupload-process.js | 164 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ forms/jquery.fileupload-process_1.js | 164 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ forms/jquery.fileupload-validate.js | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ forms/jquery.fileupload-validate_1.js | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ forms/jquery.fileupload.js | 1368 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ forms/jquery.fileupload_1.js | 1368 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ forms/jquery.iframe-transport.js | 208 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ forms/jquery.iframe-transport_1.js | 208 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ forms/jquery.tagify.js | 139 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ forms/ladda.js | 314 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ forms/ladda_1.js | 314 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ forms/spin.js | 349 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ forms/spin_1.js | 349 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ functionsForm.php | 1521 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ imaxAcordeon.php | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ imaxaddcatbyfeature.php | 394 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ imaxaddcatbyfeature_cron.php | 15 +++++++++++++++ img/abrir-ticket.png | Bin 0 -> 585 bytes img/borrar.png | Bin 0 -> 4649 bytes img/close.png | Bin 0 -> 841 bytes img/help.jpg | Bin 0 -> 7003 bytes img/help.png | Bin 0 -> 801 bytes img/help__.png | Bin 0 -> 7002 bytes img/informax.png | Bin 0 -> 1004 bytes img/ir-a-manuales.png | Bin 0 -> 599 bytes img/manual.jpg | Bin 0 -> 4708 bytes img/manual.png | Bin 0 -> 495 bytes img/manual__.png | Bin 0 -> 4707 bytes img/open.png | Bin 0 -> 881 bytes js/functions.js | 134 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ js/jquery.dynatree.min.js | 4 ++++ logo.gif | Bin 0 -> 1761 bytes logo.jpg | Bin 0 -> 3014 bytes logo.png | Bin 0 -> 3571 bytes skin/digits.png | Bin 0 -> 13406 bytes skin/icons-rtl.gif | Bin 0 -> 4046 bytes skin/icons.gif | Bin 0 -> 4041 bytes skin/loading.gif | Bin 0 -> 570 bytes skin/ui.dynatree.css | 440 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ skin/vline-rtl.gif | Bin 0 -> 842 bytes skin/vline.gif | Bin 0 -> 844 bytes sql-install.php | 19 +++++++++++++++++++ sql-unninstall.php | 4 ++++ 71 files changed, 9300 insertions(+), 0 deletions(-) create mode 100644 AdminInformax.gif create mode 100644 ComunesImaxAddCatbyFeature.php create mode 100644 FuncionesImaxAddCatbyFeature.php create mode 100644 acordeon/acordeon.css create mode 100644 acordeon/acordeon.js create mode 100644 acordeon/img/down.png create mode 100644 acordeon/img/right.png create mode 100644 config.xml create mode 100644 configuration.php create mode 100644 controllers/admin/Adminxaddcatbyfeature.php create mode 100644 css/clock.gif create mode 100644 css/css.css create mode 100644 css/custom.css create mode 100644 css/down.png create mode 100644 css/espera.gif create mode 100644 css/estadoLicencia_ausente.png create mode 100644 css/estadoLicencia_correcta.png create mode 100644 css/estadoLicencia_incorrecta.png create mode 100644 css/index.php create mode 100644 css/publi.css create mode 100644 css/right.png create mode 100644 forms/forms.15.css create mode 100644 forms/forms.css create mode 100644 forms/forms.js create mode 100644 forms/forms_1.css create mode 100644 forms/forms_1.js create mode 100644 forms/jquery.fileupload-image.js create mode 100644 forms/jquery.fileupload-image_1.js create mode 100644 forms/jquery.fileupload-process.js create mode 100644 forms/jquery.fileupload-process_1.js create mode 100644 forms/jquery.fileupload-validate.js create mode 100644 forms/jquery.fileupload-validate_1.js create mode 100644 forms/jquery.fileupload.js create mode 100644 forms/jquery.fileupload_1.js create mode 100644 forms/jquery.iframe-transport.js create mode 100644 forms/jquery.iframe-transport_1.js create mode 100644 forms/jquery.tagify.js create mode 100644 forms/ladda.js create mode 100644 forms/ladda_1.js create mode 100644 forms/spin.js create mode 100644 forms/spin_1.js create mode 100644 functionsForm.php create mode 100644 imaxAcordeon.php create mode 100644 imaxaddcatbyfeature.php create mode 100644 imaxaddcatbyfeature_cron.php create mode 100644 img/abrir-ticket.png create mode 100644 img/borrar.png create mode 100644 img/close.png create mode 100644 img/help.jpg create mode 100644 img/help.png create mode 100644 img/help__.png create mode 100644 img/informax.png create mode 100644 img/ir-a-manuales.png create mode 100644 img/manual.jpg create mode 100644 img/manual.png create mode 100644 img/manual__.png create mode 100644 img/open.png create mode 100644 js/functions.js create mode 100644 js/jquery.dynatree.min.js create mode 100644 logo.gif create mode 100644 logo.jpg create mode 100644 logo.png create mode 100644 skin/digits.png create mode 100644 skin/icons-rtl.gif create mode 100644 skin/icons.gif create mode 100644 skin/loading.gif create mode 100644 skin/ui.dynatree.css create mode 100644 skin/vline-rtl.gif create mode 100644 skin/vline.gif create mode 100644 sql-install.php create mode 100644 sql-unninstall.php diff --git a/AdminInformax.gif b/AdminInformax.gif new file mode 100644 index 0000000..7e4c010 Binary files /dev/null and b/AdminInformax.gif differ diff --git a/ComunesImaxAddCatbyFeature.php b/ComunesImaxAddCatbyFeature.php new file mode 100644 index 0000000..c780052 --- /dev/null +++ b/ComunesImaxAddCatbyFeature.php @@ -0,0 +1,485 @@ +context->controller->addCss($this->_path.'css/'.$css, 'all'); + } + + return; + } + + public function addJS($js) { + $tab = Tools::getValue('tab', 0); + if (!$tab || ($tab && $tab != 'AdminSelfUpgrade')) { + $this->context->controller->addJs($this->_path.'js/'.$js); + } + + return; + } + + public function addJqueryUI($plugin) { + $tab = Tools::getValue('tab', 0); + if (!$tab || ($tab && $tab != 'AdminSelfUpgrade')) { + if ($this->context->controller instanceof stdClass) { + $this->context->controller = new AdminModulesController(); + } + $this->context->controller->addJqueryUI($plugin); + } + return; + } + + public function createHelpHeader() { + $html = '
'; + $html .= $this->getDatosPubli('header'); + $html .= '
'; + + $html .= '
'; + $html .= '
'; + $html .= '

'.$this->displayName.' by Informax

'; + $html .= '

'.$this->l('Version: ').$this->version.'

'; + $html .= '
'; + + $html .= '
'; + $html .= ''; + $html .= '
'; + $html .= '
'; + return $html; + } + + public function getModuleFooter() { + $url = Configuration::getGlobalValue(self::prefijo.'URL_FALDON'); + $html = '
'; + $html .= '
+ + '; + $html .= '

'.$this->l('Si deseas enterarte de todos los cambios en nuestros modulos, nuevos Modulos, como funciona Prestashop, apuntate a nuestras news').'

'; + $html .= '

'; + $html .= ' '; + $html .= ''; + $html .= ''; + $html .= '

'; + $html .= '

'; + $html .= '
'; + $html .= ''; + return $html; + } + + public function getDatosPubli($tipo) { + $datosCompletos = Configuration::getGlobalValue(self::prefijo.'TXT_FILE'); + + $html = ''; + if ($datosCompletos) { + $aperturaA = ''; + $cierreA = ''; + $datosCompletos = @unserialize($datosCompletos); + if (!is_array($datosCompletos)) { + return ''; + } + shuffle($datosCompletos); + foreach ($datosCompletos AS $datoElemento) { + if ($datoElemento[1] == $tipo) { + if (trim($datoElemento[2]) != '') { + $aperturaA .= ''; + $cierreA = ''; + } + if (trim($datoElemento[0]) != '') { + $html = $aperturaA.''.$cierreA; + } + return $html; + } + } + } + return $html; + } + + public function getTxtFiles() { + if (Configuration::getGlobalValue(self::prefijo.'DESCARGA_ARCHIVO') < 10000) { + Configuration::updateGlobalValue(self::prefijo.'DESCARGA_ARCHIVO', Configuration::getGlobalValue(self::prefijo.'DESCARGA_ARCHIVO') + 1); + return false; + } + $url = Configuration::getGlobalValue(self::prefijo.'URL_TXT').'/'.Configuration::getGlobalValue(self::prefijo.'TIPO').'.txt'; + $basedir_active = ini_get('open_basedir'); + $ch = curl_init($url); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); + curl_setopt($ch, CURLOPT_BINARYTRANSFER, TRUE); + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15); + curl_setopt($ch, CURLOPT_TIMEOUT, 15); + if (!$basedir_active) { + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); + } + $datos = curl_exec($ch); + $infoCurl = curl_getinfo($ch); + if (!isset($infoCurl['http_code']) || $infoCurl['http_code'] != 200) { + + return false; + } + Configuration::updateGlobalValue(self::prefijo.'DESCARGA_ARCHIVO', 0); + return Configuration::updateGlobalValue(self::prefijo.'TXT_FILE', $this->readCsv($datos)); + } + + private function readCsv($string) { + $string = trim($string); + $temp = explode("\n", $string); + $respuesta = array(); + foreach ($temp AS $elemento) { + $elementoInterno = array(); + $elementoInterno = explode(";", $elemento); + $respuesta[] = $elementoInterno; + } + return serialize($respuesta); + } + + public function l($msg, $modulo = '') { + if ($modulo == '') { + $modulo = 'traducciones'.strtolower($this->name); + } + + if ($this->versionPS > 17) { + return parent::trans($msg, $modulo); + } + + return parent::l($msg, $modulo); + } + + /** + * Crea un nuevo tab. + * @param string $clase + * @param string $nombre + * @param string $padre + * @return boolean + */ + private function crearTab($clase, $nombre, $padre = '') { + if (!Tab::getIdFromClassName($clase)) { + $tab = new Tab(); + $tab->active = 1; + $tab->class_name = $clase; + $tab->name = array(); + foreach (Language::getLanguages(true) as $lang) { + $tab->name[$lang['id_lang']] = $nombre; + } + if ($padre == '') { + $posicion = 0; + } + else { + $posicion = Tab::getIdFromClassName($padre); + } + $tab->id_parent = intval($posicion); + $tab->module = $this->name; + try { + if (!$tab->add()) { + return false; + } + } + catch (Exception $exc) { + return false; + } + } + + return true; + } + + /** + * Borra un tab. + * @param string $clase + * @return boolean + */ + private function borrarTab($clase) { + $id_tab = (int)Tab::getIdFromClassName($clase); + if ($id_tab) { + $tab = new Tab($id_tab); + try { + if (!$tab->delete()) { + return false; + } + } + catch (Exception $exc) { + return false; + } + } + + return true; + } + + /** + * Instala los tabs del módulo. + * @return boolean + */ + private function installTab() { + include(dirname(__FILE__).'/configuration.php'); + + //Instalamos el root + if (isset($moduleTabRoot) && $moduleTabRoot) { + $this->crearTab($moduleTabRoot['clase'], $moduleTabRoot['name']); + } + + //Instalamos el resto de tabs + if (isset($moduleTabs) && $moduleTabs) { + foreach ($moduleTabs AS $moduleTab) { + $this->borrarTab($moduleTab['clase']); + if (!$this->crearTab($moduleTab['clase'], $moduleTab['name'], $moduleTab['padre'])) { + return false; + } + } + } + + return true; + } + + /** + * Desinstala los tabs del módulo. + * @return boolean + */ + private function uninstallTab() { + include(dirname(__FILE__).'/configuration.php'); + + //Desinstalamos las tabs de este módulo + if (isset($moduleTabs) && $moduleTabs) { + foreach ($moduleTabs AS $moduleTab) { + if (!$this->borrarTab($moduleTab['clase'])) { + return false; + } + } + } + + //Desinstalamos el root si está vacío + if (isset($moduleTabRoot) && $moduleTabRoot) { + $id_tab = (int)Tab::getIdFromClassName($moduleTabRoot['clase']); + if ($id_tab && Tab::getNbTabs($id_tab) == 0) { + if (!$this->borrarTab($moduleTabRoot['clase'])) { + return false; + } + } + } + + return true; + } + + public function checkLicencia($force = 0) { + $data = array(); + $f = Configuration::getGlobalValue(self::prefijo.'F'); + $check = Configuration::getGlobalValue(self::prefijo.'F_CHECK'); + $url = Configuration::getGlobalValue(self::prefijo.'F_SERVER'); + $data['server'] = $this->getDomain(); + $data['modulo'] = $this->name; + $data['action'] = 'checkLicencia'; + $data['licencia'] = Configuration::getGlobalValue(self::prefijo.'LICENCIA'); + if ($check >= 100 || $force == 1) { + $ch = curl_init($url); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15); + curl_setopt($ch, CURLOPT_POSTFIELDS, $data); + $datos = curl_exec($ch); + $datos = json_decode($datos); + $info = curl_getinfo($ch); + if (!$datos || $datos->codError != 0) { + Configuration::updateGlobalValue(self::prefijo.'F', ''); + Configuration::updateGlobalValue(self::prefijo.'F_CHECK', (int)$check + 1); + return false; + } + else { + Configuration::updateGlobalValue(self::prefijo.'F', $datos->msgError); + Configuration::updateGlobalValue(self::prefijo.'F_CHECK', 0); + return true; + } + } + else { + Configuration::updateGlobalValue(self::prefijo.'F_CHECK', (int)$check + 1); + return true; + } + } + + private function getFunction() { + $function = Configuration::getGlobalValue($this->sufijo.'F'); + return $function; + } + + private static function getUrlAdmin() { + $temp = explode('/', $_SERVER['PHP_SELF']); + $dummy = array_pop(($temp)); + $urlAdmin = implode('/', $temp); + if (Configuration::get('PS_SSL_ENABLED') == 1) { + $url = 'https://'; + } + else { + $url = 'http://'; + } + $url .= $_SERVER['SERVER_NAME'].$urlAdmin.'/'; + return $url; + } + + public function getDomain() { + $idShopDefault = Configuration::getGlobalValue('PS_SHOP_DEFAULT'); + $tienda = new Shop($idShopDefault); + if (Validate::isLoadedObject($tienda)) { + if (isset($tienda->domain)) { + return $tienda->domain; + } + } return false; + } + + public function displayWarning($error) { + if ($this->versionPS == 15) { + $output = ' +
+ '.$error.' +
'; + } + else { + $output = '
' + .'

' + .$error. + '

'; + } + return $output; + } + + private function _checkVersion() { + return false; + } + + /** + * Version comun de displayForm. + * @param string[] $tabsArray [$funcion => $nombreTab] + * @param string $extra Para meter incrustado algun js o css. + */ + private function displayFormTrait($tabsArray, $extra = '') { + if (Configuration::getGlobalValue(self::prefijo.'LICENCIA') == '') { + $this->_html .= '
'; + $this->_html .= '
'; + $this->_html .= '

'.$this->l('ATENCION: SU LICENCIA ESTA VACIA').'

'; + $this->_html .= '

'.$this->l('Debe introducir un numero de licencia valido para continuar').'

'; + $this->_html .= '
'; + $this->_html .= '
'; + $this->_html .= $this->_mostrarLicencia(); + $this->forceCheck = 0; + } + elseif (!$this->checkLicencia($this->forceCheck)) { + $this->_html .= '
'; + $this->_html .= '
'; + $this->_html .= '

'.$this->l('ATENCION: SU LICENCIA NO ES VALIDA').'

'; + $this->_html .= '

'.$this->l('Si ejecuta el modulo sin licencia los resultados no seran validos').'

'; + $this->_html .= '

'.$this->l('Haga esto bajo su responsabilidad, Informax no dara soporte ni aceptar quejas o peticiones derivadas del uso sin licencia de nuestros productos').'

'; + $this->_html .= '

'.$this->l('El uso de nuestro software sin licencia constituye una infraccion de las leyes de propiedad intelectual, y sera puesta en conocimiento de las autoridades pertinentes').'

'; + $this->_html .= '

'.$this->l('Si cree que este mensaje es un error, por favor, pongase en contacto con nosotros, enviandonos codigo de licencia, nombre del modulo, dominio de la tienda y copia de la factura de pago').'

'; + $this->_html .= '
'; + $this->_html .= '
'; + $this->_html .= $this->_mostrarLicencia(); + $this->forceCheck = 0; + } + else { + if ($this->_checkVersion()) { + $this->_html .= $this->displayConfirmation($this->_checkVersion()); + } + if ($this->idTab == '' || empty($this->idTab)) { + $this->idTab = 1; + } + $urlTienda = self::getUrlAdmin(); + $token = Tools::getAdminTokenLite('AdminModules'); + $moduleLink = $urlTienda.'index.php?controller=AdminModules&token='.$token.'&configure='.$this->name.'&tab_module=administration&module_name='.$this->name; + + $this->_html .= '' + .$extra; + $this->_html .= ''; + $this->_html .= '
'; + $i = 1; + foreach ($tabsArray as $funcion => $nombreTab) { + $this->_html .= ''; + $i++; + } + $this->_html .= '
'; + $this->_html .= ' + '; + } + } + + private function mostrarLicenciaTrait($idTab) { + include_once(dirname(__FILE__).'/functionsForm.php'); + include_once(dirname(__FILE__).'/imaxAcordeon.php'); + $licenseDomain = $this->getDomain(); + $html = ''; + $form = new imaxForm($this, $this->_path); + $acordeon = new imaxAcordeon($this->_path); + if (!$licenseDomain) { + $form->createFormInfomationText($this->l('La configuracion de su tienda no es correcta. No se puede determinar el dominio')); + $html .= $acordeon->renderAcordeon($this->l('Gestion Licencia'), $form->renderForm()); + Configuration::updateGlobalValue(self::prefijo.'LICENCIA', ''); + Configuration::updateGlobalValue(self::prefijo.'F', ''); + Configuration::updateGlobalValue(self::prefijo.'F_CHECK', 1001); + } + else { + $licencia = Configuration::getGlobalValue(self::prefijo.'LICENCIA'); + $form->createHidden("accion", "gestionLicencia"); + $form->createHidden("idTab", $idTab); + $form->createFormInfomationText($this->l('ATENCION: La licencia es obligatoria para el correcto funcionamiento del modulo')); + $form->createFormInfomationText($this->l('La licencia se deberia generar para el dominio: ').$licenseDomain, 'notice'); + $form->createFormTextGroup('licencia', $licencia, $this->l('Numero de Licencia')); + $form->createSubmitButton('submitLicencia', $this->l('Guardar')); + $html .= $acordeon->renderAcordeon($this->l('Gestion Licencia'), $form->renderForm()); + } + + return $html; + } + +} diff --git a/FuncionesImaxAddCatbyFeature.php b/FuncionesImaxAddCatbyFeature.php new file mode 100644 index 0000000..264330f --- /dev/null +++ b/FuncionesImaxAddCatbyFeature.php @@ -0,0 +1,100 @@ +modulo = $modulo; + } + + /** + * Agrega al producto las categorias pasadas. + * @param Product $producto + * @param int[] $categorias + */ + public function agregarCategorias($producto, $categorias) { + $categoriasActuales = $producto->getCategories(); + $nuevasCategorias = array_diff($categorias, $categoriasActuales); + foreach($nuevasCategorias as $categoria) { + $this->guardarMovimiento($producto->id, $categoria); + } + $producto->addToCategories($nuevasCategorias); + } + + /** + * Anota una nueva categoria de producto. + * @param int $id_product + * @param int $id_category + * @return boolean + */ + private function guardarMovimiento($id_product, $id_category) { + $id_product = (int)$id_product; + $id_category = (int)$id_category; + + return Db::getInstance()->execute('INSERT IGNORE INTO `'._DB_PREFIX_.$this->modulo->sufijo."movimiento` (id_product, id_category) VALUES ('$id_product', '$id_category')"); + } + + /** + * Devuelve los ids de categoria a los que el producto fue agregado. + * @param int $id_product + * @return int[] + */ + private function cargarMovimientos($id_product) { + $id_product = (int)$id_product; + + $movimientos = Db::getInstance()->executeS('SELECT id_category FROM `'._DB_PREFIX_.$this->modulo->sufijo."movimiento` WHERE id_product = '$id_product'"); + return array_column($movimientos, 'id_category'); + } + + /** + * Elimina los movimientos de un producto. + * @param int $id_product + * @return boolean + */ + private function eliminarMovimientos($id_product) { + $id_product = (int)$id_product; + + return Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.$this->modulo->sufijo."movimiento` WHERE id_product = '$id_product'"); + } + + /** + * Quita al producto las categorias agregadas. + * @param Product $producto + */ + public function deshacerMovimientos($producto) { + $idsCategoria = $this->cargarMovimientos($producto->id); + $num = count($idsCategoria); + foreach($idsCategoria as $clave => $idCategoria) { + $producto->deleteCategory($idCategoria, ($clave == $num - 1)); + } + $this->eliminarMovimientos($producto->id); + } + + /** + * Monta una lista de categorias recursivamente. + * @param array $categoria + * @param string $html + * @param int[] $categoriasSeleccionada + */ + public function getHijosLista($categoria, &$html, $categoriasSeleccionada) { + $categoriasHijos = Category::getChildren($categoria['id_category'], $this->modulo->idLang); + + if (count($categoriasHijos)) { + $html .= ''; + } + } +} diff --git a/acordeon/acordeon.css b/acordeon/acordeon.css new file mode 100644 index 0000000..22ddfc5 --- /dev/null +++ b/acordeon/acordeon.css @@ -0,0 +1,52 @@ +.acordeon, .acordeonInterno{ + font-family: sans-serif; + margin: 0; + position:relative; +} +.acordeon > dl{ margin: 60px auto; } +.acordeon dt, .acordeon dd, .acordeonInterno dt, .acordeonInterno dd{ padding: 10px; } +//.acordeon dt{ background: #333333; color: white; border-bottom: 1px solid #141414; border-top: 1px solid #4E4E4E; cursor: pointer; } +//.acordeon dd{ background: #F5F5F5; line-height: 1.6em; } + +.acordeon dt, +.acordeonInterno dt{ + background: #efefef; + color: #000; + border-bottom: 1px solid #cccccc; + border-top: 1px solid #cccccc; + cursor: pointer; +} +.acordeon dd +, .acordeonInterno dd +{line-height: 1.6em;margin-left:0 } + +.acordeon dt.activo, .acordeonInterno dt.activo, dt:hover{ background: #fff6d3; } +//.acordeon dt:before{ content: url("../css/right.png"); margin-right: 10px; } +//.acordeon dt.activo:before{ content: url("../css/down.png"); } + +.acordeon dt +, .acordeonInterno dt{ + background-image: url("img/right.png"); + background-position: 10px 5px; + background-repeat: no-repeat; + padding-left: 35px; +} +.acordeon dt.activo +, .acordeonInterno dt.activo{ + background-image: url("img/down.png"); + background-position: 14px 9px; + background-repeat: no-repeat; + padding-left: 35px; + +} +.acordeon input[type="submit"] { + position: absolute; + right: 5px; + top: 5px; + border-radius: 5px; + padding: 3px; +} +.tr_1 td, .tr_2 td, .tr_3 td, .tr_4 td, +.tr_5 td, .tr_6 td, .tr_7 td, .tr_8 td { + padding-right: 15px; +} diff --git a/acordeon/acordeon.js b/acordeon/acordeon.js new file mode 100644 index 0000000..75baafb --- /dev/null +++ b/acordeon/acordeon.js @@ -0,0 +1,26 @@ +$(function() { + $('dl.acordeonInterno > dd').not('dt.activo + dd').hide(); + $('dl.acordeonInterno > dt').click(function() { + if ($(this).hasClass('activo')) { + $(this).removeClass('activo'); + $(this).next().slideUp(); + } else { + $('dl.acordeonInterno dt').removeClass('activo'); + $(this).addClass('activo'); + $('dl.acordeonInterno dd').slideUp(); + $(this).next().slideDown(); + } + }); + $('dl.acordeon > dd').not('dt.activo + dd').hide(); + $('dl.acordeon > dt').click(function() { + if ($(this).hasClass('activo')) { + $(this).removeClass('activo'); + $(this).next().slideUp(); + } else { + $('dl dt').removeClass('activo'); + $(this).addClass('activo'); + $('dl dd').slideUp(); + $(this).next().slideDown(); + } + }); +}); diff --git a/acordeon/img/down.png b/acordeon/img/down.png new file mode 100644 index 0000000..a5f0d7a Binary files /dev/null and b/acordeon/img/down.png differ diff --git a/acordeon/img/right.png b/acordeon/img/right.png new file mode 100644 index 0000000..619819b Binary files /dev/null and b/acordeon/img/right.png differ diff --git a/config.xml b/config.xml new file mode 100644 index 0000000..8c0c725 --- /dev/null +++ b/config.xml @@ -0,0 +1,14 @@ + + + imaxaddcatbyfeature + + + + + + 1 + 0 + 1 + 1 + + diff --git a/configuration.php b/configuration.php new file mode 100644 index 0000000..3f53517 --- /dev/null +++ b/configuration.php @@ -0,0 +1,49 @@ +sufijo . 'CATS_NOVEDAD'] = serialize(array()); +$configuracion[$this->sufijo . 'DIAS_NOVEDAD'] = 7; +$configuracion[$this->sufijo . 'TOKEN'] = md5(uniqid()); + +$configuracion[$this->sufijo . 'LICENCIA'] = ''; +$configuracion[$this->sufijo . 'F_SERVER'] = 'http://licencia.informax.es/gestionarLicencias.php'; +$configuracion[$this->sufijo . 'F'] = ''; +$configuracion[$this->sufijo . 'F_CHECK'] = 1000; + + +$hooks = array(); +$hooks[] = 'actionObjectProductAddAfter'; + + + +/* + CAMPOS NECESARIOS PARA LA PUBLICIDAD + */ +$configuracion[$this->sufijo . 'URL_TXT'] = 'http://publi.informax.es'; +$configuracion[$this->sufijo . 'TIPO'] = 'general'; +$configuracion[$this->sufijo . 'DESCARGA_ARCHIVO'] = 10001; +$configuracion[$this->sufijo . 'TXT_FILE'] = ''; + + +$configuracion[$this->sufijo . 'F'] = ''; +$configuracion[$this->sufijo . 'LICENCIA'] = ''; +$configuracion[$this->sufijo . 'F_CHECK'] = 1000; +$configuracion[$this->sufijo . 'F_SERVER'] = 'http://licencia.informax.es/gestionarLicencias.php'; + + + + +//ARCHIVO CONFIGURATION.PHP + +$moduleTabRoot= array(); +$moduleTabRoot['name'] = 'Informax'; +$moduleTabRoot['clase'] = 'AdminInformax'; +$moduleTabRoot['padre'] = ''; +$moduleTabRoot['imagen'] = 'informax.gif'; + +$moduleTabs = array(); +$moduleTabs[0] = array(); + +$moduleTabs[0]['name'] = 'Feature by carac'; +$moduleTabs[0]['clase'] = 'Adminxaddcatbyfeature'; +$moduleTabs[0]['padre'] = 'AdminInformax'; +$moduleTabs[0]['imagen'] = 'informax.gif'; diff --git a/controllers/admin/Adminxaddcatbyfeature.php b/controllers/admin/Adminxaddcatbyfeature.php new file mode 100644 index 0000000..6c24f9c --- /dev/null +++ b/controllers/admin/Adminxaddcatbyfeature.php @@ -0,0 +1,16 @@ +id_employee)); + header('Location: index.php?configure=imaxaddcatbyfeature&tab_module=administration&module_name=imaxaddcatbyfeature&controller=AdminModules&token=' . $token); + exit; + + } + public function initContent() { + global $cookie; + $token = md5(pSQL(_COOKIE_KEY_ . 'AdminModules' . (int) Tab::getIdFromClassName('AdminModules') . (int) $cookie->id_employee)); + header('Location: index.php?configure=imaxaddcatbyfeature&tab_module=administration&module_name=imaxaddcatbyfeature&controller=AdminModules&token=' . $token); + exit; + } +} diff --git a/css/clock.gif b/css/clock.gif new file mode 100644 index 0000000..d72702c Binary files /dev/null and b/css/clock.gif differ diff --git a/css/css.css b/css/css.css new file mode 100644 index 0000000..7e03857 --- /dev/null +++ b/css/css.css @@ -0,0 +1,48 @@ +#imax_destinatarios { + text-align: center; + margin-bottom: 10px; +} + +#imax_destinatarios p { + font-weight: bold; + margin-top: 5px; +} + +.imax_destinatarios { + margin: auto; +} + +.imax_destinatarios th { + font-weight: bold; +} + +.imax_destinatarios td, .imax_destinatarios th { + padding: 3px; + border: 1px solid black; +} + +#imax_mensajeError { + color: red; +} + +.centrado { + text-align: center; +} + +@media print { + .noImprimir { + display: none; + } +} + +#order_sortable li, .table img { + cursor: pointer; +} + +.imax_marcado { + background-color: yellow; +} + +#arbolCategorias { + margin-bottom: 15px; +} \ No newline at end of file diff --git a/css/custom.css b/css/custom.css new file mode 100644 index 0000000..6582118 --- /dev/null +++ b/css/custom.css @@ -0,0 +1,7 @@ +/* + Document : custom + Created on : 12-ago-2013, 11:51:14 + Author : daniel + Description: + Para que el usuario modifique la apariencia a su gusto. +*/ diff --git a/css/down.png b/css/down.png new file mode 100644 index 0000000..a5f0d7a Binary files /dev/null and b/css/down.png differ diff --git a/css/espera.gif b/css/espera.gif new file mode 100644 index 0000000..f11dcaf Binary files /dev/null and b/css/espera.gif differ diff --git a/css/estadoLicencia_ausente.png b/css/estadoLicencia_ausente.png new file mode 100644 index 0000000..72271e9 Binary files /dev/null and b/css/estadoLicencia_ausente.png differ diff --git a/css/estadoLicencia_correcta.png b/css/estadoLicencia_correcta.png new file mode 100644 index 0000000..b06eb6a Binary files /dev/null and b/css/estadoLicencia_correcta.png differ diff --git a/css/estadoLicencia_incorrecta.png b/css/estadoLicencia_incorrecta.png new file mode 100644 index 0000000..18789a4 Binary files /dev/null and b/css/estadoLicencia_incorrecta.png differ diff --git a/css/index.php b/css/index.php new file mode 100644 index 0000000..d897a02 --- /dev/null +++ b/css/index.php @@ -0,0 +1,9 @@ + diff --git a/css/publi.css b/css/publi.css new file mode 100644 index 0000000..21bca18 --- /dev/null +++ b/css/publi.css @@ -0,0 +1,105 @@ +.module-header { + /*background-color: #8bc954; + border-bottom: 4px solid #71b238; + */ + background-color: #ff5757; + border-bottom: 4px solid #c43d3d; + box-shadow: 0 5px 0 rgba(0, 0, 0, 0.15); + height: 70px; + left: 0; + margin: 0 0 20px 0; + padding: 0; + width: 100%; + font-family:"Open Sans","Helvetica","Arial","sans-serif"; + color:#fff; +} +.module-title-container { + width:58%; + float:left; + margin-left:10px; +} +.module-header h2 { + margin-bottom:0; +} +.module-header h3 { + margin-top:0; +} +.module-toolbar { + float:right; + text-align: right; + width: 40%; +} + +.module-toolbar li { + float: right; + list-style: outside none none; + text-align: center; + width: 31%; +} +.module-nav li a { + text-decoration:none; + color:#fff; +} +.module-nav li a:hover { + text-decoration:none; + color:#EEE; +} + +.module-preheader { + width: 100%; +} + +.module-preheader img{ + width: 100%; +} + +.module-footer{ + margin-top: 30px; + width: 100%; +} +.module-footer img{ + width: 100%; +} +.module-footer-left{ + width: 63.2%; + float: left; +} +.module-footer-right{ + width: 36.65%; + float: left; + +} +.module-newsletter{ + /* background-color: #8bc954; */ + background-color: #ff5757; + border-top: 4px solid #c43d3d; + box-shadow: 0 -5px 0 rgba(0, 0, 0, 0.15); + color: #fff; + font-family: "Open Sans","Helvetica","Arial","sans-serif"; + height: 70px; + left: 0; + margin: 0 0 20px; + padding: 0; + width: 100%; +} + +.module-newsletter p { + padding-left: 10px !important; + color:#FFF; +} +.module-newsletter form p label { + color: #fff; + font-weight: normal; + text-shadow: none; +} +.module-newsletter ul li{ + list-style: none; +} + +.module-newsletter p.uppercase { + text-transform: uppercase; +} + +.nobootstrap { + min-width: 1024px !important; +} diff --git a/css/right.png b/css/right.png new file mode 100644 index 0000000..619819b Binary files /dev/null and b/css/right.png differ diff --git a/forms/forms.15.css b/forms/forms.15.css new file mode 100644 index 0000000..86fde24 --- /dev/null +++ b/forms/forms.15.css @@ -0,0 +1,9 @@ +.selectIdioma, .selectIdioma option { + padding-left: 20px; + background-position: 1px center; + background-repeat: no-repeat; +} + +.form-group { + margin-top: 5px; +} diff --git a/forms/forms.css b/forms/forms.css new file mode 100644 index 0000000..582b59f --- /dev/null +++ b/forms/forms.css @@ -0,0 +1,5 @@ +.selectIdioma, .selectIdioma option { + padding-left: 20px; + background-position: 1px center; + background-repeat: no-repeat; +} diff --git a/forms/forms.js b/forms/forms.js new file mode 100644 index 0000000..d5eaaa2 --- /dev/null +++ b/forms/forms.js @@ -0,0 +1,7 @@ +$(function() { + $('.selectIdioma').change(function() { + var idLang = $(this).val(); + $(this).css('background-image', 'url("' + rutaImagenes + idLang + '.jpg")'); + }); + $('.selectIdioma').change(); +}) diff --git a/forms/forms_1.css b/forms/forms_1.css new file mode 100644 index 0000000..582b59f --- /dev/null +++ b/forms/forms_1.css @@ -0,0 +1,5 @@ +.selectIdioma, .selectIdioma option { + padding-left: 20px; + background-position: 1px center; + background-repeat: no-repeat; +} diff --git a/forms/forms_1.js b/forms/forms_1.js new file mode 100644 index 0000000..d5eaaa2 --- /dev/null +++ b/forms/forms_1.js @@ -0,0 +1,7 @@ +$(function() { + $('.selectIdioma').change(function() { + var idLang = $(this).val(); + $(this).css('background-image', 'url("' + rutaImagenes + idLang + '.jpg")'); + }); + $('.selectIdioma').change(); +}) diff --git a/forms/jquery.fileupload-image.js b/forms/jquery.fileupload-image.js new file mode 100644 index 0000000..d8ccd3f --- /dev/null +++ b/forms/jquery.fileupload-image.js @@ -0,0 +1,294 @@ +/* + * jQuery File Upload Image Preview & Resize Plugin 1.3.1 + * https://github.com/blueimp/jQuery-File-Upload + * + * Copyright 2013, Sebastian Tschan + * https://blueimp.net + * + * Licensed under the MIT license: + * http://www.opensource.org/licenses/MIT + */ + +/*jslint nomen: true, unparam: true, regexp: true */ +/*global define, window, document, DataView, Blob, Uint8Array */ + +(function (factory) { + 'use strict'; + if (typeof define === 'function' && define.amd) { + // Register as an anonymous AMD module: + define([ + 'jquery', + 'load-image', + 'load-image-meta', + 'load-image-exif', + 'load-image-ios', + 'canvas-to-blob', + './jquery.fileupload-process' + ], factory); + } else { + // Browser globals: + factory( + window.jQuery, + window.loadImage + ); + } +}(function ($, loadImage) { + 'use strict'; + + // Prepend to the default processQueue: + $.blueimp.fileupload.prototype.options.processQueue.unshift( + { + action: 'loadImageMetaData', + disableImageHead: '@', + disableExif: '@', + disableExifThumbnail: '@', + disableExifSub: '@', + disableExifGps: '@', + disabled: '@disableImageMetaDataLoad' + }, + { + action: 'loadImage', + // Use the action as prefix for the "@" options: + prefix: true, + fileTypes: '@', + maxFileSize: '@', + noRevoke: '@', + disabled: '@disableImageLoad' + }, + { + action: 'resizeImage', + // Use "image" as prefix for the "@" options: + prefix: 'image', + maxWidth: '@', + maxHeight: '@', + minWidth: '@', + minHeight: '@', + crop: '@', + orientation: '@', + disabled: '@disableImageResize' + }, + { + action: 'saveImage', + disabled: '@disableImageResize' + }, + { + action: 'saveImageMetaData', + disabled: '@disableImageMetaDataSave' + }, + { + action: 'resizeImage', + // Use "preview" as prefix for the "@" options: + prefix: 'preview', + maxWidth: '@', + maxHeight: '@', + minWidth: '@', + minHeight: '@', + crop: '@', + orientation: '@', + thumbnail: '@', + canvas: '@', + disabled: '@disableImagePreview' + }, + { + action: 'setImage', + name: '@imagePreviewName', + disabled: '@disableImagePreview' + } + ); + + // The File Upload Resize plugin extends the fileupload widget + // with image resize functionality: + $.widget('blueimp.fileupload', $.blueimp.fileupload, { + + options: { + // The regular expression for the types of images to load: + // matched against the file type: + loadImageFileTypes: /^image\/(gif|jpeg|png)$/, + // The maximum file size of images to load: + loadImageMaxFileSize: 10000000, // 10MB + // The maximum width of resized images: + imageMaxWidth: 1920, + // The maximum height of resized images: + imageMaxHeight: 1080, + // Defines the image orientation (1-8) or takes the orientation + // value from Exif data if set to true: + imageOrientation: false, + // Define if resized images should be cropped or only scaled: + imageCrop: false, + // Disable the resize image functionality by default: + disableImageResize: true, + // The maximum width of the preview images: + previewMaxWidth: 80, + // The maximum height of the preview images: + previewMaxHeight: 80, + // Defines the preview orientation (1-8) or takes the orientation + // value from Exif data if set to true: + previewOrientation: true, + // Create the preview using the Exif data thumbnail: + previewThumbnail: true, + // Define if preview images should be cropped or only scaled: + previewCrop: false, + // Define if preview images should be resized as canvas elements: + previewCanvas: true + }, + + processActions: { + + // Loads the image given via data.files and data.index + // as img element, if the browser supports the File API. + // Accepts the options fileTypes (regular expression) + // and maxFileSize (integer) to limit the files to load: + loadImage: function (data, options) { + if (options.disabled) { + return data; + } + var that = this, + file = data.files[data.index], + dfd = $.Deferred(); + if (($.type(options.maxFileSize) === 'number' && + file.size > options.maxFileSize) || + (options.fileTypes && + !options.fileTypes.test(file.type)) || + !loadImage( + file, + function (img) { + if (img.src) { + data.img = img; + } + dfd.resolveWith(that, [data]); + }, + options + )) { + return data; + } + return dfd.promise(); + }, + + // Resizes the image given as data.canvas or data.img + // and updates data.canvas or data.img with the resized image. + // Also stores the resized image as preview property. + // Accepts the options maxWidth, maxHeight, minWidth, + // minHeight, canvas and crop: + resizeImage: function (data, options) { + if (options.disabled || !(data.canvas || data.img)) { + return data; + } + options = $.extend({canvas: true}, options); + var that = this, + dfd = $.Deferred(), + img = (options.canvas && data.canvas) || data.img, + resolve = function (newImg) { + if (newImg && (newImg.width !== img.width || + newImg.height !== img.height)) { + data[newImg.getContext ? 'canvas' : 'img'] = newImg; + } + data.preview = newImg; + dfd.resolveWith(that, [data]); + }, + thumbnail; + if (data.exif) { + if (options.orientation === true) { + options.orientation = data.exif.get('Orientation'); + } + if (options.thumbnail) { + thumbnail = data.exif.get('Thumbnail'); + if (thumbnail) { + loadImage(thumbnail, resolve, options); + return dfd.promise(); + } + } + } + if (img) { + resolve(loadImage.scale(img, options)); + return dfd.promise(); + } + return data; + }, + + // Saves the processed image given as data.canvas + // inplace at data.index of data.files: + saveImage: function (data, options) { + if (!data.canvas || options.disabled) { + return data; + } + var that = this, + file = data.files[data.index], + name = file.name, + dfd = $.Deferred(), + callback = function (blob) { + if (!blob.name) { + if (file.type === blob.type) { + blob.name = file.name; + } else if (file.name) { + blob.name = file.name.replace( + /\..+$/, + '.' + blob.type.substr(6) + ); + } + } + // Store the created blob at the position + // of the original file in the files list: + data.files[data.index] = blob; + dfd.resolveWith(that, [data]); + }; + // Use canvas.mozGetAsFile directly, to retain the filename, as + // Gecko doesn't support the filename option for FormData.append: + if (data.canvas.mozGetAsFile) { + callback(data.canvas.mozGetAsFile( + (/^image\/(jpeg|png)$/.test(file.type) && name) || + ((name && name.replace(/\..+$/, '')) || + 'blob') + '.png', + file.type + )); + } else if (data.canvas.toBlob) { + data.canvas.toBlob(callback, file.type); + } else { + return data; + } + return dfd.promise(); + }, + + loadImageMetaData: function (data, options) { + if (options.disabled) { + return data; + } + var that = this, + dfd = $.Deferred(); + loadImage.parseMetaData(data.files[data.index], function (result) { + $.extend(data, result); + dfd.resolveWith(that, [data]); + }, options); + return dfd.promise(); + }, + + saveImageMetaData: function (data, options) { + if (!(data.imageHead && data.canvas && + data.canvas.toBlob && !options.disabled)) { + return data; + } + var file = data.files[data.index], + blob = new Blob([ + data.imageHead, + // Resized images always have a head size of 20 bytes, + // including the JPEG marker and a minimal JFIF header: + this._blobSlice.call(file, 20) + ], {type: file.type}); + blob.name = file.name; + data.files[data.index] = blob; + return data; + }, + + // Sets the resized version of the image as a property of the + // file object, must be called after "saveImage": + setImage: function (data, options) { + if (data.preview && !options.disabled) { + data.files[data.index][options.name || 'preview'] = data.preview; + } + return data; + } + + } + + }); + +})); diff --git a/forms/jquery.fileupload-image_1.js b/forms/jquery.fileupload-image_1.js new file mode 100644 index 0000000..d8ccd3f --- /dev/null +++ b/forms/jquery.fileupload-image_1.js @@ -0,0 +1,294 @@ +/* + * jQuery File Upload Image Preview & Resize Plugin 1.3.1 + * https://github.com/blueimp/jQuery-File-Upload + * + * Copyright 2013, Sebastian Tschan + * https://blueimp.net + * + * Licensed under the MIT license: + * http://www.opensource.org/licenses/MIT + */ + +/*jslint nomen: true, unparam: true, regexp: true */ +/*global define, window, document, DataView, Blob, Uint8Array */ + +(function (factory) { + 'use strict'; + if (typeof define === 'function' && define.amd) { + // Register as an anonymous AMD module: + define([ + 'jquery', + 'load-image', + 'load-image-meta', + 'load-image-exif', + 'load-image-ios', + 'canvas-to-blob', + './jquery.fileupload-process' + ], factory); + } else { + // Browser globals: + factory( + window.jQuery, + window.loadImage + ); + } +}(function ($, loadImage) { + 'use strict'; + + // Prepend to the default processQueue: + $.blueimp.fileupload.prototype.options.processQueue.unshift( + { + action: 'loadImageMetaData', + disableImageHead: '@', + disableExif: '@', + disableExifThumbnail: '@', + disableExifSub: '@', + disableExifGps: '@', + disabled: '@disableImageMetaDataLoad' + }, + { + action: 'loadImage', + // Use the action as prefix for the "@" options: + prefix: true, + fileTypes: '@', + maxFileSize: '@', + noRevoke: '@', + disabled: '@disableImageLoad' + }, + { + action: 'resizeImage', + // Use "image" as prefix for the "@" options: + prefix: 'image', + maxWidth: '@', + maxHeight: '@', + minWidth: '@', + minHeight: '@', + crop: '@', + orientation: '@', + disabled: '@disableImageResize' + }, + { + action: 'saveImage', + disabled: '@disableImageResize' + }, + { + action: 'saveImageMetaData', + disabled: '@disableImageMetaDataSave' + }, + { + action: 'resizeImage', + // Use "preview" as prefix for the "@" options: + prefix: 'preview', + maxWidth: '@', + maxHeight: '@', + minWidth: '@', + minHeight: '@', + crop: '@', + orientation: '@', + thumbnail: '@', + canvas: '@', + disabled: '@disableImagePreview' + }, + { + action: 'setImage', + name: '@imagePreviewName', + disabled: '@disableImagePreview' + } + ); + + // The File Upload Resize plugin extends the fileupload widget + // with image resize functionality: + $.widget('blueimp.fileupload', $.blueimp.fileupload, { + + options: { + // The regular expression for the types of images to load: + // matched against the file type: + loadImageFileTypes: /^image\/(gif|jpeg|png)$/, + // The maximum file size of images to load: + loadImageMaxFileSize: 10000000, // 10MB + // The maximum width of resized images: + imageMaxWidth: 1920, + // The maximum height of resized images: + imageMaxHeight: 1080, + // Defines the image orientation (1-8) or takes the orientation + // value from Exif data if set to true: + imageOrientation: false, + // Define if resized images should be cropped or only scaled: + imageCrop: false, + // Disable the resize image functionality by default: + disableImageResize: true, + // The maximum width of the preview images: + previewMaxWidth: 80, + // The maximum height of the preview images: + previewMaxHeight: 80, + // Defines the preview orientation (1-8) or takes the orientation + // value from Exif data if set to true: + previewOrientation: true, + // Create the preview using the Exif data thumbnail: + previewThumbnail: true, + // Define if preview images should be cropped or only scaled: + previewCrop: false, + // Define if preview images should be resized as canvas elements: + previewCanvas: true + }, + + processActions: { + + // Loads the image given via data.files and data.index + // as img element, if the browser supports the File API. + // Accepts the options fileTypes (regular expression) + // and maxFileSize (integer) to limit the files to load: + loadImage: function (data, options) { + if (options.disabled) { + return data; + } + var that = this, + file = data.files[data.index], + dfd = $.Deferred(); + if (($.type(options.maxFileSize) === 'number' && + file.size > options.maxFileSize) || + (options.fileTypes && + !options.fileTypes.test(file.type)) || + !loadImage( + file, + function (img) { + if (img.src) { + data.img = img; + } + dfd.resolveWith(that, [data]); + }, + options + )) { + return data; + } + return dfd.promise(); + }, + + // Resizes the image given as data.canvas or data.img + // and updates data.canvas or data.img with the resized image. + // Also stores the resized image as preview property. + // Accepts the options maxWidth, maxHeight, minWidth, + // minHeight, canvas and crop: + resizeImage: function (data, options) { + if (options.disabled || !(data.canvas || data.img)) { + return data; + } + options = $.extend({canvas: true}, options); + var that = this, + dfd = $.Deferred(), + img = (options.canvas && data.canvas) || data.img, + resolve = function (newImg) { + if (newImg && (newImg.width !== img.width || + newImg.height !== img.height)) { + data[newImg.getContext ? 'canvas' : 'img'] = newImg; + } + data.preview = newImg; + dfd.resolveWith(that, [data]); + }, + thumbnail; + if (data.exif) { + if (options.orientation === true) { + options.orientation = data.exif.get('Orientation'); + } + if (options.thumbnail) { + thumbnail = data.exif.get('Thumbnail'); + if (thumbnail) { + loadImage(thumbnail, resolve, options); + return dfd.promise(); + } + } + } + if (img) { + resolve(loadImage.scale(img, options)); + return dfd.promise(); + } + return data; + }, + + // Saves the processed image given as data.canvas + // inplace at data.index of data.files: + saveImage: function (data, options) { + if (!data.canvas || options.disabled) { + return data; + } + var that = this, + file = data.files[data.index], + name = file.name, + dfd = $.Deferred(), + callback = function (blob) { + if (!blob.name) { + if (file.type === blob.type) { + blob.name = file.name; + } else if (file.name) { + blob.name = file.name.replace( + /\..+$/, + '.' + blob.type.substr(6) + ); + } + } + // Store the created blob at the position + // of the original file in the files list: + data.files[data.index] = blob; + dfd.resolveWith(that, [data]); + }; + // Use canvas.mozGetAsFile directly, to retain the filename, as + // Gecko doesn't support the filename option for FormData.append: + if (data.canvas.mozGetAsFile) { + callback(data.canvas.mozGetAsFile( + (/^image\/(jpeg|png)$/.test(file.type) && name) || + ((name && name.replace(/\..+$/, '')) || + 'blob') + '.png', + file.type + )); + } else if (data.canvas.toBlob) { + data.canvas.toBlob(callback, file.type); + } else { + return data; + } + return dfd.promise(); + }, + + loadImageMetaData: function (data, options) { + if (options.disabled) { + return data; + } + var that = this, + dfd = $.Deferred(); + loadImage.parseMetaData(data.files[data.index], function (result) { + $.extend(data, result); + dfd.resolveWith(that, [data]); + }, options); + return dfd.promise(); + }, + + saveImageMetaData: function (data, options) { + if (!(data.imageHead && data.canvas && + data.canvas.toBlob && !options.disabled)) { + return data; + } + var file = data.files[data.index], + blob = new Blob([ + data.imageHead, + // Resized images always have a head size of 20 bytes, + // including the JPEG marker and a minimal JFIF header: + this._blobSlice.call(file, 20) + ], {type: file.type}); + blob.name = file.name; + data.files[data.index] = blob; + return data; + }, + + // Sets the resized version of the image as a property of the + // file object, must be called after "saveImage": + setImage: function (data, options) { + if (data.preview && !options.disabled) { + data.files[data.index][options.name || 'preview'] = data.preview; + } + return data; + } + + } + + }); + +})); diff --git a/forms/jquery.fileupload-process.js b/forms/jquery.fileupload-process.js new file mode 100644 index 0000000..87042c3 --- /dev/null +++ b/forms/jquery.fileupload-process.js @@ -0,0 +1,164 @@ +/* + * jQuery File Upload Processing Plugin 1.2.2 + * https://github.com/blueimp/jQuery-File-Upload + * + * Copyright 2012, Sebastian Tschan + * https://blueimp.net + * + * Licensed under the MIT license: + * http://www.opensource.org/licenses/MIT + */ + +/*jslint nomen: true, unparam: true */ +/*global define, window */ + +(function (factory) { + 'use strict'; + if (typeof define === 'function' && define.amd) { + // Register as an anonymous AMD module: + define([ + 'jquery', + './jquery.fileupload' + ], factory); + } else { + // Browser globals: + factory( + window.jQuery + ); + } +}(function ($) { + 'use strict'; + + var originalAdd = $.blueimp.fileupload.prototype.options.add; + + // The File Upload Processing plugin extends the fileupload widget + // with file processing functionality: + $.widget('blueimp.fileupload', $.blueimp.fileupload, { + + options: { + // The list of processing actions: + processQueue: [ + /* + { + action: 'log', + type: 'debug' + } + */ + ], + add: function (e, data) { + var $this = $(this); + data.process(function () { + return $this.fileupload('process', data); + }); + originalAdd.call(this, e, data); + } + }, + + processActions: { + /* + log: function (data, options) { + console[options.type]( + 'Processing "' + data.files[data.index].name + '"' + ); + } + */ + }, + + _processFile: function (data) { + var that = this, + dfd = $.Deferred().resolveWith(that, [data]), + chain = dfd.promise(); + this._trigger('process', null, data); + $.each(data.processQueue, function (i, settings) { + var func = function (data) { + return that.processActions[settings.action].call( + that, + data, + settings + ); + }; + chain = chain.pipe(func, settings.always && func); + }); + chain + .done(function () { + that._trigger('processdone', null, data); + that._trigger('processalways', null, data); + }) + .fail(function () { + that._trigger('processfail', null, data); + that._trigger('processalways', null, data); + }); + return chain; + }, + + // Replaces the settings of each processQueue item that + // are strings starting with an "@", using the remaining + // substring as key for the option map, + // e.g. "@autoUpload" is replaced with options.autoUpload: + _transformProcessQueue: function (options) { + var processQueue = []; + $.each(options.processQueue, function () { + var settings = {}, + action = this.action, + prefix = this.prefix === true ? action : this.prefix; + $.each(this, function (key, value) { + if ($.type(value) === 'string' && + value.charAt(0) === '@') { + settings[key] = options[ + value.slice(1) || (prefix ? prefix + + key.charAt(0).toUpperCase() + key.slice(1) : key) + ]; + } else { + settings[key] = value; + } + + }); + processQueue.push(settings); + }); + options.processQueue = processQueue; + }, + + // Returns the number of files currently in the processsing queue: + processing: function () { + return this._processing; + }, + + // Processes the files given as files property of the data parameter, + // returns a Promise object that allows to bind callbacks: + process: function (data) { + var that = this, + options = $.extend({}, this.options, data); + if (options.processQueue && options.processQueue.length) { + this._transformProcessQueue(options); + if (this._processing === 0) { + this._trigger('processstart'); + } + $.each(data.files, function (index) { + var opts = index ? $.extend({}, options) : options, + func = function () { + return that._processFile(opts); + }; + opts.index = index; + that._processing += 1; + that._processingQueue = that._processingQueue.pipe(func, func) + .always(function () { + that._processing -= 1; + if (that._processing === 0) { + that._trigger('processstop'); + } + }); + }); + } + return this._processingQueue; + }, + + _create: function () { + this._super(); + this._processing = 0; + this._processingQueue = $.Deferred().resolveWith(this) + .promise(); + } + + }); + +})); diff --git a/forms/jquery.fileupload-process_1.js b/forms/jquery.fileupload-process_1.js new file mode 100644 index 0000000..87042c3 --- /dev/null +++ b/forms/jquery.fileupload-process_1.js @@ -0,0 +1,164 @@ +/* + * jQuery File Upload Processing Plugin 1.2.2 + * https://github.com/blueimp/jQuery-File-Upload + * + * Copyright 2012, Sebastian Tschan + * https://blueimp.net + * + * Licensed under the MIT license: + * http://www.opensource.org/licenses/MIT + */ + +/*jslint nomen: true, unparam: true */ +/*global define, window */ + +(function (factory) { + 'use strict'; + if (typeof define === 'function' && define.amd) { + // Register as an anonymous AMD module: + define([ + 'jquery', + './jquery.fileupload' + ], factory); + } else { + // Browser globals: + factory( + window.jQuery + ); + } +}(function ($) { + 'use strict'; + + var originalAdd = $.blueimp.fileupload.prototype.options.add; + + // The File Upload Processing plugin extends the fileupload widget + // with file processing functionality: + $.widget('blueimp.fileupload', $.blueimp.fileupload, { + + options: { + // The list of processing actions: + processQueue: [ + /* + { + action: 'log', + type: 'debug' + } + */ + ], + add: function (e, data) { + var $this = $(this); + data.process(function () { + return $this.fileupload('process', data); + }); + originalAdd.call(this, e, data); + } + }, + + processActions: { + /* + log: function (data, options) { + console[options.type]( + 'Processing "' + data.files[data.index].name + '"' + ); + } + */ + }, + + _processFile: function (data) { + var that = this, + dfd = $.Deferred().resolveWith(that, [data]), + chain = dfd.promise(); + this._trigger('process', null, data); + $.each(data.processQueue, function (i, settings) { + var func = function (data) { + return that.processActions[settings.action].call( + that, + data, + settings + ); + }; + chain = chain.pipe(func, settings.always && func); + }); + chain + .done(function () { + that._trigger('processdone', null, data); + that._trigger('processalways', null, data); + }) + .fail(function () { + that._trigger('processfail', null, data); + that._trigger('processalways', null, data); + }); + return chain; + }, + + // Replaces the settings of each processQueue item that + // are strings starting with an "@", using the remaining + // substring as key for the option map, + // e.g. "@autoUpload" is replaced with options.autoUpload: + _transformProcessQueue: function (options) { + var processQueue = []; + $.each(options.processQueue, function () { + var settings = {}, + action = this.action, + prefix = this.prefix === true ? action : this.prefix; + $.each(this, function (key, value) { + if ($.type(value) === 'string' && + value.charAt(0) === '@') { + settings[key] = options[ + value.slice(1) || (prefix ? prefix + + key.charAt(0).toUpperCase() + key.slice(1) : key) + ]; + } else { + settings[key] = value; + } + + }); + processQueue.push(settings); + }); + options.processQueue = processQueue; + }, + + // Returns the number of files currently in the processsing queue: + processing: function () { + return this._processing; + }, + + // Processes the files given as files property of the data parameter, + // returns a Promise object that allows to bind callbacks: + process: function (data) { + var that = this, + options = $.extend({}, this.options, data); + if (options.processQueue && options.processQueue.length) { + this._transformProcessQueue(options); + if (this._processing === 0) { + this._trigger('processstart'); + } + $.each(data.files, function (index) { + var opts = index ? $.extend({}, options) : options, + func = function () { + return that._processFile(opts); + }; + opts.index = index; + that._processing += 1; + that._processingQueue = that._processingQueue.pipe(func, func) + .always(function () { + that._processing -= 1; + if (that._processing === 0) { + that._trigger('processstop'); + } + }); + }); + } + return this._processingQueue; + }, + + _create: function () { + this._super(); + this._processing = 0; + this._processingQueue = $.Deferred().resolveWith(this) + .promise(); + } + + }); + +})); diff --git a/forms/jquery.fileupload-validate.js b/forms/jquery.fileupload-validate.js new file mode 100644 index 0000000..ee1c2f2 --- /dev/null +++ b/forms/jquery.fileupload-validate.js @@ -0,0 +1,117 @@ +/* + * jQuery File Upload Validation Plugin 1.1.1 + * https://github.com/blueimp/jQuery-File-Upload + * + * Copyright 2013, Sebastian Tschan + * https://blueimp.net + * + * Licensed under the MIT license: + * http://www.opensource.org/licenses/MIT + */ + +/*jslint nomen: true, unparam: true, regexp: true */ +/*global define, window */ + +(function (factory) { + 'use strict'; + if (typeof define === 'function' && define.amd) { + // Register as an anonymous AMD module: + define([ + 'jquery', + './jquery.fileupload-process' + ], factory); + } else { + // Browser globals: + factory( + window.jQuery + ); + } +}(function ($) { + 'use strict'; + + // Append to the default processQueue: + $.blueimp.fileupload.prototype.options.processQueue.push( + { + action: 'validate', + // Always trigger this action, + // even if the previous action was rejected: + always: true, + // Options taken from the global options map: + acceptFileTypes: '@', + maxFileSize: '@', + minFileSize: '@', + maxNumberOfFiles: '@', + disabled: '@disableValidation' + } + ); + + // The File Upload Validation plugin extends the fileupload widget + // with file validation functionality: + $.widget('blueimp.fileupload', $.blueimp.fileupload, { + + options: { + /* + // The regular expression for allowed file types, matches + // against either file type or file name: + acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i, + // The maximum allowed file size in bytes: + maxFileSize: 10000000, // 10 MB + // The minimum allowed file size in bytes: + minFileSize: undefined, // No minimal file size + // The limit of files to be uploaded: + maxNumberOfFiles: 10, + */ + + // Function returning the current number of files, + // has to be overriden for maxNumberOfFiles validation: + getNumberOfFiles: $.noop, + + // Error and info messages: + messages: { + maxNumberOfFiles: 'Maximum number of files exceeded', + acceptFileTypes: 'File type not allowed', + maxFileSize: 'File is too large', + minFileSize: 'File is too small' + } + }, + + processActions: { + + validate: function (data, options) { + if (options.disabled) { + return data; + } + var dfd = $.Deferred(), + settings = this.options, + file = data.files[data.index]; + if ($.type(options.maxNumberOfFiles) === 'number' && + (settings.getNumberOfFiles() || 0) + data.files.length > + options.maxNumberOfFiles) { + file.error = settings.i18n('maxNumberOfFiles'); + } else if (options.acceptFileTypes && + !(options.acceptFileTypes.test(file.type) || + options.acceptFileTypes.test(file.name))) { + file.error = settings.i18n('acceptFileTypes'); + } else if (options.maxFileSize && file.size > + options.maxFileSize) { + file.error = settings.i18n('maxFileSize'); + } else if ($.type(file.size) === 'number' && + file.size < options.minFileSize) { + file.error = settings.i18n('minFileSize'); + } else { + delete file.error; + } + if (file.error || data.files.error) { + data.files.error = true; + dfd.rejectWith(this, [data]); + } else { + dfd.resolveWith(this, [data]); + } + return dfd.promise(); + } + + } + + }); + +})); diff --git a/forms/jquery.fileupload-validate_1.js b/forms/jquery.fileupload-validate_1.js new file mode 100644 index 0000000..ee1c2f2 --- /dev/null +++ b/forms/jquery.fileupload-validate_1.js @@ -0,0 +1,117 @@ +/* + * jQuery File Upload Validation Plugin 1.1.1 + * https://github.com/blueimp/jQuery-File-Upload + * + * Copyright 2013, Sebastian Tschan + * https://blueimp.net + * + * Licensed under the MIT license: + * http://www.opensource.org/licenses/MIT + */ + +/*jslint nomen: true, unparam: true, regexp: true */ +/*global define, window */ + +(function (factory) { + 'use strict'; + if (typeof define === 'function' && define.amd) { + // Register as an anonymous AMD module: + define([ + 'jquery', + './jquery.fileupload-process' + ], factory); + } else { + // Browser globals: + factory( + window.jQuery + ); + } +}(function ($) { + 'use strict'; + + // Append to the default processQueue: + $.blueimp.fileupload.prototype.options.processQueue.push( + { + action: 'validate', + // Always trigger this action, + // even if the previous action was rejected: + always: true, + // Options taken from the global options map: + acceptFileTypes: '@', + maxFileSize: '@', + minFileSize: '@', + maxNumberOfFiles: '@', + disabled: '@disableValidation' + } + ); + + // The File Upload Validation plugin extends the fileupload widget + // with file validation functionality: + $.widget('blueimp.fileupload', $.blueimp.fileupload, { + + options: { + /* + // The regular expression for allowed file types, matches + // against either file type or file name: + acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i, + // The maximum allowed file size in bytes: + maxFileSize: 10000000, // 10 MB + // The minimum allowed file size in bytes: + minFileSize: undefined, // No minimal file size + // The limit of files to be uploaded: + maxNumberOfFiles: 10, + */ + + // Function returning the current number of files, + // has to be overriden for maxNumberOfFiles validation: + getNumberOfFiles: $.noop, + + // Error and info messages: + messages: { + maxNumberOfFiles: 'Maximum number of files exceeded', + acceptFileTypes: 'File type not allowed', + maxFileSize: 'File is too large', + minFileSize: 'File is too small' + } + }, + + processActions: { + + validate: function (data, options) { + if (options.disabled) { + return data; + } + var dfd = $.Deferred(), + settings = this.options, + file = data.files[data.index]; + if ($.type(options.maxNumberOfFiles) === 'number' && + (settings.getNumberOfFiles() || 0) + data.files.length > + options.maxNumberOfFiles) { + file.error = settings.i18n('maxNumberOfFiles'); + } else if (options.acceptFileTypes && + !(options.acceptFileTypes.test(file.type) || + options.acceptFileTypes.test(file.name))) { + file.error = settings.i18n('acceptFileTypes'); + } else if (options.maxFileSize && file.size > + options.maxFileSize) { + file.error = settings.i18n('maxFileSize'); + } else if ($.type(file.size) === 'number' && + file.size < options.minFileSize) { + file.error = settings.i18n('minFileSize'); + } else { + delete file.error; + } + if (file.error || data.files.error) { + data.files.error = true; + dfd.rejectWith(this, [data]); + } else { + dfd.resolveWith(this, [data]); + } + return dfd.promise(); + } + + } + + }); + +})); diff --git a/forms/jquery.fileupload.js b/forms/jquery.fileupload.js new file mode 100644 index 0000000..a39958a --- /dev/null +++ b/forms/jquery.fileupload.js @@ -0,0 +1,1368 @@ +/* + * jQuery File Upload Plugin 5.34.0 + * https://github.com/blueimp/jQuery-File-Upload + * + * Copyright 2010, Sebastian Tschan + * https://blueimp.net + * + * Licensed under the MIT license: + * http://www.opensource.org/licenses/MIT + */ + +/*jslint nomen: true, unparam: true, regexp: true */ +/*global define, window, document, location, File, Blob, FormData */ + +(function (factory) { + 'use strict'; + if (typeof define === 'function' && define.amd) { + // Register as an anonymous AMD module: + define([ + 'jquery', + 'jquery.ui.widget' + ], factory); + } else { + // Browser globals: + factory(window.jQuery); + } +}(function ($) { + 'use strict'; + + // Detect file input support, based on + // http://viljamis.com/blog/2012/file-upload-support-on-mobile/ + $.support.fileInput = !(new RegExp( + // Handle devices which give false positives for the feature detection: + '(Android (1\\.[0156]|2\\.[01]))' + + '|(Windows Phone (OS 7|8\\.0))|(XBLWP)|(ZuneWP)|(WPDesktop)' + + '|(w(eb)?OSBrowser)|(webOS)' + + '|(Kindle/(1\\.0|2\\.[05]|3\\.0))' + ).test(window.navigator.userAgent) || + // Feature detection for all other devices: + $('').prop('disabled')); + + // The FileReader API is not actually used, but works as feature detection, + // as e.g. Safari supports XHR file uploads via the FormData API, + // but not non-multipart XHR file uploads: + $.support.xhrFileUpload = !!(window.XMLHttpRequestUpload && window.FileReader); + $.support.xhrFormDataFileUpload = !!window.FormData; + + // Detect support for Blob slicing (required for chunked uploads): + $.support.blobSlice = window.Blob && (Blob.prototype.slice || + Blob.prototype.webkitSlice || Blob.prototype.mozSlice); + + // The fileupload widget listens for change events on file input fields defined + // via fileInput setting and paste or drop events of the given dropZone. + // In addition to the default jQuery Widget methods, the fileupload widget + // exposes the "add" and "send" methods, to add or directly send files using + // the fileupload API. + // By default, files added via file input selection, paste, drag & drop or + // "add" method are uploaded immediately, but it is possible to override + // the "add" callback option to queue file uploads. + $.widget('blueimp.fileupload', { + + options: { + // The drop target element(s), by the default the complete document. + // Set to null to disable drag & drop support: + dropZone: $(document), + // The paste target element(s), by the default the complete document. + // Set to null to disable paste support: + pasteZone: $(document), + // The file input field(s), that are listened to for change events. + // If undefined, it is set to the file input fields inside + // of the widget element on plugin initialization. + // Set to null to disable the change listener. + fileInput: undefined, + // By default, the file input field is replaced with a clone after + // each input field change event. This is required for iframe transport + // queues and allows change events to be fired for the same file + // selection, but can be disabled by setting the following option to false: + replaceFileInput: true, + // The parameter name for the file form data (the request argument name). + // If undefined or empty, the name property of the file input field is + // used, or "files[]" if the file input name property is also empty, + // can be a string or an array of strings: + paramName: undefined, + // By default, each file of a selection is uploaded using an individual + // request for XHR type uploads. Set to false to upload file + // selections in one request each: + singleFileUploads: true, + // To limit the number of files uploaded with one XHR request, + // set the following option to an integer greater than 0: + limitMultiFileUploads: undefined, + // Set the following option to true to issue all file upload requests + // in a sequential order: + sequentialUploads: false, + // To limit the number of concurrent uploads, + // set the following option to an integer greater than 0: + limitConcurrentUploads: undefined, + // Set the following option to true to force iframe transport uploads: + forceIframeTransport: false, + // Set the following option to the location of a redirect url on the + // origin server, for cross-domain iframe transport uploads: + redirect: undefined, + // The parameter name for the redirect url, sent as part of the form + // data and set to 'redirect' if this option is empty: + redirectParamName: undefined, + // Set the following option to the location of a postMessage window, + // to enable postMessage transport uploads: + postMessage: undefined, + // By default, XHR file uploads are sent as multipart/form-data. + // The iframe transport is always using multipart/form-data. + // Set to false to enable non-multipart XHR uploads: + multipart: true, + // To upload large files in smaller chunks, set the following option + // to a preferred maximum chunk size. If set to 0, null or undefined, + // or the browser does not support the required Blob API, files will + // be uploaded as a whole. + maxChunkSize: undefined, + // When a non-multipart upload or a chunked multipart upload has been + // aborted, this option can be used to resume the upload by setting + // it to the size of the already uploaded bytes. This option is most + // useful when modifying the options object inside of the "add" or + // "send" callbacks, as the options are cloned for each file upload. + uploadedBytes: undefined, + // By default, failed (abort or error) file uploads are removed from the + // global progress calculation. Set the following option to false to + // prevent recalculating the global progress data: + recalculateProgress: true, + // Interval in milliseconds to calculate and trigger progress events: + progressInterval: 100, + // Interval in milliseconds to calculate progress bitrate: + bitrateInterval: 500, + // By default, uploads are started automatically when adding files: + autoUpload: true, + + // Error and info messages: + messages: { + uploadedBytes: 'Uploaded bytes exceed file size' + }, + + // Translation function, gets the message key to be translated + // and an object with context specific data as arguments: + i18n: function (message, context) { + message = this.messages[message] || message.toString(); + if (context) { + $.each(context, function (key, value) { + message = message.replace('{' + key + '}', value); + }); + } + return message; + }, + + // Additional form data to be sent along with the file uploads can be set + // using this option, which accepts an array of objects with name and + // value properties, a function returning such an array, a FormData + // object (for XHR file uploads), or a simple object. + // The form of the first fileInput is given as parameter to the function: + formData: function (form) { + return form.serializeArray(); + }, + + // The add callback is invoked as soon as files are added to the fileupload + // widget (via file input selection, drag & drop, paste or add API call). + // If the singleFileUploads option is enabled, this callback will be + // called once for each file in the selection for XHR file uploads, else + // once for each file selection. + // + // The upload starts when the submit method is invoked on the data parameter. + // The data object contains a files property holding the added files + // and allows you to override plugin options as well as define ajax settings. + // + // Listeners for this callback can also be bound the following way: + // .bind('fileuploadadd', func); + // + // data.submit() returns a Promise object and allows to attach additional + // handlers using jQuery's Deferred callbacks: + // data.submit().done(func).fail(func).always(func); + add: function (e, data) { + if (e.isDefaultPrevented()) { + return false; + } + if (data.autoUpload || (data.autoUpload !== false && + $(this).fileupload('option', 'autoUpload'))) { + data.process().done(function () { + data.submit(); + }); + } + }, + + // Other callbacks: + + // Callback for the submit event of each file upload: + // submit: function (e, data) {}, // .bind('fileuploadsubmit', func); + + // Callback for the start of each file upload request: + // send: function (e, data) {}, // .bind('fileuploadsend', func); + + // Callback for successful uploads: + // done: function (e, data) {}, // .bind('fileuploaddone', func); + + // Callback for failed (abort or error) uploads: + // fail: function (e, data) {}, // .bind('fileuploadfail', func); + + // Callback for completed (success, abort or error) requests: + // always: function (e, data) {}, // .bind('fileuploadalways', func); + + // Callback for upload progress events: + // progress: function (e, data) {}, // .bind('fileuploadprogress', func); + + // Callback for global upload progress events: + // progressall: function (e, data) {}, // .bind('fileuploadprogressall', func); + + // Callback for uploads start, equivalent to the global ajaxStart event: + // start: function (e) {}, // .bind('fileuploadstart', func); + + // Callback for uploads stop, equivalent to the global ajaxStop event: + // stop: function (e) {}, // .bind('fileuploadstop', func); + + // Callback for change events of the fileInput(s): + // change: function (e, data) {}, // .bind('fileuploadchange', func); + + // Callback for paste events to the pasteZone(s): + // paste: function (e, data) {}, // .bind('fileuploadpaste', func); + + // Callback for drop events of the dropZone(s): + // drop: function (e, data) {}, // .bind('fileuploaddrop', func); + + // Callback for dragover events of the dropZone(s): + // dragover: function (e) {}, // .bind('fileuploaddragover', func); + + // Callback for the start of each chunk upload request: + // chunksend: function (e, data) {}, // .bind('fileuploadchunksend', func); + + // Callback for successful chunk uploads: + // chunkdone: function (e, data) {}, // .bind('fileuploadchunkdone', func); + + // Callback for failed (abort or error) chunk uploads: + // chunkfail: function (e, data) {}, // .bind('fileuploadchunkfail', func); + + // Callback for completed (success, abort or error) chunk upload requests: + // chunkalways: function (e, data) {}, // .bind('fileuploadchunkalways', func); + + // The plugin options are used as settings object for the ajax calls. + // The following are jQuery ajax settings required for the file uploads: + processData: false, + contentType: false, + cache: false + }, + + // A list of options that require reinitializing event listeners and/or + // special initialization code: + _specialOptions: [ + 'fileInput', + 'dropZone', + 'pasteZone', + 'multipart', + 'forceIframeTransport' + ], + + _blobSlice: $.support.blobSlice && function () { + var slice = this.slice || this.webkitSlice || this.mozSlice; + return slice.apply(this, arguments); + }, + + _BitrateTimer: function () { + this.timestamp = ((Date.now) ? Date.now() : (new Date()).getTime()); + this.loaded = 0; + this.bitrate = 0; + this.getBitrate = function (now, loaded, interval) { + var timeDiff = now - this.timestamp; + if (!this.bitrate || !interval || timeDiff > interval) { + this.bitrate = (loaded - this.loaded) * (1000 / timeDiff) * 8; + this.loaded = loaded; + this.timestamp = now; + } + return this.bitrate; + }; + }, + + _isXHRUpload: function (options) { + return !options.forceIframeTransport && + ((!options.multipart && $.support.xhrFileUpload) || + $.support.xhrFormDataFileUpload); + }, + + _getFormData: function (options) { + var formData; + if (typeof options.formData === 'function') { + return options.formData(options.form); + } + if ($.isArray(options.formData)) { + return options.formData; + } + if ($.type(options.formData) === 'object') { + formData = []; + $.each(options.formData, function (name, value) { + formData.push({name: name, value: value}); + }); + return formData; + } + return []; + }, + + _getTotal: function (files) { + var total = 0; + $.each(files, function (index, file) { + total += file.size || 1; + }); + return total; + }, + + _initProgressObject: function (obj) { + var progress = { + loaded: 0, + total: 0, + bitrate: 0 + }; + if (obj._progress) { + $.extend(obj._progress, progress); + } else { + obj._progress = progress; + } + }, + + _initResponseObject: function (obj) { + var prop; + if (obj._response) { + for (prop in obj._response) { + if (obj._response.hasOwnProperty(prop)) { + delete obj._response[prop]; + } + } + } else { + obj._response = {}; + } + }, + + _onProgress: function (e, data) { + if (e.lengthComputable) { + var now = ((Date.now) ? Date.now() : (new Date()).getTime()), + loaded; + if (data._time && data.progressInterval && + (now - data._time < data.progressInterval) && + e.loaded !== e.total) { + return; + } + data._time = now; + loaded = Math.floor( + e.loaded / e.total * (data.chunkSize || data._progress.total) + ) + (data.uploadedBytes || 0); + // Add the difference from the previously loaded state + // to the global loaded counter: + this._progress.loaded += (loaded - data._progress.loaded); + this._progress.bitrate = this._bitrateTimer.getBitrate( + now, + this._progress.loaded, + data.bitrateInterval + ); + data._progress.loaded = data.loaded = loaded; + data._progress.bitrate = data.bitrate = data._bitrateTimer.getBitrate( + now, + loaded, + data.bitrateInterval + ); + // Trigger a custom progress event with a total data property set + // to the file size(s) of the current upload and a loaded data + // property calculated accordingly: + this._trigger( + 'progress', + $.Event('progress', {delegatedEvent: e}), + data + ); + // Trigger a global progress event for all current file uploads, + // including ajax calls queued for sequential file uploads: + this._trigger( + 'progressall', + $.Event('progressall', {delegatedEvent: e}), + this._progress + ); + } + }, + + _initProgressListener: function (options) { + var that = this, + xhr = options.xhr ? options.xhr() : $.ajaxSettings.xhr(); + // Accesss to the native XHR object is required to add event listeners + // for the upload progress event: + if (xhr.upload) { + $(xhr.upload).bind('progress', function (e) { + var oe = e.originalEvent; + // Make sure the progress event properties get copied over: + e.lengthComputable = oe.lengthComputable; + e.loaded = oe.loaded; + e.total = oe.total; + that._onProgress(e, options); + }); + options.xhr = function () { + return xhr; + }; + } + }, + + _isInstanceOf: function (type, obj) { + // Cross-frame instanceof check + return Object.prototype.toString.call(obj) === '[object ' + type + ']'; + }, + + _initXHRData: function (options) { + var that = this, + formData, + file = options.files[0], + // Ignore non-multipart setting if not supported: + multipart = options.multipart || !$.support.xhrFileUpload, + paramName = options.paramName[0]; + options.headers = $.extend({}, options.headers); + if (options.contentRange) { + options.headers['Content-Range'] = options.contentRange; + } + if (!multipart || options.blob || !this._isInstanceOf('File', file)) { + options.headers['Content-Disposition'] = 'attachment; filename="' + + encodeURI(file.name) + '"'; + } + if (!multipart) { + options.contentType = file.type; + options.data = options.blob || file; + } else if ($.support.xhrFormDataFileUpload) { + if (options.postMessage) { + // window.postMessage does not allow sending FormData + // objects, so we just add the File/Blob objects to + // the formData array and let the postMessage window + // create the FormData object out of this array: + formData = this._getFormData(options); + if (options.blob) { + formData.push({ + name: paramName, + value: options.blob + }); + } else { + $.each(options.files, function (index, file) { + formData.push({ + name: options.paramName[index] || paramName, + value: file + }); + }); + } + } else { + if (that._isInstanceOf('FormData', options.formData)) { + formData = options.formData; + } else { + formData = new FormData(); + $.each(this._getFormData(options), function (index, field) { + formData.append(field.name, field.value); + }); + } + if (options.blob) { + formData.append(paramName, options.blob, file.name); + } else { + $.each(options.files, function (index, file) { + // This check allows the tests to run with + // dummy objects: + if (that._isInstanceOf('File', file) || + that._isInstanceOf('Blob', file)) { + formData.append( + options.paramName[index] || paramName, + file, + file.name + ); + } + }); + } + } + options.data = formData; + } + // Blob reference is not needed anymore, free memory: + options.blob = null; + }, + + _initIframeSettings: function (options) { + var targetHost = $('').prop('href', options.url).prop('host'); + // Setting the dataType to iframe enables the iframe transport: + options.dataType = 'iframe ' + (options.dataType || ''); + // The iframe transport accepts a serialized array as form data: + options.formData = this._getFormData(options); + // Add redirect url to form data on cross-domain uploads: + if (options.redirect && targetHost && targetHost !== location.host) { + options.formData.push({ + name: options.redirectParamName || 'redirect', + value: options.redirect + }); + } + }, + + _initDataSettings: function (options) { + if (this._isXHRUpload(options)) { + if (!this._chunkedUpload(options, true)) { + if (!options.data) { + this._initXHRData(options); + } + this._initProgressListener(options); + } + if (options.postMessage) { + // Setting the dataType to postmessage enables the + // postMessage transport: + options.dataType = 'postmessage ' + (options.dataType || ''); + } + } else { + this._initIframeSettings(options); + } + }, + + _getParamName: function (options) { + var fileInput = $(options.fileInput), + paramName = options.paramName; + if (!paramName) { + paramName = []; + fileInput.each(function () { + var input = $(this), + name = input.prop('name') || 'files[]', + i = (input.prop('files') || [1]).length; + while (i) { + paramName.push(name); + i -= 1; + } + }); + if (!paramName.length) { + paramName = [fileInput.prop('name') || 'files[]']; + } + } else if (!$.isArray(paramName)) { + paramName = [paramName]; + } + return paramName; + }, + + _initFormSettings: function (options) { + // Retrieve missing options from the input field and the + // associated form, if available: + if (!options.form || !options.form.length) { + options.form = $(options.fileInput.prop('form')); + // If the given file input doesn't have an associated form, + // use the default widget file input's form: + if (!options.form.length) { + options.form = $(this.options.fileInput.prop('form')); + } + } + options.paramName = this._getParamName(options); + if (!options.url) { + options.url = options.form.prop('action') || location.href; + } + // The HTTP request method must be "POST" or "PUT": + options.type = (options.type || + ($.type(options.form.prop('method')) === 'string' && + options.form.prop('method')) || '' + ).toUpperCase(); + if (options.type !== 'POST' && options.type !== 'PUT' && + options.type !== 'PATCH') { + options.type = 'POST'; + } + if (!options.formAcceptCharset) { + options.formAcceptCharset = options.form.attr('accept-charset'); + } + }, + + _getAJAXSettings: function (data) { + var options = $.extend({}, this.options, data); + this._initFormSettings(options); + this._initDataSettings(options); + options.url = options.url+'&rand=' + new Date().getTime(); + return options; + }, + + // jQuery 1.6 doesn't provide .state(), + // while jQuery 1.8+ removed .isRejected() and .isResolved(): + _getDeferredState: function (deferred) { + if (deferred.state) { + return deferred.state(); + } + if (deferred.isResolved()) { + return 'resolved'; + } + if (deferred.isRejected()) { + return 'rejected'; + } + return 'pending'; + }, + + // Maps jqXHR callbacks to the equivalent + // methods of the given Promise object: + _enhancePromise: function (promise) { + promise.success = promise.done; + promise.error = promise.fail; + promise.complete = promise.always; + return promise; + }, + + // Creates and returns a Promise object enhanced with + // the jqXHR methods abort, success, error and complete: + _getXHRPromise: function (resolveOrReject, context, args) { + var dfd = $.Deferred(), + promise = dfd.promise(); + context = context || this.options.context || promise; + if (resolveOrReject === true) { + dfd.resolveWith(context, args); + } else if (resolveOrReject === false) { + dfd.rejectWith(context, args); + } + promise.abort = dfd.promise; + return this._enhancePromise(promise); + }, + + // Adds convenience methods to the data callback argument: + _addConvenienceMethods: function (e, data) { + var that = this, + getPromise = function (data) { + return $.Deferred().resolveWith(that, [data]).promise(); + }; + data.process = function (resolveFunc, rejectFunc) { + if (resolveFunc || rejectFunc) { + data._processQueue = this._processQueue = + (this._processQueue || getPromise(this)) + .pipe(resolveFunc, rejectFunc); + } + return this._processQueue || getPromise(this); + }; + data.submit = function () { + if (this.state() !== 'pending') { + data.jqXHR = this.jqXHR = + (that._trigger( + 'submit', + $.Event('submit', {delegatedEvent: e}), + this + ) !== false) && that._onSend(e, this); + } + return this.jqXHR || that._getXHRPromise(); + }; + data.abort = function () { + if (this.jqXHR) { + return this.jqXHR.abort(); + } + return that._getXHRPromise(); + }; + data.state = function () { + if (this.jqXHR) { + return that._getDeferredState(this.jqXHR); + } + if (this._processQueue) { + return that._getDeferredState(this._processQueue); + } + }; + data.progress = function () { + return this._progress; + }; + data.response = function () { + return this._response; + }; + }, + + // Parses the Range header from the server response + // and returns the uploaded bytes: + _getUploadedBytes: function (jqXHR) { + var range = jqXHR.getResponseHeader('Range'), + parts = range && range.split('-'), + upperBytesPos = parts && parts.length > 1 && + parseInt(parts[1], 10); + return upperBytesPos && upperBytesPos + 1; + }, + + // Uploads a file in multiple, sequential requests + // by splitting the file up in multiple blob chunks. + // If the second parameter is true, only tests if the file + // should be uploaded in chunks, but does not invoke any + // upload requests: + _chunkedUpload: function (options, testOnly) { + options.uploadedBytes = options.uploadedBytes || 0; + var that = this, + file = options.files[0], + fs = file.size, + ub = options.uploadedBytes, + mcs = options.maxChunkSize || fs, + slice = this._blobSlice, + dfd = $.Deferred(), + promise = dfd.promise(), + jqXHR, + upload; + if (!(this._isXHRUpload(options) && slice && (ub || mcs < fs)) || + options.data) { + return false; + } + if (testOnly) { + return true; + } + if (ub >= fs) { + file.error = options.i18n('uploadedBytes'); + return this._getXHRPromise( + false, + options.context, + [null, 'error', file.error] + ); + } + // The chunk upload method: + upload = function () { + // Clone the options object for each chunk upload: + var o = $.extend({}, options), + currentLoaded = o._progress.loaded; + o.blob = slice.call( + file, + ub, + ub + mcs, + file.type + ); + // Store the current chunk size, as the blob itself + // will be dereferenced after data processing: + o.chunkSize = o.blob.size; + // Expose the chunk bytes position range: + o.contentRange = 'bytes ' + ub + '-' + + (ub + o.chunkSize - 1) + '/' + fs; + // Process the upload data (the blob and potential form data): + that._initXHRData(o); + // Add progress listeners for this chunk upload: + that._initProgressListener(o); + jqXHR = ((that._trigger('chunksend', null, o) !== false && $.ajax(o)) || + that._getXHRPromise(false, o.context)) + .done(function (result, textStatus, jqXHR) { + ub = that._getUploadedBytes(jqXHR) || + (ub + o.chunkSize); + // Create a progress event if no final progress event + // with loaded equaling total has been triggered + // for this chunk: + if (currentLoaded + o.chunkSize - o._progress.loaded) { + that._onProgress($.Event('progress', { + lengthComputable: true, + loaded: ub - o.uploadedBytes, + total: ub - o.uploadedBytes + }), o); + } + options.uploadedBytes = o.uploadedBytes = ub; + o.result = result; + o.textStatus = textStatus; + o.jqXHR = jqXHR; + that._trigger('chunkdone', null, o); + that._trigger('chunkalways', null, o); + if (ub < fs) { + // File upload not yet complete, + // continue with the next chunk: + upload(); + } else { + dfd.resolveWith( + o.context, + [result, textStatus, jqXHR] + ); + } + }) + .fail(function (jqXHR, textStatus, errorThrown) { + o.jqXHR = jqXHR; + o.textStatus = textStatus; + o.errorThrown = errorThrown; + that._trigger('chunkfail', null, o); + that._trigger('chunkalways', null, o); + dfd.rejectWith( + o.context, + [jqXHR, textStatus, errorThrown] + ); + }); + }; + this._enhancePromise(promise); + promise.abort = function () { + return jqXHR.abort(); + }; + upload(); + return promise; + }, + + _beforeSend: function (e, data) { + if (this._active === 0) { + // the start callback is triggered when an upload starts + // and no other uploads are currently running, + // equivalent to the global ajaxStart event: + this._trigger('start'); + // Set timer for global bitrate progress calculation: + this._bitrateTimer = new this._BitrateTimer(); + // Reset the global progress values: + this._progress.loaded = this._progress.total = 0; + this._progress.bitrate = 0; + } + // Make sure the container objects for the .response() and + // .progress() methods on the data object are available + // and reset to their initial state: + this._initResponseObject(data); + this._initProgressObject(data); + data._progress.loaded = data.loaded = data.uploadedBytes || 0; + data._progress.total = data.total = this._getTotal(data.files) || 1; + data._progress.bitrate = data.bitrate = 0; + this._active += 1; + // Initialize the global progress values: + this._progress.loaded += data.loaded; + this._progress.total += data.total; + }, + + _onDone: function (result, textStatus, jqXHR, options) { + var total = options._progress.total, + response = options._response; + if (options._progress.loaded < total) { + // Create a progress event if no final progress event + // with loaded equaling total has been triggered: + this._onProgress($.Event('progress', { + lengthComputable: true, + loaded: total, + total: total + }), options); + } + response.result = options.result = result; + response.textStatus = options.textStatus = textStatus; + response.jqXHR = options.jqXHR = jqXHR; + this._trigger('done', null, options); + }, + + _onFail: function (jqXHR, textStatus, errorThrown, options) { + var response = options._response; + if (options.recalculateProgress) { + // Remove the failed (error or abort) file upload from + // the global progress calculation: + this._progress.loaded -= options._progress.loaded; + this._progress.total -= options._progress.total; + } + response.jqXHR = options.jqXHR = jqXHR; + response.textStatus = options.textStatus = textStatus; + response.errorThrown = options.errorThrown = errorThrown; + this._trigger('fail', null, options); + }, + + _onAlways: function (jqXHRorResult, textStatus, jqXHRorError, options) { + // jqXHRorResult, textStatus and jqXHRorError are added to the + // options object via done and fail callbacks + this._trigger('always', null, options); + }, + + _onSend: function (e, data) { + if (!data.submit) { + this._addConvenienceMethods(e, data); + } + var that = this, + jqXHR, + aborted, + slot, + pipe, + options = that._getAJAXSettings(data), + send = function () { + that._sending += 1; + // Set timer for bitrate progress calculation: + options._bitrateTimer = new that._BitrateTimer(); + jqXHR = jqXHR || ( + ((aborted || that._trigger( + 'send', + $.Event('send', {delegatedEvent: e}), + options + ) === false) && + that._getXHRPromise(false, options.context, aborted)) || + that._chunkedUpload(options) || $.ajax(options) + ).done(function (result, textStatus, jqXHR) { + that._onDone(result, textStatus, jqXHR, options); + }).fail(function (jqXHR, textStatus, errorThrown) { + that._onFail(jqXHR, textStatus, errorThrown, options); + }).always(function (jqXHRorResult, textStatus, jqXHRorError) { + that._onAlways( + jqXHRorResult, + textStatus, + jqXHRorError, + options + ); + that._sending -= 1; + that._active -= 1; + if (options.limitConcurrentUploads && + options.limitConcurrentUploads > that._sending) { + // Start the next queued upload, + // that has not been aborted: + var nextSlot = that._slots.shift(); + while (nextSlot) { + if (that._getDeferredState(nextSlot) === 'pending') { + nextSlot.resolve(); + break; + } + nextSlot = that._slots.shift(); + } + } + if (that._active === 0) { + // The stop callback is triggered when all uploads have + // been completed, equivalent to the global ajaxStop event: + that._trigger('stop'); + } + }); + return jqXHR; + }; + this._beforeSend(e, options); + if (this.options.sequentialUploads || + (this.options.limitConcurrentUploads && + this.options.limitConcurrentUploads <= this._sending)) { + if (this.options.limitConcurrentUploads > 1) { + slot = $.Deferred(); + this._slots.push(slot); + pipe = slot.pipe(send); + } else { + this._sequence = this._sequence.pipe(send, send); + pipe = this._sequence; + } + // Return the piped Promise object, enhanced with an abort method, + // which is delegated to the jqXHR object of the current upload, + // and jqXHR callbacks mapped to the equivalent Promise methods: + pipe.abort = function () { + aborted = [undefined, 'abort', 'abort']; + if (!jqXHR) { + if (slot) { + slot.rejectWith(options.context, aborted); + } + return send(); + } + return jqXHR.abort(); + }; + return this._enhancePromise(pipe); + } + return send(); + }, + + _onAdd: function (e, data) { + var that = this, + result = true, + options = $.extend({}, this.options, data), + limit = options.limitMultiFileUploads, + paramName = this._getParamName(options), + paramNameSet, + paramNameSlice, + fileSet, + i; + if (!(options.singleFileUploads || limit) || + !this._isXHRUpload(options)) { + fileSet = [data.files]; + paramNameSet = [paramName]; + } else if (!options.singleFileUploads && limit) { + fileSet = []; + paramNameSet = []; + for (i = 0; i < data.files.length; i += limit) { + fileSet.push(data.files.slice(i, i + limit)); + paramNameSlice = paramName.slice(i, i + limit); + if (!paramNameSlice.length) { + paramNameSlice = paramName; + } + paramNameSet.push(paramNameSlice); + } + } else { + paramNameSet = paramName; + } + data.originalFiles = data.files; + $.each(fileSet || data.files, function (index, element) { + var newData = $.extend({}, data); + newData.files = fileSet ? element : [element]; + newData.paramName = paramNameSet[index]; + that._initResponseObject(newData); + that._initProgressObject(newData); + that._addConvenienceMethods(e, newData); + result = that._trigger( + 'add', + $.Event('add', {delegatedEvent: e}), + newData + ); + return result; + }); + return result; + }, + + _replaceFileInput: function (input) { + var inputClone = input.clone(true); + $('
').append(inputClone)[0].reset(); + // Detaching allows to insert the fileInput on another form + // without loosing the file input value: + input.after(inputClone).detach(); + // Avoid memory leaks with the detached file input: + $.cleanData(input.unbind('remove')); + // Replace the original file input element in the fileInput + // elements set with the clone, which has been copied including + // event handlers: + this.options.fileInput = this.options.fileInput.map(function (i, el) { + if (el === input[0]) { + return inputClone[0]; + } + return el; + }); + // If the widget has been initialized on the file input itself, + // override this.element with the file input clone: + if (input[0] === this.element[0]) { + this.element = inputClone; + } + }, + + _handleFileTreeEntry: function (entry, path) { + var that = this, + dfd = $.Deferred(), + errorHandler = function (e) { + if (e && !e.entry) { + e.entry = entry; + } + // Since $.when returns immediately if one + // Deferred is rejected, we use resolve instead. + // This allows valid files and invalid items + // to be returned together in one set: + dfd.resolve([e]); + }, + dirReader; + path = path || ''; + if (entry.isFile) { + if (entry._file) { + // Workaround for Chrome bug #149735 + entry._file.relativePath = path; + dfd.resolve(entry._file); + } else { + entry.file(function (file) { + file.relativePath = path; + dfd.resolve(file); + }, errorHandler); + } + } else if (entry.isDirectory) { + dirReader = entry.createReader(); + dirReader.readEntries(function (entries) { + that._handleFileTreeEntries( + entries, + path + entry.name + '/' + ).done(function (files) { + dfd.resolve(files); + }).fail(errorHandler); + }, errorHandler); + } else { + // Return an empy list for file system items + // other than files or directories: + dfd.resolve([]); + } + return dfd.promise(); + }, + + _handleFileTreeEntries: function (entries, path) { + var that = this; + return $.when.apply( + $, + $.map(entries, function (entry) { + return that._handleFileTreeEntry(entry, path); + }) + ).pipe(function () { + return Array.prototype.concat.apply( + [], + arguments + ); + }); + }, + + _getDroppedFiles: function (dataTransfer) { + dataTransfer = dataTransfer || {}; + var items = dataTransfer.items; + if (items && items.length && (items[0].webkitGetAsEntry || + items[0].getAsEntry)) { + return this._handleFileTreeEntries( + $.map(items, function (item) { + var entry; + if (item.webkitGetAsEntry) { + entry = item.webkitGetAsEntry(); + if (entry) { + // Workaround for Chrome bug #149735: + entry._file = item.getAsFile(); + } + return entry; + } + return item.getAsEntry(); + }) + ); + } + return $.Deferred().resolve( + $.makeArray(dataTransfer.files) + ).promise(); + }, + + _getSingleFileInputFiles: function (fileInput) { + fileInput = $(fileInput); + var entries = fileInput.prop('webkitEntries') || + fileInput.prop('entries'), + files, + value; + if (entries && entries.length) { + return this._handleFileTreeEntries(entries); + } + files = $.makeArray(fileInput.prop('files')); + if (!files.length) { + value = fileInput.prop('value'); + if (!value) { + return $.Deferred().resolve([]).promise(); + } + // If the files property is not available, the browser does not + // support the File API and we add a pseudo File object with + // the input value as name with path information removed: + files = [{name: value.replace(/^.*\\/, '')}]; + } else if (files[0].name === undefined && files[0].fileName) { + // File normalization for Safari 4 and Firefox 3: + $.each(files, function (index, file) { + file.name = file.fileName; + file.size = file.fileSize; + }); + } + return $.Deferred().resolve(files).promise(); + }, + + _getFileInputFiles: function (fileInput) { + if (!(fileInput instanceof $) || fileInput.length === 1) { + return this._getSingleFileInputFiles(fileInput); + } + return $.when.apply( + $, + $.map(fileInput, this._getSingleFileInputFiles) + ).pipe(function () { + return Array.prototype.concat.apply( + [], + arguments + ); + }); + }, + + _onChange: function (e) { + var that = this, + data = { + fileInput: $(e.target), + form: $(e.target.form) + }; + this._getFileInputFiles(data.fileInput).always(function (files) { + data.files = files; + if (that.options.replaceFileInput) { + that._replaceFileInput(data.fileInput); + } + if (that._trigger( + 'change', + $.Event('change', {delegatedEvent: e}), + data + ) !== false) { + that._onAdd(e, data); + } + }); + }, + + _onPaste: function (e) { + var items = e.originalEvent && e.originalEvent.clipboardData && + e.originalEvent.clipboardData.items, + data = {files: []}; + if (items && items.length) { + $.each(items, function (index, item) { + var file = item.getAsFile && item.getAsFile(); + if (file) { + data.files.push(file); + } + }); + if (this._trigger( + 'paste', + $.Event('paste', {delegatedEvent: e}), + data + ) !== false) { + this._onAdd(e, data); + } + } + }, + + _onDrop: function (e) { + e.dataTransfer = e.originalEvent && e.originalEvent.dataTransfer; + var that = this, + dataTransfer = e.dataTransfer, + data = {}; + if (dataTransfer && dataTransfer.files && dataTransfer.files.length) { + e.preventDefault(); + this._getDroppedFiles(dataTransfer).always(function (files) { + data.files = files; + if (that._trigger( + 'drop', + $.Event('drop', {delegatedEvent: e}), + data + ) !== false) { + that._onAdd(e, data); + } + }); + } + }, + + _onDragOver: function (e) { + e.dataTransfer = e.originalEvent && e.originalEvent.dataTransfer; + var dataTransfer = e.dataTransfer; + if (dataTransfer && $.inArray('Files', dataTransfer.types) !== -1 && + this._trigger( + 'dragover', + $.Event('dragover', {delegatedEvent: e}) + ) !== false) { + e.preventDefault(); + dataTransfer.dropEffect = 'copy'; + } + }, + + _initEventHandlers: function () { + if (this._isXHRUpload(this.options)) { + this._on(this.options.dropZone, { + dragover: this._onDragOver, + drop: this._onDrop + }); + this._on(this.options.pasteZone, { + paste: this._onPaste + }); + } + if ($.support.fileInput) { + this._on(this.options.fileInput, { + change: this._onChange + }); + } + }, + + _destroyEventHandlers: function () { + this._off(this.options.dropZone, 'dragover drop'); + this._off(this.options.pasteZone, 'paste'); + this._off(this.options.fileInput, 'change'); + }, + + _setOption: function (key, value) { + var reinit = $.inArray(key, this._specialOptions) !== -1; + if (reinit) { + this._destroyEventHandlers(); + } + this._super(key, value); + if (reinit) { + this._initSpecialOptions(); + this._initEventHandlers(); + } + }, + + _initSpecialOptions: function () { + var options = this.options; + if (options.fileInput === undefined) { + options.fileInput = this.element.is('input[type="file"]') ? + this.element : this.element.find('input[type="file"]'); + } else if (!(options.fileInput instanceof $)) { + options.fileInput = $(options.fileInput); + } + if (!(options.dropZone instanceof $)) { + options.dropZone = $(options.dropZone); + } + if (!(options.pasteZone instanceof $)) { + options.pasteZone = $(options.pasteZone); + } + }, + + _getRegExp: function (str) { + var parts = str.split('/'), + modifiers = parts.pop(); + parts.shift(); + return new RegExp(parts.join('/'), modifiers); + }, + + _isRegExpOption: function (key, value) { + return key !== 'url' && $.type(value) === 'string' && + /^\/.*\/[igm]{0,3}$/.test(value); + }, + + _initDataAttributes: function () { + var that = this, + options = this.options; + // Initialize options set via HTML5 data-attributes: + $.each( + $(this.element[0].cloneNode(false)).data(), + function (key, value) { + if (that._isRegExpOption(key, value)) { + value = that._getRegExp(value); + } + options[key] = value; + } + ); + }, + + _create: function () { + this._initDataAttributes(); + this._initSpecialOptions(); + this._slots = []; + this._sequence = this._getXHRPromise(true); + this._sending = this._active = 0; + this._initProgressObject(this); + this._initEventHandlers(); + }, + + // This method is exposed to the widget API and allows to query + // the number of active uploads: + active: function () { + return this._active; + }, + + // This method is exposed to the widget API and allows to query + // the widget upload progress. + // It returns an object with loaded, total and bitrate properties + // for the running uploads: + progress: function () { + return this._progress; + }, + + // This method is exposed to the widget API and allows adding files + // using the fileupload API. The data parameter accepts an object which + // must have a files property and can contain additional options: + // .fileupload('add', {files: filesList}); + add: function (data) { + var that = this; + if (!data || this.options.disabled) { + return; + } + if (data.fileInput && !data.files) { + this._getFileInputFiles(data.fileInput).always(function (files) { + data.files = files; + that._onAdd(null, data); + }); + } else { + data.files = $.makeArray(data.files); + this._onAdd(null, data); + } + }, + + // This method is exposed to the widget API and allows sending files + // using the fileupload API. The data parameter accepts an object which + // must have a files or fileInput property and can contain additional options: + // .fileupload('send', {files: filesList}); + // The method returns a Promise object for the file upload call. + send: function (data) { + if (data && !this.options.disabled) { + if (data.fileInput && !data.files) { + var that = this, + dfd = $.Deferred(), + promise = dfd.promise(), + jqXHR, + aborted; + promise.abort = function () { + aborted = true; + if (jqXHR) { + return jqXHR.abort(); + } + dfd.reject(null, 'abort', 'abort'); + return promise; + }; + this._getFileInputFiles(data.fileInput).always( + function (files) { + if (aborted) { + return; + } + if (!files.length) { + dfd.reject(); + return; + } + data.files = files; + jqXHR = that._onSend(null, data).then( + function (result, textStatus, jqXHR) { + dfd.resolve(result, textStatus, jqXHR); + }, + function (jqXHR, textStatus, errorThrown) { + dfd.reject(jqXHR, textStatus, errorThrown); + } + ); + } + ); + return this._enhancePromise(promise); + } + data.files = $.makeArray(data.files); + if (data.files.length) { + return this._onSend(null, data); + } + } + return this._getXHRPromise(false, data && data.context); + } + + }); + +})); diff --git a/forms/jquery.fileupload_1.js b/forms/jquery.fileupload_1.js new file mode 100644 index 0000000..a39958a --- /dev/null +++ b/forms/jquery.fileupload_1.js @@ -0,0 +1,1368 @@ +/* + * jQuery File Upload Plugin 5.34.0 + * https://github.com/blueimp/jQuery-File-Upload + * + * Copyright 2010, Sebastian Tschan + * https://blueimp.net + * + * Licensed under the MIT license: + * http://www.opensource.org/licenses/MIT + */ + +/*jslint nomen: true, unparam: true, regexp: true */ +/*global define, window, document, location, File, Blob, FormData */ + +(function (factory) { + 'use strict'; + if (typeof define === 'function' && define.amd) { + // Register as an anonymous AMD module: + define([ + 'jquery', + 'jquery.ui.widget' + ], factory); + } else { + // Browser globals: + factory(window.jQuery); + } +}(function ($) { + 'use strict'; + + // Detect file input support, based on + // http://viljamis.com/blog/2012/file-upload-support-on-mobile/ + $.support.fileInput = !(new RegExp( + // Handle devices which give false positives for the feature detection: + '(Android (1\\.[0156]|2\\.[01]))' + + '|(Windows Phone (OS 7|8\\.0))|(XBLWP)|(ZuneWP)|(WPDesktop)' + + '|(w(eb)?OSBrowser)|(webOS)' + + '|(Kindle/(1\\.0|2\\.[05]|3\\.0))' + ).test(window.navigator.userAgent) || + // Feature detection for all other devices: + $('').prop('disabled')); + + // The FileReader API is not actually used, but works as feature detection, + // as e.g. Safari supports XHR file uploads via the FormData API, + // but not non-multipart XHR file uploads: + $.support.xhrFileUpload = !!(window.XMLHttpRequestUpload && window.FileReader); + $.support.xhrFormDataFileUpload = !!window.FormData; + + // Detect support for Blob slicing (required for chunked uploads): + $.support.blobSlice = window.Blob && (Blob.prototype.slice || + Blob.prototype.webkitSlice || Blob.prototype.mozSlice); + + // The fileupload widget listens for change events on file input fields defined + // via fileInput setting and paste or drop events of the given dropZone. + // In addition to the default jQuery Widget methods, the fileupload widget + // exposes the "add" and "send" methods, to add or directly send files using + // the fileupload API. + // By default, files added via file input selection, paste, drag & drop or + // "add" method are uploaded immediately, but it is possible to override + // the "add" callback option to queue file uploads. + $.widget('blueimp.fileupload', { + + options: { + // The drop target element(s), by the default the complete document. + // Set to null to disable drag & drop support: + dropZone: $(document), + // The paste target element(s), by the default the complete document. + // Set to null to disable paste support: + pasteZone: $(document), + // The file input field(s), that are listened to for change events. + // If undefined, it is set to the file input fields inside + // of the widget element on plugin initialization. + // Set to null to disable the change listener. + fileInput: undefined, + // By default, the file input field is replaced with a clone after + // each input field change event. This is required for iframe transport + // queues and allows change events to be fired for the same file + // selection, but can be disabled by setting the following option to false: + replaceFileInput: true, + // The parameter name for the file form data (the request argument name). + // If undefined or empty, the name property of the file input field is + // used, or "files[]" if the file input name property is also empty, + // can be a string or an array of strings: + paramName: undefined, + // By default, each file of a selection is uploaded using an individual + // request for XHR type uploads. Set to false to upload file + // selections in one request each: + singleFileUploads: true, + // To limit the number of files uploaded with one XHR request, + // set the following option to an integer greater than 0: + limitMultiFileUploads: undefined, + // Set the following option to true to issue all file upload requests + // in a sequential order: + sequentialUploads: false, + // To limit the number of concurrent uploads, + // set the following option to an integer greater than 0: + limitConcurrentUploads: undefined, + // Set the following option to true to force iframe transport uploads: + forceIframeTransport: false, + // Set the following option to the location of a redirect url on the + // origin server, for cross-domain iframe transport uploads: + redirect: undefined, + // The parameter name for the redirect url, sent as part of the form + // data and set to 'redirect' if this option is empty: + redirectParamName: undefined, + // Set the following option to the location of a postMessage window, + // to enable postMessage transport uploads: + postMessage: undefined, + // By default, XHR file uploads are sent as multipart/form-data. + // The iframe transport is always using multipart/form-data. + // Set to false to enable non-multipart XHR uploads: + multipart: true, + // To upload large files in smaller chunks, set the following option + // to a preferred maximum chunk size. If set to 0, null or undefined, + // or the browser does not support the required Blob API, files will + // be uploaded as a whole. + maxChunkSize: undefined, + // When a non-multipart upload or a chunked multipart upload has been + // aborted, this option can be used to resume the upload by setting + // it to the size of the already uploaded bytes. This option is most + // useful when modifying the options object inside of the "add" or + // "send" callbacks, as the options are cloned for each file upload. + uploadedBytes: undefined, + // By default, failed (abort or error) file uploads are removed from the + // global progress calculation. Set the following option to false to + // prevent recalculating the global progress data: + recalculateProgress: true, + // Interval in milliseconds to calculate and trigger progress events: + progressInterval: 100, + // Interval in milliseconds to calculate progress bitrate: + bitrateInterval: 500, + // By default, uploads are started automatically when adding files: + autoUpload: true, + + // Error and info messages: + messages: { + uploadedBytes: 'Uploaded bytes exceed file size' + }, + + // Translation function, gets the message key to be translated + // and an object with context specific data as arguments: + i18n: function (message, context) { + message = this.messages[message] || message.toString(); + if (context) { + $.each(context, function (key, value) { + message = message.replace('{' + key + '}', value); + }); + } + return message; + }, + + // Additional form data to be sent along with the file uploads can be set + // using this option, which accepts an array of objects with name and + // value properties, a function returning such an array, a FormData + // object (for XHR file uploads), or a simple object. + // The form of the first fileInput is given as parameter to the function: + formData: function (form) { + return form.serializeArray(); + }, + + // The add callback is invoked as soon as files are added to the fileupload + // widget (via file input selection, drag & drop, paste or add API call). + // If the singleFileUploads option is enabled, this callback will be + // called once for each file in the selection for XHR file uploads, else + // once for each file selection. + // + // The upload starts when the submit method is invoked on the data parameter. + // The data object contains a files property holding the added files + // and allows you to override plugin options as well as define ajax settings. + // + // Listeners for this callback can also be bound the following way: + // .bind('fileuploadadd', func); + // + // data.submit() returns a Promise object and allows to attach additional + // handlers using jQuery's Deferred callbacks: + // data.submit().done(func).fail(func).always(func); + add: function (e, data) { + if (e.isDefaultPrevented()) { + return false; + } + if (data.autoUpload || (data.autoUpload !== false && + $(this).fileupload('option', 'autoUpload'))) { + data.process().done(function () { + data.submit(); + }); + } + }, + + // Other callbacks: + + // Callback for the submit event of each file upload: + // submit: function (e, data) {}, // .bind('fileuploadsubmit', func); + + // Callback for the start of each file upload request: + // send: function (e, data) {}, // .bind('fileuploadsend', func); + + // Callback for successful uploads: + // done: function (e, data) {}, // .bind('fileuploaddone', func); + + // Callback for failed (abort or error) uploads: + // fail: function (e, data) {}, // .bind('fileuploadfail', func); + + // Callback for completed (success, abort or error) requests: + // always: function (e, data) {}, // .bind('fileuploadalways', func); + + // Callback for upload progress events: + // progress: function (e, data) {}, // .bind('fileuploadprogress', func); + + // Callback for global upload progress events: + // progressall: function (e, data) {}, // .bind('fileuploadprogressall', func); + + // Callback for uploads start, equivalent to the global ajaxStart event: + // start: function (e) {}, // .bind('fileuploadstart', func); + + // Callback for uploads stop, equivalent to the global ajaxStop event: + // stop: function (e) {}, // .bind('fileuploadstop', func); + + // Callback for change events of the fileInput(s): + // change: function (e, data) {}, // .bind('fileuploadchange', func); + + // Callback for paste events to the pasteZone(s): + // paste: function (e, data) {}, // .bind('fileuploadpaste', func); + + // Callback for drop events of the dropZone(s): + // drop: function (e, data) {}, // .bind('fileuploaddrop', func); + + // Callback for dragover events of the dropZone(s): + // dragover: function (e) {}, // .bind('fileuploaddragover', func); + + // Callback for the start of each chunk upload request: + // chunksend: function (e, data) {}, // .bind('fileuploadchunksend', func); + + // Callback for successful chunk uploads: + // chunkdone: function (e, data) {}, // .bind('fileuploadchunkdone', func); + + // Callback for failed (abort or error) chunk uploads: + // chunkfail: function (e, data) {}, // .bind('fileuploadchunkfail', func); + + // Callback for completed (success, abort or error) chunk upload requests: + // chunkalways: function (e, data) {}, // .bind('fileuploadchunkalways', func); + + // The plugin options are used as settings object for the ajax calls. + // The following are jQuery ajax settings required for the file uploads: + processData: false, + contentType: false, + cache: false + }, + + // A list of options that require reinitializing event listeners and/or + // special initialization code: + _specialOptions: [ + 'fileInput', + 'dropZone', + 'pasteZone', + 'multipart', + 'forceIframeTransport' + ], + + _blobSlice: $.support.blobSlice && function () { + var slice = this.slice || this.webkitSlice || this.mozSlice; + return slice.apply(this, arguments); + }, + + _BitrateTimer: function () { + this.timestamp = ((Date.now) ? Date.now() : (new Date()).getTime()); + this.loaded = 0; + this.bitrate = 0; + this.getBitrate = function (now, loaded, interval) { + var timeDiff = now - this.timestamp; + if (!this.bitrate || !interval || timeDiff > interval) { + this.bitrate = (loaded - this.loaded) * (1000 / timeDiff) * 8; + this.loaded = loaded; + this.timestamp = now; + } + return this.bitrate; + }; + }, + + _isXHRUpload: function (options) { + return !options.forceIframeTransport && + ((!options.multipart && $.support.xhrFileUpload) || + $.support.xhrFormDataFileUpload); + }, + + _getFormData: function (options) { + var formData; + if (typeof options.formData === 'function') { + return options.formData(options.form); + } + if ($.isArray(options.formData)) { + return options.formData; + } + if ($.type(options.formData) === 'object') { + formData = []; + $.each(options.formData, function (name, value) { + formData.push({name: name, value: value}); + }); + return formData; + } + return []; + }, + + _getTotal: function (files) { + var total = 0; + $.each(files, function (index, file) { + total += file.size || 1; + }); + return total; + }, + + _initProgressObject: function (obj) { + var progress = { + loaded: 0, + total: 0, + bitrate: 0 + }; + if (obj._progress) { + $.extend(obj._progress, progress); + } else { + obj._progress = progress; + } + }, + + _initResponseObject: function (obj) { + var prop; + if (obj._response) { + for (prop in obj._response) { + if (obj._response.hasOwnProperty(prop)) { + delete obj._response[prop]; + } + } + } else { + obj._response = {}; + } + }, + + _onProgress: function (e, data) { + if (e.lengthComputable) { + var now = ((Date.now) ? Date.now() : (new Date()).getTime()), + loaded; + if (data._time && data.progressInterval && + (now - data._time < data.progressInterval) && + e.loaded !== e.total) { + return; + } + data._time = now; + loaded = Math.floor( + e.loaded / e.total * (data.chunkSize || data._progress.total) + ) + (data.uploadedBytes || 0); + // Add the difference from the previously loaded state + // to the global loaded counter: + this._progress.loaded += (loaded - data._progress.loaded); + this._progress.bitrate = this._bitrateTimer.getBitrate( + now, + this._progress.loaded, + data.bitrateInterval + ); + data._progress.loaded = data.loaded = loaded; + data._progress.bitrate = data.bitrate = data._bitrateTimer.getBitrate( + now, + loaded, + data.bitrateInterval + ); + // Trigger a custom progress event with a total data property set + // to the file size(s) of the current upload and a loaded data + // property calculated accordingly: + this._trigger( + 'progress', + $.Event('progress', {delegatedEvent: e}), + data + ); + // Trigger a global progress event for all current file uploads, + // including ajax calls queued for sequential file uploads: + this._trigger( + 'progressall', + $.Event('progressall', {delegatedEvent: e}), + this._progress + ); + } + }, + + _initProgressListener: function (options) { + var that = this, + xhr = options.xhr ? options.xhr() : $.ajaxSettings.xhr(); + // Accesss to the native XHR object is required to add event listeners + // for the upload progress event: + if (xhr.upload) { + $(xhr.upload).bind('progress', function (e) { + var oe = e.originalEvent; + // Make sure the progress event properties get copied over: + e.lengthComputable = oe.lengthComputable; + e.loaded = oe.loaded; + e.total = oe.total; + that._onProgress(e, options); + }); + options.xhr = function () { + return xhr; + }; + } + }, + + _isInstanceOf: function (type, obj) { + // Cross-frame instanceof check + return Object.prototype.toString.call(obj) === '[object ' + type + ']'; + }, + + _initXHRData: function (options) { + var that = this, + formData, + file = options.files[0], + // Ignore non-multipart setting if not supported: + multipart = options.multipart || !$.support.xhrFileUpload, + paramName = options.paramName[0]; + options.headers = $.extend({}, options.headers); + if (options.contentRange) { + options.headers['Content-Range'] = options.contentRange; + } + if (!multipart || options.blob || !this._isInstanceOf('File', file)) { + options.headers['Content-Disposition'] = 'attachment; filename="' + + encodeURI(file.name) + '"'; + } + if (!multipart) { + options.contentType = file.type; + options.data = options.blob || file; + } else if ($.support.xhrFormDataFileUpload) { + if (options.postMessage) { + // window.postMessage does not allow sending FormData + // objects, so we just add the File/Blob objects to + // the formData array and let the postMessage window + // create the FormData object out of this array: + formData = this._getFormData(options); + if (options.blob) { + formData.push({ + name: paramName, + value: options.blob + }); + } else { + $.each(options.files, function (index, file) { + formData.push({ + name: options.paramName[index] || paramName, + value: file + }); + }); + } + } else { + if (that._isInstanceOf('FormData', options.formData)) { + formData = options.formData; + } else { + formData = new FormData(); + $.each(this._getFormData(options), function (index, field) { + formData.append(field.name, field.value); + }); + } + if (options.blob) { + formData.append(paramName, options.blob, file.name); + } else { + $.each(options.files, function (index, file) { + // This check allows the tests to run with + // dummy objects: + if (that._isInstanceOf('File', file) || + that._isInstanceOf('Blob', file)) { + formData.append( + options.paramName[index] || paramName, + file, + file.name + ); + } + }); + } + } + options.data = formData; + } + // Blob reference is not needed anymore, free memory: + options.blob = null; + }, + + _initIframeSettings: function (options) { + var targetHost = $('').prop('href', options.url).prop('host'); + // Setting the dataType to iframe enables the iframe transport: + options.dataType = 'iframe ' + (options.dataType || ''); + // The iframe transport accepts a serialized array as form data: + options.formData = this._getFormData(options); + // Add redirect url to form data on cross-domain uploads: + if (options.redirect && targetHost && targetHost !== location.host) { + options.formData.push({ + name: options.redirectParamName || 'redirect', + value: options.redirect + }); + } + }, + + _initDataSettings: function (options) { + if (this._isXHRUpload(options)) { + if (!this._chunkedUpload(options, true)) { + if (!options.data) { + this._initXHRData(options); + } + this._initProgressListener(options); + } + if (options.postMessage) { + // Setting the dataType to postmessage enables the + // postMessage transport: + options.dataType = 'postmessage ' + (options.dataType || ''); + } + } else { + this._initIframeSettings(options); + } + }, + + _getParamName: function (options) { + var fileInput = $(options.fileInput), + paramName = options.paramName; + if (!paramName) { + paramName = []; + fileInput.each(function () { + var input = $(this), + name = input.prop('name') || 'files[]', + i = (input.prop('files') || [1]).length; + while (i) { + paramName.push(name); + i -= 1; + } + }); + if (!paramName.length) { + paramName = [fileInput.prop('name') || 'files[]']; + } + } else if (!$.isArray(paramName)) { + paramName = [paramName]; + } + return paramName; + }, + + _initFormSettings: function (options) { + // Retrieve missing options from the input field and the + // associated form, if available: + if (!options.form || !options.form.length) { + options.form = $(options.fileInput.prop('form')); + // If the given file input doesn't have an associated form, + // use the default widget file input's form: + if (!options.form.length) { + options.form = $(this.options.fileInput.prop('form')); + } + } + options.paramName = this._getParamName(options); + if (!options.url) { + options.url = options.form.prop('action') || location.href; + } + // The HTTP request method must be "POST" or "PUT": + options.type = (options.type || + ($.type(options.form.prop('method')) === 'string' && + options.form.prop('method')) || '' + ).toUpperCase(); + if (options.type !== 'POST' && options.type !== 'PUT' && + options.type !== 'PATCH') { + options.type = 'POST'; + } + if (!options.formAcceptCharset) { + options.formAcceptCharset = options.form.attr('accept-charset'); + } + }, + + _getAJAXSettings: function (data) { + var options = $.extend({}, this.options, data); + this._initFormSettings(options); + this._initDataSettings(options); + options.url = options.url+'&rand=' + new Date().getTime(); + return options; + }, + + // jQuery 1.6 doesn't provide .state(), + // while jQuery 1.8+ removed .isRejected() and .isResolved(): + _getDeferredState: function (deferred) { + if (deferred.state) { + return deferred.state(); + } + if (deferred.isResolved()) { + return 'resolved'; + } + if (deferred.isRejected()) { + return 'rejected'; + } + return 'pending'; + }, + + // Maps jqXHR callbacks to the equivalent + // methods of the given Promise object: + _enhancePromise: function (promise) { + promise.success = promise.done; + promise.error = promise.fail; + promise.complete = promise.always; + return promise; + }, + + // Creates and returns a Promise object enhanced with + // the jqXHR methods abort, success, error and complete: + _getXHRPromise: function (resolveOrReject, context, args) { + var dfd = $.Deferred(), + promise = dfd.promise(); + context = context || this.options.context || promise; + if (resolveOrReject === true) { + dfd.resolveWith(context, args); + } else if (resolveOrReject === false) { + dfd.rejectWith(context, args); + } + promise.abort = dfd.promise; + return this._enhancePromise(promise); + }, + + // Adds convenience methods to the data callback argument: + _addConvenienceMethods: function (e, data) { + var that = this, + getPromise = function (data) { + return $.Deferred().resolveWith(that, [data]).promise(); + }; + data.process = function (resolveFunc, rejectFunc) { + if (resolveFunc || rejectFunc) { + data._processQueue = this._processQueue = + (this._processQueue || getPromise(this)) + .pipe(resolveFunc, rejectFunc); + } + return this._processQueue || getPromise(this); + }; + data.submit = function () { + if (this.state() !== 'pending') { + data.jqXHR = this.jqXHR = + (that._trigger( + 'submit', + $.Event('submit', {delegatedEvent: e}), + this + ) !== false) && that._onSend(e, this); + } + return this.jqXHR || that._getXHRPromise(); + }; + data.abort = function () { + if (this.jqXHR) { + return this.jqXHR.abort(); + } + return that._getXHRPromise(); + }; + data.state = function () { + if (this.jqXHR) { + return that._getDeferredState(this.jqXHR); + } + if (this._processQueue) { + return that._getDeferredState(this._processQueue); + } + }; + data.progress = function () { + return this._progress; + }; + data.response = function () { + return this._response; + }; + }, + + // Parses the Range header from the server response + // and returns the uploaded bytes: + _getUploadedBytes: function (jqXHR) { + var range = jqXHR.getResponseHeader('Range'), + parts = range && range.split('-'), + upperBytesPos = parts && parts.length > 1 && + parseInt(parts[1], 10); + return upperBytesPos && upperBytesPos + 1; + }, + + // Uploads a file in multiple, sequential requests + // by splitting the file up in multiple blob chunks. + // If the second parameter is true, only tests if the file + // should be uploaded in chunks, but does not invoke any + // upload requests: + _chunkedUpload: function (options, testOnly) { + options.uploadedBytes = options.uploadedBytes || 0; + var that = this, + file = options.files[0], + fs = file.size, + ub = options.uploadedBytes, + mcs = options.maxChunkSize || fs, + slice = this._blobSlice, + dfd = $.Deferred(), + promise = dfd.promise(), + jqXHR, + upload; + if (!(this._isXHRUpload(options) && slice && (ub || mcs < fs)) || + options.data) { + return false; + } + if (testOnly) { + return true; + } + if (ub >= fs) { + file.error = options.i18n('uploadedBytes'); + return this._getXHRPromise( + false, + options.context, + [null, 'error', file.error] + ); + } + // The chunk upload method: + upload = function () { + // Clone the options object for each chunk upload: + var o = $.extend({}, options), + currentLoaded = o._progress.loaded; + o.blob = slice.call( + file, + ub, + ub + mcs, + file.type + ); + // Store the current chunk size, as the blob itself + // will be dereferenced after data processing: + o.chunkSize = o.blob.size; + // Expose the chunk bytes position range: + o.contentRange = 'bytes ' + ub + '-' + + (ub + o.chunkSize - 1) + '/' + fs; + // Process the upload data (the blob and potential form data): + that._initXHRData(o); + // Add progress listeners for this chunk upload: + that._initProgressListener(o); + jqXHR = ((that._trigger('chunksend', null, o) !== false && $.ajax(o)) || + that._getXHRPromise(false, o.context)) + .done(function (result, textStatus, jqXHR) { + ub = that._getUploadedBytes(jqXHR) || + (ub + o.chunkSize); + // Create a progress event if no final progress event + // with loaded equaling total has been triggered + // for this chunk: + if (currentLoaded + o.chunkSize - o._progress.loaded) { + that._onProgress($.Event('progress', { + lengthComputable: true, + loaded: ub - o.uploadedBytes, + total: ub - o.uploadedBytes + }), o); + } + options.uploadedBytes = o.uploadedBytes = ub; + o.result = result; + o.textStatus = textStatus; + o.jqXHR = jqXHR; + that._trigger('chunkdone', null, o); + that._trigger('chunkalways', null, o); + if (ub < fs) { + // File upload not yet complete, + // continue with the next chunk: + upload(); + } else { + dfd.resolveWith( + o.context, + [result, textStatus, jqXHR] + ); + } + }) + .fail(function (jqXHR, textStatus, errorThrown) { + o.jqXHR = jqXHR; + o.textStatus = textStatus; + o.errorThrown = errorThrown; + that._trigger('chunkfail', null, o); + that._trigger('chunkalways', null, o); + dfd.rejectWith( + o.context, + [jqXHR, textStatus, errorThrown] + ); + }); + }; + this._enhancePromise(promise); + promise.abort = function () { + return jqXHR.abort(); + }; + upload(); + return promise; + }, + + _beforeSend: function (e, data) { + if (this._active === 0) { + // the start callback is triggered when an upload starts + // and no other uploads are currently running, + // equivalent to the global ajaxStart event: + this._trigger('start'); + // Set timer for global bitrate progress calculation: + this._bitrateTimer = new this._BitrateTimer(); + // Reset the global progress values: + this._progress.loaded = this._progress.total = 0; + this._progress.bitrate = 0; + } + // Make sure the container objects for the .response() and + // .progress() methods on the data object are available + // and reset to their initial state: + this._initResponseObject(data); + this._initProgressObject(data); + data._progress.loaded = data.loaded = data.uploadedBytes || 0; + data._progress.total = data.total = this._getTotal(data.files) || 1; + data._progress.bitrate = data.bitrate = 0; + this._active += 1; + // Initialize the global progress values: + this._progress.loaded += data.loaded; + this._progress.total += data.total; + }, + + _onDone: function (result, textStatus, jqXHR, options) { + var total = options._progress.total, + response = options._response; + if (options._progress.loaded < total) { + // Create a progress event if no final progress event + // with loaded equaling total has been triggered: + this._onProgress($.Event('progress', { + lengthComputable: true, + loaded: total, + total: total + }), options); + } + response.result = options.result = result; + response.textStatus = options.textStatus = textStatus; + response.jqXHR = options.jqXHR = jqXHR; + this._trigger('done', null, options); + }, + + _onFail: function (jqXHR, textStatus, errorThrown, options) { + var response = options._response; + if (options.recalculateProgress) { + // Remove the failed (error or abort) file upload from + // the global progress calculation: + this._progress.loaded -= options._progress.loaded; + this._progress.total -= options._progress.total; + } + response.jqXHR = options.jqXHR = jqXHR; + response.textStatus = options.textStatus = textStatus; + response.errorThrown = options.errorThrown = errorThrown; + this._trigger('fail', null, options); + }, + + _onAlways: function (jqXHRorResult, textStatus, jqXHRorError, options) { + // jqXHRorResult, textStatus and jqXHRorError are added to the + // options object via done and fail callbacks + this._trigger('always', null, options); + }, + + _onSend: function (e, data) { + if (!data.submit) { + this._addConvenienceMethods(e, data); + } + var that = this, + jqXHR, + aborted, + slot, + pipe, + options = that._getAJAXSettings(data), + send = function () { + that._sending += 1; + // Set timer for bitrate progress calculation: + options._bitrateTimer = new that._BitrateTimer(); + jqXHR = jqXHR || ( + ((aborted || that._trigger( + 'send', + $.Event('send', {delegatedEvent: e}), + options + ) === false) && + that._getXHRPromise(false, options.context, aborted)) || + that._chunkedUpload(options) || $.ajax(options) + ).done(function (result, textStatus, jqXHR) { + that._onDone(result, textStatus, jqXHR, options); + }).fail(function (jqXHR, textStatus, errorThrown) { + that._onFail(jqXHR, textStatus, errorThrown, options); + }).always(function (jqXHRorResult, textStatus, jqXHRorError) { + that._onAlways( + jqXHRorResult, + textStatus, + jqXHRorError, + options + ); + that._sending -= 1; + that._active -= 1; + if (options.limitConcurrentUploads && + options.limitConcurrentUploads > that._sending) { + // Start the next queued upload, + // that has not been aborted: + var nextSlot = that._slots.shift(); + while (nextSlot) { + if (that._getDeferredState(nextSlot) === 'pending') { + nextSlot.resolve(); + break; + } + nextSlot = that._slots.shift(); + } + } + if (that._active === 0) { + // The stop callback is triggered when all uploads have + // been completed, equivalent to the global ajaxStop event: + that._trigger('stop'); + } + }); + return jqXHR; + }; + this._beforeSend(e, options); + if (this.options.sequentialUploads || + (this.options.limitConcurrentUploads && + this.options.limitConcurrentUploads <= this._sending)) { + if (this.options.limitConcurrentUploads > 1) { + slot = $.Deferred(); + this._slots.push(slot); + pipe = slot.pipe(send); + } else { + this._sequence = this._sequence.pipe(send, send); + pipe = this._sequence; + } + // Return the piped Promise object, enhanced with an abort method, + // which is delegated to the jqXHR object of the current upload, + // and jqXHR callbacks mapped to the equivalent Promise methods: + pipe.abort = function () { + aborted = [undefined, 'abort', 'abort']; + if (!jqXHR) { + if (slot) { + slot.rejectWith(options.context, aborted); + } + return send(); + } + return jqXHR.abort(); + }; + return this._enhancePromise(pipe); + } + return send(); + }, + + _onAdd: function (e, data) { + var that = this, + result = true, + options = $.extend({}, this.options, data), + limit = options.limitMultiFileUploads, + paramName = this._getParamName(options), + paramNameSet, + paramNameSlice, + fileSet, + i; + if (!(options.singleFileUploads || limit) || + !this._isXHRUpload(options)) { + fileSet = [data.files]; + paramNameSet = [paramName]; + } else if (!options.singleFileUploads && limit) { + fileSet = []; + paramNameSet = []; + for (i = 0; i < data.files.length; i += limit) { + fileSet.push(data.files.slice(i, i + limit)); + paramNameSlice = paramName.slice(i, i + limit); + if (!paramNameSlice.length) { + paramNameSlice = paramName; + } + paramNameSet.push(paramNameSlice); + } + } else { + paramNameSet = paramName; + } + data.originalFiles = data.files; + $.each(fileSet || data.files, function (index, element) { + var newData = $.extend({}, data); + newData.files = fileSet ? element : [element]; + newData.paramName = paramNameSet[index]; + that._initResponseObject(newData); + that._initProgressObject(newData); + that._addConvenienceMethods(e, newData); + result = that._trigger( + 'add', + $.Event('add', {delegatedEvent: e}), + newData + ); + return result; + }); + return result; + }, + + _replaceFileInput: function (input) { + var inputClone = input.clone(true); + $('
').append(inputClone)[0].reset(); + // Detaching allows to insert the fileInput on another form + // without loosing the file input value: + input.after(inputClone).detach(); + // Avoid memory leaks with the detached file input: + $.cleanData(input.unbind('remove')); + // Replace the original file input element in the fileInput + // elements set with the clone, which has been copied including + // event handlers: + this.options.fileInput = this.options.fileInput.map(function (i, el) { + if (el === input[0]) { + return inputClone[0]; + } + return el; + }); + // If the widget has been initialized on the file input itself, + // override this.element with the file input clone: + if (input[0] === this.element[0]) { + this.element = inputClone; + } + }, + + _handleFileTreeEntry: function (entry, path) { + var that = this, + dfd = $.Deferred(), + errorHandler = function (e) { + if (e && !e.entry) { + e.entry = entry; + } + // Since $.when returns immediately if one + // Deferred is rejected, we use resolve instead. + // This allows valid files and invalid items + // to be returned together in one set: + dfd.resolve([e]); + }, + dirReader; + path = path || ''; + if (entry.isFile) { + if (entry._file) { + // Workaround for Chrome bug #149735 + entry._file.relativePath = path; + dfd.resolve(entry._file); + } else { + entry.file(function (file) { + file.relativePath = path; + dfd.resolve(file); + }, errorHandler); + } + } else if (entry.isDirectory) { + dirReader = entry.createReader(); + dirReader.readEntries(function (entries) { + that._handleFileTreeEntries( + entries, + path + entry.name + '/' + ).done(function (files) { + dfd.resolve(files); + }).fail(errorHandler); + }, errorHandler); + } else { + // Return an empy list for file system items + // other than files or directories: + dfd.resolve([]); + } + return dfd.promise(); + }, + + _handleFileTreeEntries: function (entries, path) { + var that = this; + return $.when.apply( + $, + $.map(entries, function (entry) { + return that._handleFileTreeEntry(entry, path); + }) + ).pipe(function () { + return Array.prototype.concat.apply( + [], + arguments + ); + }); + }, + + _getDroppedFiles: function (dataTransfer) { + dataTransfer = dataTransfer || {}; + var items = dataTransfer.items; + if (items && items.length && (items[0].webkitGetAsEntry || + items[0].getAsEntry)) { + return this._handleFileTreeEntries( + $.map(items, function (item) { + var entry; + if (item.webkitGetAsEntry) { + entry = item.webkitGetAsEntry(); + if (entry) { + // Workaround for Chrome bug #149735: + entry._file = item.getAsFile(); + } + return entry; + } + return item.getAsEntry(); + }) + ); + } + return $.Deferred().resolve( + $.makeArray(dataTransfer.files) + ).promise(); + }, + + _getSingleFileInputFiles: function (fileInput) { + fileInput = $(fileInput); + var entries = fileInput.prop('webkitEntries') || + fileInput.prop('entries'), + files, + value; + if (entries && entries.length) { + return this._handleFileTreeEntries(entries); + } + files = $.makeArray(fileInput.prop('files')); + if (!files.length) { + value = fileInput.prop('value'); + if (!value) { + return $.Deferred().resolve([]).promise(); + } + // If the files property is not available, the browser does not + // support the File API and we add a pseudo File object with + // the input value as name with path information removed: + files = [{name: value.replace(/^.*\\/, '')}]; + } else if (files[0].name === undefined && files[0].fileName) { + // File normalization for Safari 4 and Firefox 3: + $.each(files, function (index, file) { + file.name = file.fileName; + file.size = file.fileSize; + }); + } + return $.Deferred().resolve(files).promise(); + }, + + _getFileInputFiles: function (fileInput) { + if (!(fileInput instanceof $) || fileInput.length === 1) { + return this._getSingleFileInputFiles(fileInput); + } + return $.when.apply( + $, + $.map(fileInput, this._getSingleFileInputFiles) + ).pipe(function () { + return Array.prototype.concat.apply( + [], + arguments + ); + }); + }, + + _onChange: function (e) { + var that = this, + data = { + fileInput: $(e.target), + form: $(e.target.form) + }; + this._getFileInputFiles(data.fileInput).always(function (files) { + data.files = files; + if (that.options.replaceFileInput) { + that._replaceFileInput(data.fileInput); + } + if (that._trigger( + 'change', + $.Event('change', {delegatedEvent: e}), + data + ) !== false) { + that._onAdd(e, data); + } + }); + }, + + _onPaste: function (e) { + var items = e.originalEvent && e.originalEvent.clipboardData && + e.originalEvent.clipboardData.items, + data = {files: []}; + if (items && items.length) { + $.each(items, function (index, item) { + var file = item.getAsFile && item.getAsFile(); + if (file) { + data.files.push(file); + } + }); + if (this._trigger( + 'paste', + $.Event('paste', {delegatedEvent: e}), + data + ) !== false) { + this._onAdd(e, data); + } + } + }, + + _onDrop: function (e) { + e.dataTransfer = e.originalEvent && e.originalEvent.dataTransfer; + var that = this, + dataTransfer = e.dataTransfer, + data = {}; + if (dataTransfer && dataTransfer.files && dataTransfer.files.length) { + e.preventDefault(); + this._getDroppedFiles(dataTransfer).always(function (files) { + data.files = files; + if (that._trigger( + 'drop', + $.Event('drop', {delegatedEvent: e}), + data + ) !== false) { + that._onAdd(e, data); + } + }); + } + }, + + _onDragOver: function (e) { + e.dataTransfer = e.originalEvent && e.originalEvent.dataTransfer; + var dataTransfer = e.dataTransfer; + if (dataTransfer && $.inArray('Files', dataTransfer.types) !== -1 && + this._trigger( + 'dragover', + $.Event('dragover', {delegatedEvent: e}) + ) !== false) { + e.preventDefault(); + dataTransfer.dropEffect = 'copy'; + } + }, + + _initEventHandlers: function () { + if (this._isXHRUpload(this.options)) { + this._on(this.options.dropZone, { + dragover: this._onDragOver, + drop: this._onDrop + }); + this._on(this.options.pasteZone, { + paste: this._onPaste + }); + } + if ($.support.fileInput) { + this._on(this.options.fileInput, { + change: this._onChange + }); + } + }, + + _destroyEventHandlers: function () { + this._off(this.options.dropZone, 'dragover drop'); + this._off(this.options.pasteZone, 'paste'); + this._off(this.options.fileInput, 'change'); + }, + + _setOption: function (key, value) { + var reinit = $.inArray(key, this._specialOptions) !== -1; + if (reinit) { + this._destroyEventHandlers(); + } + this._super(key, value); + if (reinit) { + this._initSpecialOptions(); + this._initEventHandlers(); + } + }, + + _initSpecialOptions: function () { + var options = this.options; + if (options.fileInput === undefined) { + options.fileInput = this.element.is('input[type="file"]') ? + this.element : this.element.find('input[type="file"]'); + } else if (!(options.fileInput instanceof $)) { + options.fileInput = $(options.fileInput); + } + if (!(options.dropZone instanceof $)) { + options.dropZone = $(options.dropZone); + } + if (!(options.pasteZone instanceof $)) { + options.pasteZone = $(options.pasteZone); + } + }, + + _getRegExp: function (str) { + var parts = str.split('/'), + modifiers = parts.pop(); + parts.shift(); + return new RegExp(parts.join('/'), modifiers); + }, + + _isRegExpOption: function (key, value) { + return key !== 'url' && $.type(value) === 'string' && + /^\/.*\/[igm]{0,3}$/.test(value); + }, + + _initDataAttributes: function () { + var that = this, + options = this.options; + // Initialize options set via HTML5 data-attributes: + $.each( + $(this.element[0].cloneNode(false)).data(), + function (key, value) { + if (that._isRegExpOption(key, value)) { + value = that._getRegExp(value); + } + options[key] = value; + } + ); + }, + + _create: function () { + this._initDataAttributes(); + this._initSpecialOptions(); + this._slots = []; + this._sequence = this._getXHRPromise(true); + this._sending = this._active = 0; + this._initProgressObject(this); + this._initEventHandlers(); + }, + + // This method is exposed to the widget API and allows to query + // the number of active uploads: + active: function () { + return this._active; + }, + + // This method is exposed to the widget API and allows to query + // the widget upload progress. + // It returns an object with loaded, total and bitrate properties + // for the running uploads: + progress: function () { + return this._progress; + }, + + // This method is exposed to the widget API and allows adding files + // using the fileupload API. The data parameter accepts an object which + // must have a files property and can contain additional options: + // .fileupload('add', {files: filesList}); + add: function (data) { + var that = this; + if (!data || this.options.disabled) { + return; + } + if (data.fileInput && !data.files) { + this._getFileInputFiles(data.fileInput).always(function (files) { + data.files = files; + that._onAdd(null, data); + }); + } else { + data.files = $.makeArray(data.files); + this._onAdd(null, data); + } + }, + + // This method is exposed to the widget API and allows sending files + // using the fileupload API. The data parameter accepts an object which + // must have a files or fileInput property and can contain additional options: + // .fileupload('send', {files: filesList}); + // The method returns a Promise object for the file upload call. + send: function (data) { + if (data && !this.options.disabled) { + if (data.fileInput && !data.files) { + var that = this, + dfd = $.Deferred(), + promise = dfd.promise(), + jqXHR, + aborted; + promise.abort = function () { + aborted = true; + if (jqXHR) { + return jqXHR.abort(); + } + dfd.reject(null, 'abort', 'abort'); + return promise; + }; + this._getFileInputFiles(data.fileInput).always( + function (files) { + if (aborted) { + return; + } + if (!files.length) { + dfd.reject(); + return; + } + data.files = files; + jqXHR = that._onSend(null, data).then( + function (result, textStatus, jqXHR) { + dfd.resolve(result, textStatus, jqXHR); + }, + function (jqXHR, textStatus, errorThrown) { + dfd.reject(jqXHR, textStatus, errorThrown); + } + ); + } + ); + return this._enhancePromise(promise); + } + data.files = $.makeArray(data.files); + if (data.files.length) { + return this._onSend(null, data); + } + } + return this._getXHRPromise(false, data && data.context); + } + + }); + +})); diff --git a/forms/jquery.iframe-transport.js b/forms/jquery.iframe-transport.js new file mode 100644 index 0000000..33e2795 --- /dev/null +++ b/forms/jquery.iframe-transport.js @@ -0,0 +1,208 @@ +/* + * jQuery Iframe Transport Plugin 1.8.0 + * https://github.com/blueimp/jQuery-File-Upload + * + * Copyright 2011, Sebastian Tschan + * https://blueimp.net + * + * Licensed under the MIT license: + * http://www.opensource.org/licenses/MIT + */ + +/*jslint unparam: true, nomen: true */ +/*global define, window, document */ + +(function (factory) { + 'use strict'; + if (typeof define === 'function' && define.amd) { + // Register as an anonymous AMD module: + define(['jquery'], factory); + } else { + // Browser globals: + factory(window.jQuery); + } +}(function ($) { + 'use strict'; + + // Helper variable to create unique names for the transport iframes: + var counter = 0; + + // The iframe transport accepts four additional options: + // options.fileInput: a jQuery collection of file input fields + // options.paramName: the parameter name for the file form data, + // overrides the name property of the file input field(s), + // can be a string or an array of strings. + // options.formData: an array of objects with name and value properties, + // equivalent to the return data of .serializeArray(), e.g.: + // [{name: 'a', value: 1}, {name: 'b', value: 2}] + // options.initialIframeSrc: the URL of the initial iframe src, + // by default set to "javascript:false;" + $.ajaxTransport('iframe', function (options) { + if (options.async) { + // javascript:false as initial iframe src + // prevents warning popups on HTTPS in IE6: + var initialIframeSrc = options.initialIframeSrc || 'javascript:false;', + form, + iframe, + addParamChar; + return { + send: function (_, completeCallback) { + form = $('
'); + form.attr('accept-charset', options.formAcceptCharset); + addParamChar = /\?/.test(options.url) ? '&' : '?'; + // XDomainRequest only supports GET and POST: + if (options.type === 'DELETE') { + options.url = options.url + addParamChar + '_method=DELETE'; + options.type = 'POST'; + } else if (options.type === 'PUT') { + options.url = options.url + addParamChar + '_method=PUT'; + options.type = 'POST'; + } else if (options.type === 'PATCH') { + options.url = options.url + addParamChar + '_method=PATCH'; + options.type = 'POST'; + } + // IE versions below IE8 cannot set the name property of + // elements that have already been added to the DOM, + // so we set the name along with the iframe HTML markup: + counter += 1; + iframe = $( + '' + ).bind('load', function () { + var fileInputClones, + paramNames = $.isArray(options.paramName) ? + options.paramName : [options.paramName]; + iframe + .unbind('load') + .bind('load', function () { + var response; + // Wrap in a try/catch block to catch exceptions thrown + // when trying to access cross-domain iframe contents: + try { + response = iframe.contents(); + // Google Chrome and Firefox do not throw an + // exception when calling iframe.contents() on + // cross-domain requests, so we unify the response: + if (!response.length || !response[0].firstChild) { + throw new Error(); + } + } catch (e) { + response = undefined; + } + // The complete callback returns the + // iframe content document as response object: + completeCallback( + 200, + 'success', + {'iframe': response} + ); + // Fix for IE endless progress bar activity bug + // (happens on form submits to iframe targets): + $('') + .appendTo(form); + window.setTimeout(function () { + // Removing the form in a setTimeout call + // allows Chrome's developer tools to display + // the response result + form.remove(); + }, 0); + }); + form + .prop('target', iframe.prop('name')) + .prop('action', options.url) + .prop('method', options.type); + if (options.formData) { + $.each(options.formData, function (index, field) { + $('') + .prop('name', field.name) + .val(field.value) + .appendTo(form); + }); + } + if (options.fileInput && options.fileInput.length && + options.type === 'POST') { + fileInputClones = options.fileInput.clone(); + // Insert a clone for each file input field: + options.fileInput.after(function (index) { + return fileInputClones[index]; + }); + if (options.paramName) { + options.fileInput.each(function (index) { + $(this).prop( + 'name', + paramNames[index] || options.paramName + ); + }); + } + // Appending the file input fields to the hidden form + // removes them from their original location: + form + .append(options.fileInput) + .prop('enctype', 'multipart/form-data') + // enctype must be set as encoding for IE: + .prop('encoding', 'multipart/form-data'); + } + form.submit(); + // Insert the file input fields at their original location + // by replacing the clones with the originals: + if (fileInputClones && fileInputClones.length) { + options.fileInput.each(function (index, input) { + var clone = $(fileInputClones[index]); + $(input).prop('name', clone.prop('name')); + clone.replaceWith(input); + }); + } + }); + form.append(iframe).appendTo(document.body); + }, + abort: function () { + if (iframe) { + // javascript:false as iframe src aborts the request + // and prevents warning popups on HTTPS in IE6. + // concat is used to avoid the "Script URL" JSLint error: + iframe + .unbind('load') + .prop('src', initialIframeSrc); + } + if (form) { + form.remove(); + } + } + }; + } + }); + + // The iframe transport returns the iframe content document as response. + // The following adds converters from iframe to text, json, html, xml + // and script. + // Please note that the Content-Type for JSON responses has to be text/plain + // or text/html, if the browser doesn't include application/json in the + // Accept header, else IE will show a download dialog. + // The Content-Type for XML responses on the other hand has to be always + // application/xml or text/xml, so IE properly parses the XML response. + // See also + // https://github.com/blueimp/jQuery-File-Upload/wiki/Setup#content-type-negotiation + $.ajaxSetup({ + converters: { + 'iframe text': function (iframe) { + return iframe && $(iframe[0].body).text(); + }, + 'iframe json': function (iframe) { + return iframe && $.parseJSON($(iframe[0].body).text()); + }, + 'iframe html': function (iframe) { + return iframe && $(iframe[0].body).html(); + }, + 'iframe xml': function (iframe) { + var xmlDoc = iframe && iframe[0]; + return xmlDoc && $.isXMLDoc(xmlDoc) ? xmlDoc : + $.parseXML((xmlDoc.XMLDocument && xmlDoc.XMLDocument.xml) || + $(xmlDoc.body).html()); + }, + 'iframe script': function (iframe) { + return iframe && $.globalEval($(iframe[0].body).text()); + } + } + }); + +})); diff --git a/forms/jquery.iframe-transport_1.js b/forms/jquery.iframe-transport_1.js new file mode 100644 index 0000000..33e2795 --- /dev/null +++ b/forms/jquery.iframe-transport_1.js @@ -0,0 +1,208 @@ +/* + * jQuery Iframe Transport Plugin 1.8.0 + * https://github.com/blueimp/jQuery-File-Upload + * + * Copyright 2011, Sebastian Tschan + * https://blueimp.net + * + * Licensed under the MIT license: + * http://www.opensource.org/licenses/MIT + */ + +/*jslint unparam: true, nomen: true */ +/*global define, window, document */ + +(function (factory) { + 'use strict'; + if (typeof define === 'function' && define.amd) { + // Register as an anonymous AMD module: + define(['jquery'], factory); + } else { + // Browser globals: + factory(window.jQuery); + } +}(function ($) { + 'use strict'; + + // Helper variable to create unique names for the transport iframes: + var counter = 0; + + // The iframe transport accepts four additional options: + // options.fileInput: a jQuery collection of file input fields + // options.paramName: the parameter name for the file form data, + // overrides the name property of the file input field(s), + // can be a string or an array of strings. + // options.formData: an array of objects with name and value properties, + // equivalent to the return data of .serializeArray(), e.g.: + // [{name: 'a', value: 1}, {name: 'b', value: 2}] + // options.initialIframeSrc: the URL of the initial iframe src, + // by default set to "javascript:false;" + $.ajaxTransport('iframe', function (options) { + if (options.async) { + // javascript:false as initial iframe src + // prevents warning popups on HTTPS in IE6: + var initialIframeSrc = options.initialIframeSrc || 'javascript:false;', + form, + iframe, + addParamChar; + return { + send: function (_, completeCallback) { + form = $('
'); + form.attr('accept-charset', options.formAcceptCharset); + addParamChar = /\?/.test(options.url) ? '&' : '?'; + // XDomainRequest only supports GET and POST: + if (options.type === 'DELETE') { + options.url = options.url + addParamChar + '_method=DELETE'; + options.type = 'POST'; + } else if (options.type === 'PUT') { + options.url = options.url + addParamChar + '_method=PUT'; + options.type = 'POST'; + } else if (options.type === 'PATCH') { + options.url = options.url + addParamChar + '_method=PATCH'; + options.type = 'POST'; + } + // IE versions below IE8 cannot set the name property of + // elements that have already been added to the DOM, + // so we set the name along with the iframe HTML markup: + counter += 1; + iframe = $( + '' + ).bind('load', function () { + var fileInputClones, + paramNames = $.isArray(options.paramName) ? + options.paramName : [options.paramName]; + iframe + .unbind('load') + .bind('load', function () { + var response; + // Wrap in a try/catch block to catch exceptions thrown + // when trying to access cross-domain iframe contents: + try { + response = iframe.contents(); + // Google Chrome and Firefox do not throw an + // exception when calling iframe.contents() on + // cross-domain requests, so we unify the response: + if (!response.length || !response[0].firstChild) { + throw new Error(); + } + } catch (e) { + response = undefined; + } + // The complete callback returns the + // iframe content document as response object: + completeCallback( + 200, + 'success', + {'iframe': response} + ); + // Fix for IE endless progress bar activity bug + // (happens on form submits to iframe targets): + $('') + .appendTo(form); + window.setTimeout(function () { + // Removing the form in a setTimeout call + // allows Chrome's developer tools to display + // the response result + form.remove(); + }, 0); + }); + form + .prop('target', iframe.prop('name')) + .prop('action', options.url) + .prop('method', options.type); + if (options.formData) { + $.each(options.formData, function (index, field) { + $('') + .prop('name', field.name) + .val(field.value) + .appendTo(form); + }); + } + if (options.fileInput && options.fileInput.length && + options.type === 'POST') { + fileInputClones = options.fileInput.clone(); + // Insert a clone for each file input field: + options.fileInput.after(function (index) { + return fileInputClones[index]; + }); + if (options.paramName) { + options.fileInput.each(function (index) { + $(this).prop( + 'name', + paramNames[index] || options.paramName + ); + }); + } + // Appending the file input fields to the hidden form + // removes them from their original location: + form + .append(options.fileInput) + .prop('enctype', 'multipart/form-data') + // enctype must be set as encoding for IE: + .prop('encoding', 'multipart/form-data'); + } + form.submit(); + // Insert the file input fields at their original location + // by replacing the clones with the originals: + if (fileInputClones && fileInputClones.length) { + options.fileInput.each(function (index, input) { + var clone = $(fileInputClones[index]); + $(input).prop('name', clone.prop('name')); + clone.replaceWith(input); + }); + } + }); + form.append(iframe).appendTo(document.body); + }, + abort: function () { + if (iframe) { + // javascript:false as iframe src aborts the request + // and prevents warning popups on HTTPS in IE6. + // concat is used to avoid the "Script URL" JSLint error: + iframe + .unbind('load') + .prop('src', initialIframeSrc); + } + if (form) { + form.remove(); + } + } + }; + } + }); + + // The iframe transport returns the iframe content document as response. + // The following adds converters from iframe to text, json, html, xml + // and script. + // Please note that the Content-Type for JSON responses has to be text/plain + // or text/html, if the browser doesn't include application/json in the + // Accept header, else IE will show a download dialog. + // The Content-Type for XML responses on the other hand has to be always + // application/xml or text/xml, so IE properly parses the XML response. + // See also + // https://github.com/blueimp/jQuery-File-Upload/wiki/Setup#content-type-negotiation + $.ajaxSetup({ + converters: { + 'iframe text': function (iframe) { + return iframe && $(iframe[0].body).text(); + }, + 'iframe json': function (iframe) { + return iframe && $.parseJSON($(iframe[0].body).text()); + }, + 'iframe html': function (iframe) { + return iframe && $(iframe[0].body).html(); + }, + 'iframe xml': function (iframe) { + var xmlDoc = iframe && iframe[0]; + return xmlDoc && $.isXMLDoc(xmlDoc) ? xmlDoc : + $.parseXML((xmlDoc.XMLDocument && xmlDoc.XMLDocument.xml) || + $(xmlDoc.body).html()); + }, + 'iframe script': function (iframe) { + return iframe && $.globalEval($(iframe[0].body).text()); + } + } + }); + +})); diff --git a/forms/jquery.tagify.js b/forms/jquery.tagify.js new file mode 100644 index 0000000..a758fea --- /dev/null +++ b/forms/jquery.tagify.js @@ -0,0 +1,139 @@ +/* Author: Alicia Liu */ + +(function ($) { + + $.widget("ui.tagify", { + options: { + delimiters: [13, 188], // what user can type to complete a tag in char codes: [enter], [comma] + outputDelimiter: ',', // delimiter for tags in original input field + cssClass: 'tagify-container', // CSS class to style the tagify div and tags, see stylesheet + addTagPrompt: 'add tags' // placeholder text + }, + + _create: function() { + var self = this, + el = self.element, + opts = self.options; + + this.tags = []; + + // hide text field and replace with a div that contains it's own input field for entering tags + this.tagInput = $("") + .attr( 'placeholder', opts.addTagPrompt ) + .keypress( function(e) { + var $this = $(this), + pressed = e.which; + + for ( i in opts.delimiters ) { + + if (pressed == opts.delimiters[i]) { + self.add( $this.val() ); + e.preventDefault(); + return false; + } + } + }) + // for some reason, in Safari, backspace is only recognized on keyup + .keyup( function(e) { + var $this = $(this), + pressed = e.which; + + // if backspace is hit with no input, remove the last tag + if (pressed == 8) { // backspace + return; + } + }); + + this.tagDiv = $("
") + .addClass( opts.cssClass ) + .click( function() { + $(this).children('input').focus(); + }) + .append( this.tagInput ) + .insertAfter( el.hide() ); + + // if the field isn't empty, parse the field for tags, and prepopulate existing tags + var initVal = $.trim( el.val() ); + + if ( initVal ) { + var initTags = initVal.split( opts.outputDelimiter ); + $.each( initTags, function(i, tag) { + self.add( tag ); + }); + } + }, + + _setOption: function( key, value ) { + options.key = value; + }, + + // add a tag, public function + add: function(text) { + var self = this; + text = text || self.tagInput.val(); + if (text) { + var tagIndex = self.tags.length; + + var removeButton = $("x") + .click( function() { + self.remove( tagIndex ); + return false; + }); + var newTag = $("") + .text( text ) + .append( removeButton ); + + self.tagInput.before( newTag ); + self.tags.push( text ); + self.tagInput.val(''); + } + }, + + // remove a tag by index, public function + // if index is blank, remove the last tag + remove: function( tagIndex ) { + var self = this; + if ( tagIndex == null || tagIndex === (self.tags.length - 1) ) { + this.tagDiv.children("span").last().remove(); + self.tags.pop(); + } + if ( typeof(tagIndex) == 'number' ) { + // otherwise just hide this tag, and we don't mess up the index + this.tagDiv.children( "span:eq(" + tagIndex + ")" ).hide(); + // we rely on the serialize function to remove null values + delete( self.tags[tagIndex] ); + } + }, + + // serialize the tags with the given delimiter, and write it back into the tagified field + serialize: function() { + var self = this; + var delim = self.options.outputDelimiter; + var tagsStr = self.tags.join( delim ); + + // our tags might have deleted entries, remove them here + var dupes = new RegExp(delim + delim + '+', 'g'); // regex: /,,+/g + var ends = new RegExp('^' + delim + '|' + delim + '$', 'g'); // regex: /^,|,$/g + var outputStr = tagsStr.replace( dupes, delim ).replace(ends, ''); + + self.element.val(outputStr); + return outputStr; + }, + + inputField: function() { + return this.tagInput; + }, + + containerDiv: function() { + return this.tagDiv; + }, + + // remove the div, and show original input + destroy: function() { + $.Widget.prototype.destroy.apply(this); + this.tagDiv.remove(); + this.element.show(); + } + }); + +})(jQuery); diff --git a/forms/ladda.js b/forms/ladda.js new file mode 100644 index 0000000..e161f94 --- /dev/null +++ b/forms/ladda.js @@ -0,0 +1,314 @@ +/*! + * Ladda 0.8.0 + * http://lab.hakim.se/ladda + * MIT licensed + * + * Copyright (C) 2013 Hakim El Hattab, http://hakim.se + */ +(function( root, factory ) { + + // CommonJS + if( typeof exports === 'object' ) { + module.exports = factory(); + } + // AMD module + else if( typeof define === 'function' && define.amd ) { + define( [ 'spin' ], factory ); + } + // Browser global + else { + root.Ladda = factory( root.Spinner ); + } + +} +(this, function( Spinner ) { + 'use strict'; + + // All currently instantiated instances of Ladda + var ALL_INSTANCES = []; + + /** + * Creates a new instance of Ladda which wraps the + * target button element. + * + * @return An API object that can be used to control + * the loading animation state. + */ + function create( button ) { + + if( typeof button === 'undefined' ) { + console.warn( "Ladda button target must be defined." ); + return; + } + + // The text contents must be wrapped in a ladda-label + // element, create one if it doesn't already exist + if( !button.querySelector( '.ladda-label' ) ) { + button.innerHTML = ''+ button.innerHTML +''; + } + + // Create the spinner + var spinner = createSpinner( button ); + + // Wrapper element for the spinner + var spinnerWrapper = document.createElement( 'span' ); + spinnerWrapper.className = 'ladda-spinner'; + button.appendChild( spinnerWrapper ); + + // Timer used to delay starting/stopping + var timer; + + var instance = { + + /** + * Enter the loading state. + */ + start: function() { + + button.setAttribute( 'disabled', '' ); + button.setAttribute( 'data-loading', '' ); + + clearTimeout( timer ); + spinner.spin( spinnerWrapper ); + + this.setProgress( 0 ); + + return this; // chain + + }, + + /** + * Enter the loading state, after a delay. + */ + startAfter: function( delay ) { + + clearTimeout( timer ); + timer = setTimeout( function() { instance.start(); }, delay ); + + return this; // chain + + }, + + /** + * Exit the loading state. + */ + stop: function() { + + button.removeAttribute( 'disabled' ); + button.removeAttribute( 'data-loading' ); + + // Kill the animation after a delay to make sure it + // runs for the duration of the button transition + clearTimeout( timer ); + timer = setTimeout( function() { spinner.stop(); }, 1000 ); + + return this; // chain + + }, + + /** + * Toggle the loading state on/off. + */ + toggle: function() { + + if( this.isLoading() ) { + this.stop(); + } + else { + this.start(); + } + + return this; // chain + + }, + + /** + * Sets the width of the visual progress bar inside of + * this Ladda button + * + * @param {Number} progress in the range of 0-1 + */ + setProgress: function( progress ) { + + // Cap it + progress = Math.max( Math.min( progress, 1 ), 0 ); + + var progressElement = button.querySelector( '.ladda-progress' ); + + // Remove the progress bar if we're at 0 progress + if( progress === 0 && progressElement && progressElement.parentNode ) { + progressElement.parentNode.removeChild( progressElement ); + } + else { + if( !progressElement ) { + progressElement = document.createElement( 'div' ); + progressElement.className = 'ladda-progress'; + button.appendChild( progressElement ); + } + + progressElement.style.width = ( ( progress || 0 ) * button.offsetWidth ) + 'px'; + } + + }, + + enable: function() { + + this.stop(); + + return this; // chain + + }, + + disable: function () { + + this.stop(); + button.setAttribute( 'disabled', '' ); + + return this; // chain + + }, + + isLoading: function() { + + return button.hasAttribute( 'data-loading' ); + + } + + }; + + ALL_INSTANCES.push( instance ); + + return instance; + + } + + /** + * Binds the target buttons to automatically enter the + * loading state when clicked. + * + * @param target Either an HTML element or a CSS selector. + * @param options + * - timeout Number of milliseconds to wait before + * automatically cancelling the animation. + */ + function bind( target, options ) { + + options = options || {}; + + var targets = []; + + if( typeof target === 'string' ) { + targets = toArray( document.querySelectorAll( target ) ); + } + else if( typeof target === 'object' && typeof target.nodeName === 'string' ) { + targets = [ target ]; + } + + for( var i = 0, len = targets.length; i < len; i++ ) { + + (function() { + var element = targets[i]; + + // Make sure we're working with a DOM element + if( typeof element.addEventListener === 'function' ) { + var instance = create( element ); + var timeout = -1; + + element.addEventListener( 'click', function() { + + // This is asynchronous to avoid an issue where setting + // the disabled attribute on the button prevents forms + // from submitting + instance.startAfter( 1 ); + + // Set a loading timeout if one is specified + if( typeof options.timeout === 'number' ) { + clearTimeout( timeout ); + timeout = setTimeout( instance.stop, options.timeout ); + } + + // Invoke callbacks + if( typeof options.callback === 'function' ) { + options.callback.apply( null, [ instance ] ); + } + + }, false ); + } + })(); + + } + + } + + /** + * Stops ALL current loading animations. + */ + function stopAll() { + + for( var i = 0, len = ALL_INSTANCES.length; i < len; i++ ) { + ALL_INSTANCES[i].stop(); + } + + } + + function createSpinner( button ) { + + var height = button.offsetHeight, + spinnerColor; + + // If the button is tall we can afford some padding + if( height > 32 ) { + height *= 0.8; + } + + // Prefer an explicit height if one is defined + if( button.hasAttribute( 'data-spinner-size' ) ) { + height = parseInt( button.getAttribute( 'data-spinner-size' ), 10 ); + } + + // Allow buttons to specify the color of the spinner element + if (button.hasAttribute('data-spinner-color' ) ) { + spinnerColor = button.getAttribute( 'data-spinner-color' ); + } + + var lines = 12, + radius = height * 0.2, + length = radius * 0.6, + width = radius < 7 ? 2 : 3; + + return new Spinner( { + color: spinnerColor || '#fff', + lines: lines, + radius: radius, + length: length, + width: width, + zIndex: 'auto', + top: 'auto', + left: 'auto', + className: '' + } ); + + } + + function toArray( nodes ) { + + var a = []; + + for ( var i = 0; i < nodes.length; i++ ) { + a.push( nodes[ i ] ); + } + + return a; + + } + + // Public API + return { + + bind: bind, + create: create, + stopAll: stopAll + + }; + +})); diff --git a/forms/ladda_1.js b/forms/ladda_1.js new file mode 100644 index 0000000..e161f94 --- /dev/null +++ b/forms/ladda_1.js @@ -0,0 +1,314 @@ +/*! + * Ladda 0.8.0 + * http://lab.hakim.se/ladda + * MIT licensed + * + * Copyright (C) 2013 Hakim El Hattab, http://hakim.se + */ +(function( root, factory ) { + + // CommonJS + if( typeof exports === 'object' ) { + module.exports = factory(); + } + // AMD module + else if( typeof define === 'function' && define.amd ) { + define( [ 'spin' ], factory ); + } + // Browser global + else { + root.Ladda = factory( root.Spinner ); + } + +} +(this, function( Spinner ) { + 'use strict'; + + // All currently instantiated instances of Ladda + var ALL_INSTANCES = []; + + /** + * Creates a new instance of Ladda which wraps the + * target button element. + * + * @return An API object that can be used to control + * the loading animation state. + */ + function create( button ) { + + if( typeof button === 'undefined' ) { + console.warn( "Ladda button target must be defined." ); + return; + } + + // The text contents must be wrapped in a ladda-label + // element, create one if it doesn't already exist + if( !button.querySelector( '.ladda-label' ) ) { + button.innerHTML = ''+ button.innerHTML +''; + } + + // Create the spinner + var spinner = createSpinner( button ); + + // Wrapper element for the spinner + var spinnerWrapper = document.createElement( 'span' ); + spinnerWrapper.className = 'ladda-spinner'; + button.appendChild( spinnerWrapper ); + + // Timer used to delay starting/stopping + var timer; + + var instance = { + + /** + * Enter the loading state. + */ + start: function() { + + button.setAttribute( 'disabled', '' ); + button.setAttribute( 'data-loading', '' ); + + clearTimeout( timer ); + spinner.spin( spinnerWrapper ); + + this.setProgress( 0 ); + + return this; // chain + + }, + + /** + * Enter the loading state, after a delay. + */ + startAfter: function( delay ) { + + clearTimeout( timer ); + timer = setTimeout( function() { instance.start(); }, delay ); + + return this; // chain + + }, + + /** + * Exit the loading state. + */ + stop: function() { + + button.removeAttribute( 'disabled' ); + button.removeAttribute( 'data-loading' ); + + // Kill the animation after a delay to make sure it + // runs for the duration of the button transition + clearTimeout( timer ); + timer = setTimeout( function() { spinner.stop(); }, 1000 ); + + return this; // chain + + }, + + /** + * Toggle the loading state on/off. + */ + toggle: function() { + + if( this.isLoading() ) { + this.stop(); + } + else { + this.start(); + } + + return this; // chain + + }, + + /** + * Sets the width of the visual progress bar inside of + * this Ladda button + * + * @param {Number} progress in the range of 0-1 + */ + setProgress: function( progress ) { + + // Cap it + progress = Math.max( Math.min( progress, 1 ), 0 ); + + var progressElement = button.querySelector( '.ladda-progress' ); + + // Remove the progress bar if we're at 0 progress + if( progress === 0 && progressElement && progressElement.parentNode ) { + progressElement.parentNode.removeChild( progressElement ); + } + else { + if( !progressElement ) { + progressElement = document.createElement( 'div' ); + progressElement.className = 'ladda-progress'; + button.appendChild( progressElement ); + } + + progressElement.style.width = ( ( progress || 0 ) * button.offsetWidth ) + 'px'; + } + + }, + + enable: function() { + + this.stop(); + + return this; // chain + + }, + + disable: function () { + + this.stop(); + button.setAttribute( 'disabled', '' ); + + return this; // chain + + }, + + isLoading: function() { + + return button.hasAttribute( 'data-loading' ); + + } + + }; + + ALL_INSTANCES.push( instance ); + + return instance; + + } + + /** + * Binds the target buttons to automatically enter the + * loading state when clicked. + * + * @param target Either an HTML element or a CSS selector. + * @param options + * - timeout Number of milliseconds to wait before + * automatically cancelling the animation. + */ + function bind( target, options ) { + + options = options || {}; + + var targets = []; + + if( typeof target === 'string' ) { + targets = toArray( document.querySelectorAll( target ) ); + } + else if( typeof target === 'object' && typeof target.nodeName === 'string' ) { + targets = [ target ]; + } + + for( var i = 0, len = targets.length; i < len; i++ ) { + + (function() { + var element = targets[i]; + + // Make sure we're working with a DOM element + if( typeof element.addEventListener === 'function' ) { + var instance = create( element ); + var timeout = -1; + + element.addEventListener( 'click', function() { + + // This is asynchronous to avoid an issue where setting + // the disabled attribute on the button prevents forms + // from submitting + instance.startAfter( 1 ); + + // Set a loading timeout if one is specified + if( typeof options.timeout === 'number' ) { + clearTimeout( timeout ); + timeout = setTimeout( instance.stop, options.timeout ); + } + + // Invoke callbacks + if( typeof options.callback === 'function' ) { + options.callback.apply( null, [ instance ] ); + } + + }, false ); + } + })(); + + } + + } + + /** + * Stops ALL current loading animations. + */ + function stopAll() { + + for( var i = 0, len = ALL_INSTANCES.length; i < len; i++ ) { + ALL_INSTANCES[i].stop(); + } + + } + + function createSpinner( button ) { + + var height = button.offsetHeight, + spinnerColor; + + // If the button is tall we can afford some padding + if( height > 32 ) { + height *= 0.8; + } + + // Prefer an explicit height if one is defined + if( button.hasAttribute( 'data-spinner-size' ) ) { + height = parseInt( button.getAttribute( 'data-spinner-size' ), 10 ); + } + + // Allow buttons to specify the color of the spinner element + if (button.hasAttribute('data-spinner-color' ) ) { + spinnerColor = button.getAttribute( 'data-spinner-color' ); + } + + var lines = 12, + radius = height * 0.2, + length = radius * 0.6, + width = radius < 7 ? 2 : 3; + + return new Spinner( { + color: spinnerColor || '#fff', + lines: lines, + radius: radius, + length: length, + width: width, + zIndex: 'auto', + top: 'auto', + left: 'auto', + className: '' + } ); + + } + + function toArray( nodes ) { + + var a = []; + + for ( var i = 0; i < nodes.length; i++ ) { + a.push( nodes[ i ] ); + } + + return a; + + } + + // Public API + return { + + bind: bind, + create: create, + stopAll: stopAll + + }; + +})); diff --git a/forms/spin.js b/forms/spin.js new file mode 100644 index 0000000..b4fca55 --- /dev/null +++ b/forms/spin.js @@ -0,0 +1,349 @@ +//fgnass.github.com/spin.js#v1.3 + +/*! + * Copyright (c) 2011-2013 Felix Gnass + * Licensed under the MIT license + */ +(function(root, factory) { + + /* CommonJS */ + if (typeof exports == 'object') module.exports = factory() + + /* AMD module */ + else if (typeof define == 'function' && define.amd) define(factory) + + /* Browser global */ + else root.Spinner = factory() +} +(this, function() { + "use strict"; + + var prefixes = ['webkit', 'Moz', 'ms', 'O'] /* Vendor prefixes */ + , animations = {} /* Animation rules keyed by their name */ + , useCssAnimations /* Whether to use CSS animations or setTimeout */ + + /** + * Utility function to create elements. If no tag name is given, + * a DIV is created. Optionally properties can be passed. + */ + function createEl(tag, prop) { + var el = document.createElement(tag || 'div') + , n + + for(n in prop) el[n] = prop[n] + return el + } + + /** + * Appends children and returns the parent. + */ + function ins(parent /* child1, child2, ...*/) { + for (var i=1, n=arguments.length; i> 1) : parseInt(o.left, 10) + mid) + 'px', + top: (o.top == 'auto' ? tp.y-ep.y + (target.offsetHeight >> 1) : parseInt(o.top, 10) + mid) + 'px' + }) + } + + el.setAttribute('role', 'progressbar') + self.lines(el, self.opts) + + if (!useCssAnimations) { + // No CSS animation support, use setTimeout() instead + var i = 0 + , start = (o.lines - 1) * (1 - o.direction) / 2 + , alpha + , fps = o.fps + , f = fps/o.speed + , ostep = (1-o.opacity) / (f*o.trail / 100) + , astep = f/o.lines + + ;(function anim() { + i++; + for (var j = 0; j < o.lines; j++) { + alpha = Math.max(1 - (i + (o.lines - j) * astep) % f * ostep, o.opacity) + + self.opacity(el, j * o.direction + start, alpha, o) + } + self.timeout = self.el && setTimeout(anim, ~~(1000/fps)) + })() + } + return self + }, + + /** + * Stops and removes the Spinner. + */ + stop: function() { + var el = this.el + if (el) { + clearTimeout(this.timeout) + if (el.parentNode) el.parentNode.removeChild(el) + this.el = undefined + } + return this + }, + + /** + * Internal method that draws the individual lines. Will be overwritten + * in VML fallback mode below. + */ + lines: function(el, o) { + var i = 0 + , start = (o.lines - 1) * (1 - o.direction) / 2 + , seg + + function fill(color, shadow) { + return css(createEl(), { + position: 'absolute', + width: (o.length+o.width) + 'px', + height: o.width + 'px', + background: color, + boxShadow: shadow, + transformOrigin: 'left', + transform: 'rotate(' + ~~(360/o.lines*i+o.rotate) + 'deg) translate(' + o.radius+'px' +',0)', + borderRadius: (o.corners * o.width>>1) + 'px' + }) + } + + for (; i < o.lines; i++) { + seg = css(createEl(), { + position: 'absolute', + top: 1+~(o.width/2) + 'px', + transform: o.hwaccel ? 'translate3d(0,0,0)' : '', + opacity: o.opacity, + animation: useCssAnimations && addAnimation(o.opacity, o.trail, start + i * o.direction, o.lines) + ' ' + 1/o.speed + 's linear infinite' + }) + + if (o.shadow) ins(seg, css(fill('#000', '0 0 4px ' + '#000'), {top: 2+'px'})) + + ins(el, ins(seg, fill(o.color, '0 0 1px rgba(0,0,0,.1)'))) + } + return el + }, + + /** + * Internal method that adjusts the opacity of a single line. + * Will be overwritten in VML fallback mode below. + */ + opacity: function(el, i, val) { + if (i < el.childNodes.length) el.childNodes[i].style.opacity = val + } + + }) + + + function initVML() { + + /* Utility function to create a VML tag */ + function vml(tag, attr) { + return createEl('<' + tag + ' xmlns="urn:schemas-microsoft.com:vml" class="spin-vml">', attr) + } + + // No CSS transforms but VML support, add a CSS rule for VML elements: + sheet.addRule('.spin-vml', 'behavior:url(#default#VML)') + + Spinner.prototype.lines = function(el, o) { + var r = o.length+o.width + , s = 2*r + + function grp() { + return css( + vml('group', { + coordsize: s + ' ' + s, + coordorigin: -r + ' ' + -r + }), + { width: s, height: s } + ) + } + + var margin = -(o.width+o.length)*2 + 'px' + , g = css(grp(), {position: 'absolute', top: margin, left: margin}) + , i + + function seg(i, dx, filter) { + ins(g, + ins(css(grp(), {rotation: 360 / o.lines * i + 'deg', left: ~~dx}), + ins(css(vml('roundrect', {arcsize: o.corners}), { + width: r, + height: o.width, + left: o.radius, + top: -o.width>>1, + filter: filter + }), + vml('fill', {color: o.color, opacity: o.opacity}), + vml('stroke', {opacity: 0}) // transparent stroke to fix color bleeding upon opacity change + ) + ) + ) + } + + if (o.shadow) + for (i = 1; i <= o.lines; i++) + seg(i, -2, 'progid:DXImageTransform.Microsoft.Blur(pixelradius=2,makeshadow=1,shadowopacity=.3)') + + for (i = 1; i <= o.lines; i++) seg(i) + return ins(el, g) + } + + Spinner.prototype.opacity = function(el, i, val, o) { + var c = el.firstChild + o = o.shadow && o.lines || 0 + if (c && i+o < c.childNodes.length) { + c = c.childNodes[i+o]; c = c && c.firstChild; c = c && c.firstChild + if (c) c.opacity = val + } + } + } + + var probe = css(createEl('group'), {behavior: 'url(#default#VML)'}) + + if (!vendor(probe, 'transform') && probe.adj) initVML() + else useCssAnimations = vendor(probe, 'animation') + + return Spinner + +})); diff --git a/forms/spin_1.js b/forms/spin_1.js new file mode 100644 index 0000000..b4fca55 --- /dev/null +++ b/forms/spin_1.js @@ -0,0 +1,349 @@ +//fgnass.github.com/spin.js#v1.3 + +/*! + * Copyright (c) 2011-2013 Felix Gnass + * Licensed under the MIT license + */ +(function(root, factory) { + + /* CommonJS */ + if (typeof exports == 'object') module.exports = factory() + + /* AMD module */ + else if (typeof define == 'function' && define.amd) define(factory) + + /* Browser global */ + else root.Spinner = factory() +} +(this, function() { + "use strict"; + + var prefixes = ['webkit', 'Moz', 'ms', 'O'] /* Vendor prefixes */ + , animations = {} /* Animation rules keyed by their name */ + , useCssAnimations /* Whether to use CSS animations or setTimeout */ + + /** + * Utility function to create elements. If no tag name is given, + * a DIV is created. Optionally properties can be passed. + */ + function createEl(tag, prop) { + var el = document.createElement(tag || 'div') + , n + + for(n in prop) el[n] = prop[n] + return el + } + + /** + * Appends children and returns the parent. + */ + function ins(parent /* child1, child2, ...*/) { + for (var i=1, n=arguments.length; i> 1) : parseInt(o.left, 10) + mid) + 'px', + top: (o.top == 'auto' ? tp.y-ep.y + (target.offsetHeight >> 1) : parseInt(o.top, 10) + mid) + 'px' + }) + } + + el.setAttribute('role', 'progressbar') + self.lines(el, self.opts) + + if (!useCssAnimations) { + // No CSS animation support, use setTimeout() instead + var i = 0 + , start = (o.lines - 1) * (1 - o.direction) / 2 + , alpha + , fps = o.fps + , f = fps/o.speed + , ostep = (1-o.opacity) / (f*o.trail / 100) + , astep = f/o.lines + + ;(function anim() { + i++; + for (var j = 0; j < o.lines; j++) { + alpha = Math.max(1 - (i + (o.lines - j) * astep) % f * ostep, o.opacity) + + self.opacity(el, j * o.direction + start, alpha, o) + } + self.timeout = self.el && setTimeout(anim, ~~(1000/fps)) + })() + } + return self + }, + + /** + * Stops and removes the Spinner. + */ + stop: function() { + var el = this.el + if (el) { + clearTimeout(this.timeout) + if (el.parentNode) el.parentNode.removeChild(el) + this.el = undefined + } + return this + }, + + /** + * Internal method that draws the individual lines. Will be overwritten + * in VML fallback mode below. + */ + lines: function(el, o) { + var i = 0 + , start = (o.lines - 1) * (1 - o.direction) / 2 + , seg + + function fill(color, shadow) { + return css(createEl(), { + position: 'absolute', + width: (o.length+o.width) + 'px', + height: o.width + 'px', + background: color, + boxShadow: shadow, + transformOrigin: 'left', + transform: 'rotate(' + ~~(360/o.lines*i+o.rotate) + 'deg) translate(' + o.radius+'px' +',0)', + borderRadius: (o.corners * o.width>>1) + 'px' + }) + } + + for (; i < o.lines; i++) { + seg = css(createEl(), { + position: 'absolute', + top: 1+~(o.width/2) + 'px', + transform: o.hwaccel ? 'translate3d(0,0,0)' : '', + opacity: o.opacity, + animation: useCssAnimations && addAnimation(o.opacity, o.trail, start + i * o.direction, o.lines) + ' ' + 1/o.speed + 's linear infinite' + }) + + if (o.shadow) ins(seg, css(fill('#000', '0 0 4px ' + '#000'), {top: 2+'px'})) + + ins(el, ins(seg, fill(o.color, '0 0 1px rgba(0,0,0,.1)'))) + } + return el + }, + + /** + * Internal method that adjusts the opacity of a single line. + * Will be overwritten in VML fallback mode below. + */ + opacity: function(el, i, val) { + if (i < el.childNodes.length) el.childNodes[i].style.opacity = val + } + + }) + + + function initVML() { + + /* Utility function to create a VML tag */ + function vml(tag, attr) { + return createEl('<' + tag + ' xmlns="urn:schemas-microsoft.com:vml" class="spin-vml">', attr) + } + + // No CSS transforms but VML support, add a CSS rule for VML elements: + sheet.addRule('.spin-vml', 'behavior:url(#default#VML)') + + Spinner.prototype.lines = function(el, o) { + var r = o.length+o.width + , s = 2*r + + function grp() { + return css( + vml('group', { + coordsize: s + ' ' + s, + coordorigin: -r + ' ' + -r + }), + { width: s, height: s } + ) + } + + var margin = -(o.width+o.length)*2 + 'px' + , g = css(grp(), {position: 'absolute', top: margin, left: margin}) + , i + + function seg(i, dx, filter) { + ins(g, + ins(css(grp(), {rotation: 360 / o.lines * i + 'deg', left: ~~dx}), + ins(css(vml('roundrect', {arcsize: o.corners}), { + width: r, + height: o.width, + left: o.radius, + top: -o.width>>1, + filter: filter + }), + vml('fill', {color: o.color, opacity: o.opacity}), + vml('stroke', {opacity: 0}) // transparent stroke to fix color bleeding upon opacity change + ) + ) + ) + } + + if (o.shadow) + for (i = 1; i <= o.lines; i++) + seg(i, -2, 'progid:DXImageTransform.Microsoft.Blur(pixelradius=2,makeshadow=1,shadowopacity=.3)') + + for (i = 1; i <= o.lines; i++) seg(i) + return ins(el, g) + } + + Spinner.prototype.opacity = function(el, i, val, o) { + var c = el.firstChild + o = o.shadow && o.lines || 0 + if (c && i+o < c.childNodes.length) { + c = c.childNodes[i+o]; c = c && c.firstChild; c = c && c.firstChild + if (c) c.opacity = val + } + } + } + + var probe = css(createEl('group'), {behavior: 'url(#default#VML)'}) + + if (!vendor(probe, 'transform') && probe.adj) initVML() + else useCssAnimations = vendor(probe, 'animation') + + return Spinner + +})); diff --git a/functionsForm.php b/functionsForm.php new file mode 100644 index 0000000..ec42474 --- /dev/null +++ b/functionsForm.php @@ -0,0 +1,1521 @@ +formulario = '
$extra) { + $this->formulario .= $indice . '="' . $extra . '"'; + } + } + $this->formulario .= ' >'; + } + $this->sinFormulario = $sinFormulario; + + $this->context = Context::getContext(); + $this->_path = $modulePath; + $this->_modulePath = $pathToModule; + $this->ajax = $ajax; + if (!$this->ajax) { + if (version_compare(_PS_VERSION_, '1.6.0.0 ', '>=')) { + $this->addCSS('forms.css'); + } else { + $this->addCSS('forms.15.css'); + } + $this->addJS('forms.js'); + } + $this->idLang = Configuration::getGlobalValue('PS_LANG_DEFAULT'); + $this->idShop = Configuration::getGlobalValue('PS_SHOP_DEFAULT'); + $this->modulo = $modulo; + } + + /** + * Agrega html al formulario. + * @param string $html + * @return $this + */ + public function addToForm($html) { + $this->formulario .= $html; + + return $this; + } + + /** + * Devuelve el html del formulario. + * @param boolean $vaciarFormulario Si es true se vacia el form despues de devolver el html. + * @return string + */ + public function renderForm($vaciarFormulario = false) { + if (!$this->sinFormulario) { + $this->formulario .= '
'; + } + + $formulario = $this->formulario; + + if ($vaciarFormulario) { + $this->formulario = ''; + } + + return $formulario; + } + + /** + * Crea un elemento informativo + * @param string $text Texto a mostrar + * @param string $class Clase del elemento (warning (defecto), confirm) + * @return $this + */ + function createFormInfomationText($text, $class = 'warning') { + switch ($class) { + case 'warning': + $class = ' warning warn alert alert-warning '; + break; + case 'confirm': + $class = ' module_confirmation conf confirm alert alert-success '; + break; + default: + break; + } + $html = ''; + $html .= '
'; + $html .= '
'; + $html .= '

'; + $html .= $text; + $html .= '

'; + $html .= '
'; + $html .= '
'; + $this->formulario .= $html; + + return $this; + } + + /** + * + * @param string $name + * @param string $text + * @param string $title + * @param array $checks + * @param array $selectedValue + * @return $this + */ + public function createFormCheckboxGroupList($name, $text, $title, $checks, $selectedValue = array(), $extras = array()) { + $html = ''; + $html .= '
addExtras($extras); + $html .= '>'; + $html .= ''; + $html .= '
'; + foreach ($checks as $check) { + $marcado = ($selectedValue !== false && in_array($check['value'], $selectedValue) ? 'checked="checked"' : ''); + + $html .= '
'; + $html .= ' ' . $check['text']; + $html .= '
'; + } + $html .= '
'; + $html .= '
'; + + $this->formulario .= $html; + + return $this; + } + /** + * Crea un checkbox. + * @param string $name Nombre del checkbox + * @param string $text Texto informativo + * @param boolean $checked Marcado(true) o no(false), por defecto false + * @param string $title Titulo + * @param string $value El valor del checkbox. + * @return $this + */ + function createFormCheckboxGroup($name, $text, $checked = false, $title = '', $value = 1) { + $marcado = ''; + if ($checked == true) { + $marcado = ' checked="checked"'; + } + $html = ''; + $html .= '
'; + $html .= ''; + $html .= '
'; + $html .= ''; + $html .= '
'; + $html .= '
'; + $this->formulario .= $html; + + return $this; + } + + /** + * + * @param array $datos + * @param string $text + * @param array $extras + * @return $this + */ + function createFormRadioButtonGroup($datos, $text, $extras = false) { + $html = ''; + $html .= '
'; + $html .= ''; + $html .= '
'; + foreach ($datos AS $indice => $dato) { + $checked = ''; + if (isset($dato['checked']) && $dato['checked'] == 1) { + $checked = ' checked="checked"'; + } + $html .= '
'; + $html .= ''; + $html .= '
'; + } + $html .= '
'; + $html .= '
'; + $this->formulario .= $html; + + return $this; + } + + /** + * + * @param string $name + * @param string $contenido + * @param string $text + * @param string $title + * @param boolean $multiLang + * @param boolean $wysiwyg + * @return $this + */ + public function generarTextArea($name, $contenido, $text, $title = '', $multiLang = 0, $wysiwyg = 1, $array=false) { + $html = ''; + $html .= '
'; + $html .= ''; + if ($multiLang) { + $idiomas = $this->getLanguages(); + $idiomasSelect = $idiomas; + foreach ($idiomas AS $language) { + $html .= '
'; + $html .= '
'; + $html .= ''; + $html .= '
'; + } + $html .= '
'; + if ($wysiwyg) { + $html .= ''; + } + if($multiLang) { + $html .= ''; + } + $this->formulario .= $html; + + return $this; + } + + /** + * + * @param string $name + * @param string $value + * @param string $text + * @param string $title + * @param boolean $multiLang + * @param boolean $password + * @param array $extras + * @param boolean $autofocus + * @return $this + */ + function createFormTextGroup($name, $value, $text, $title = '', $multiLang = 0, $password = 0, $extras = false, $autofocus = false) { + $tipo = 'text'; + if ($password == 1) { + $tipo = 'password'; + } + + $html = '
'; + $html .= ''; + if ($multiLang) { + $idiomas = $this->getLanguages(); + $idiomasSelect = $idiomas; + foreach ($idiomas AS $language) { + $html .= '
'; + $html .= '
'; + $html .= ""; + $html .= '
'; + $html .= '
'; + $html .= ' '; + $html .= ' '; + $html .= '
'; + $html .= '
'; + } + } else { + $html .= '
'; + $html .= ' $extra) { + $html.= ' ' . $indice . '="' . $extra . '"'; + } + } + if ($autofocus) { + $html .= ' autofocus '; + } + $html .= '>'; + $html .= '
'; + } + $html .= '
'; + + $html .= ''; + + $this->formulario .= $html; + + return $this; + } + + /** + * + * @param string $name + * @param string $text + * @param string $title + * @param array $extras + * @return $this + */ + function createFormDate($name, $text, $title = '', $extras = false) { + $tipo = 'text'; + + + $html = '
'; + $html .= ''; + + $html .= '
'; + $html .= ' $extra) { + $html.= ' ' . $indice . '="' . $extra . '"'; + } + } + $html .= '>'; + $html .= '
'; + $html .= '
'; + $html .= ''; + + + $this->formulario .= $html; + + return $this; + } + + /** + * Permite crear un elemento de tipo color picker + * @param string $name + * @param string $value + * @param string $text + * @param string $title + * @param array $extras + * @param boolean $autofocus + */ + function createFormColorPicker($name, $value, $text, $title = '', $extras = false, $autofocus = false) { + $html = '
'; + $html .= ''; + $html .= '
'; + $html .= '
'; + $html .= '
'; + $html .= ' $extra) { + if ($indice == 'class') { + $class .= ' ' . $extra; + } else { + $html.= ' ' . $indice . '="' . $extra . '"'; + } + } + } + $html .= ' class="color mColorPickerInput'; + if ($class) { + $html .= ' ' . $class . '"'; + } else { + $html .= '"'; + } + if ($autofocus) { + $html .= ' autofocus '; + } + $html .= '>'; + $html .= '
'; + $html .= '
'; + $html .= '
'; + $html .= '
'; + $this->formulario .= $html; + } + + /** + * + * @param string $name + * @param string $value + * @param string $text + * @param string $title + * @param string $outputDelimiter + * @param string $paceholder + * @param array $options + * @return $this + */ + function createFormTagTextGroup($name, $value, $text, $title = '', $outputDelimiter = ',', $paceholder = 'Añadir etiqueta', $options = array()) { + $html = ''; + $this->addJS('jquery.tagify.js'); + $html .= '
'; + $html .= ''; + $html .= '
'; + $html .= ' $valor) { + if ($indice == 'class') { + $valor .= ' tagify'; + } + $html .= $indice . '="' . $valor . '"'; + } + } + $html .= '>'; + $html .= '
'; + $html .= '
'; + $html .= ''; + $this->formulario .= $html; + + return $this; + } + + /** + * + * @param string $name + * @param string $text + * @param int $defaultValue + * @param int $min + * @param int $max + * @param int $step + * @param string $title + * @return $this + */ + function createFormSelectNumerico($name, $text, $defaultValue, $min, $max, $step = 1, $title = '') { + $html = ''; + $html .= '
'; + $html .= ''; + $html .= '
'; + $html .= ''; + $html .= '
'; + $html .= '
'; + $this->formulario .= $html; + + return $this; + } + + function createHidden($name, $value) { + $html = ''; + $this->formulario .= $html; + + return $this; + } + + /** + * + * @param string $name + * @param string $text + * @param array $extras + * @return $this + */ + function createSubmitButton($name, $text, $extras = false) { + $html = ''; + $this->formulario .= $html; + + return $this; + } + + /** + * + * @param string $name + * @param string $text + * @param array $extras + * @param string $type + * @param string $icon + * @return $this + */ + public function createButton($name, $text, $extras = false, $type = 'button', $icon = 'plus') { + $html = ''; + $this->formulario .= $html; + + return $this; + } + + /** + * Crea un select. + * @param string $name + * @param array $text + * @param string $datos valor => visible + * @param string $defaultValue + * @param string $title + * @param array $extras + * @return $this + */ + function createFormSelect($name, $text, $datos, $defaultValue, $title = '', $extras = null) { + $html = ''; + $html .= '
'; + $html .= ''; + $html .= '
'; + $html .= ''; + $html .= '
'; + $html .= '
'; + $this->formulario .= $html; + + return $this; + } + + /** + * + * @param string $name + * @param string $label + * @param string $title + * @param string $url + * @return $this + */ + public function createFormFileButton($name, $label, $title, $url) { + $this->addJS('spin.js'); + $this->addJS('ladda.js'); + + $this->addJS('jquery.iframe-transport.js'); + $this->addJS('jquery.fileupload.js'); + $this->addJS('jquery.fileupload-process.js'); + $this->addJS('jquery.fileupload-validate.js'); + //$this->addJS('jquery.fileupload-image.js'); + + $html = ''; + $html .= '
'; + $html .= ''; + $html .= '
'; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= '
'; + + $html .= "'; + $html .= '
'; + $this->formulario .= $html; + + return $this; + } + + /** + * + * @param string $name + * @param string $text + * @param mixed $defaultValue + * @param string $title + * @return $this + */ + public function generarSelectIdioma($name, $text, $defaultValue, $title) { + $html = ''; + $html .= '
'; + $html .= ''; + $html .= '
'; + $html .= ''; + $html .= '
'; + $html .= '
'; + reset($idiomas); + $html .= ''; + $html .= ''; + $this->formulario .= $html; + + return $this; + } + + private function addCSS($css) { + $tab = Tools::getValue('tab', 0); + if (!$tab || ($tab && $tab != 'AdminSelfUpgrade')) { + if ($this->context->controller instanceof stdClass) { + $this->context->controller = new AdminModulesController(); + } + if ($this->_modulePath) { + $this->context->controller->addCss($this->_modulePath . '/forms/' . $css, 'all'); + } else { + $this->context->controller->addCss($this->_path . '/forms/' . $css, 'all'); + } + } + return; + } + + private function addJS($js) { + $tab = Tools::getValue('tab', 0); + if (!$tab || ($tab && $tab != 'AdminSelfUpgrade')) { + + if ($this->context->controller instanceof stdClass) { + $this->context->controller = new AdminModulesController(); + } + if ($this->_modulePath) { + $this->context->controller->addJs($this->_modulePath . '/forms/' . $js); + } else { + $this->context->controller->addJs($this->_path . '/forms/' . $js); + } + } + return; + } + + public function getLanguages() { + $languages = Language::getLanguages(); + return $languages; + } + + /** + * + * @param string $name + * @param string $text + * @param int $defaultValue + * @param string $title + * @return $this + */ + public function createSelectSupplier($name, $text, $defaultValue, $title = '') { + $suppliers = Supplier::getSuppliers(); + $html = ''; + $html .= '
'; + $html .= ''; + $html .= '
'; + $html .= ''; + $html .= '
'; + $html .= '
'; + $this->formulario .= $html; + + return $this; + } + + /** + * + * @param string $name + * @param string $text + * @param int $defaultValue + * @param string $title + * @return $this + */ + public function createSelectManufacturer($name, $text, $defaultValue, $title = '') { + $manufacturers = Manufacturer::getManufacturers(); + $html = ''; + $html .= '
'; + $html .= ''; + $html .= '
'; + $html .= ''; + $html .= '
'; + $html .= '
'; + $this->formulario .= $html; + + return $this; + } + + /** + * + * @param int $id_lang + * @param string $name + * @param string $text + * @param array $value + * @param string $title + * @return $this + */ + public function createSelectGroups($id_lang, $name, $text, $value, $title = '') { + $groups = Group::getGroups($id_lang); + $html = ''; + $html .= '
'; + $html .= ''; + $html .= '
'; + foreach ($groups as $group) { + $marcado = ''; + foreach ($value as $v) { + if ($group['id_group'] == $v) { + $marcado = ' checked '; + break; + } + } + $html .= ' ' . $group['name'] . '
'; + } + $html .= '
'; + $html .= '
'; + + $this->formulario .= $html; + return $this; + } + + /** + * + * @param int $id_lang + * @param string $name + * @param string $text + * @param array $value + * @param string $title + * @param boolean $referencia + * @return $this + */ + public function createCheckBoxCarriers($id_lang, $name, $text, $value, $title = '', $referencia = false) { + $carriers = Carrier::getCarriers($id_lang); + $html = ''; + $html .= '
'; + $html .= ''; + $html .= '
'; + foreach ($carriers as $carrier) { + $idCarrier = $carrier['id_carrier']; + if ($referencia) { + $idCarrier = $carrier['id_reference']; + } + $marcado = ''; + foreach ($value as $v) { + if ($idCarrier == $v) { + $marcado = ' checked '; + break; + } + } + $html .= ' ' . $carrier['name'] . '
'; + } + $html .= '
'; + $html .= '
'; + + $this->formulario .= $html; + return $this; + } + + /** + * + * @param int $id_lang + * @param string $name + * @param string $text + * @param array $idDefault + * @param string $title + * @param boolean $referencia + * @return $this + */ + public function createSelectCarriers($id_lang, $name, $text, $idDefault, $title = '', $referencia = false) { + $carriers = Carrier::getCarriers($id_lang); + $html = ''; + $html .= '
'; + $html .= ''; + $html .= '
'; + $html .= ''; + $html .= ''; + foreach ($images AS $image) { + $selected = ''; + if ($image['id_image_type'] == $defaultValue) { + $selected = ' selected="selected"'; + } + $html .= ''; + } + + $html .= ''; + $html .= '
'; + $html .= '
'; + $this->formulario .= $html; + + return $this; + } + + public function mostrarCategorias($name, $prefijo, $idParentCategoria = 2) { + $sql = ' SELECT ' + . ' c.id_category, c.id_parent, cl.name, s.id_category AS checked, s.margen ' + . ' FROM ' + . ' ' . _DB_PREFIX_ . 'category AS c ' + . ' INNER JOIN ' . _DB_PREFIX_ . 'category_lang AS cl ' + . ' ON ' + . ' cl.id_category = c.id_category ' + . ' AND cl.id_lang = ' . $this->idLang . '' + . ' AND c.id_shop_default = cl.id_shop ' + . ' AND c.id_shop_default = ' . $this->idShop . '' + . ' LEFT JOIN ' . _DB_PREFIX_ . $prefijo . 'categorias AS s ' + . ' ON s.id_category = c.id_category ' + . ' WHERE ' + . ' c.id_parent = ' . $idParentCategoria . ' ' + . ' ORDER BY ' + . ' c.id_parent, c.id_category '; + $categorias = Db::getInstance()->executeS($sql); + $html = ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + foreach ($categorias AS $categoria) { + $num = 0; + $html .= ''; + $html .= ''; + $checked = ""; + $porcentaje = ""; + if (!empty($categoria['checked'])) { + $checked = ' checked="checked"'; + $porcentaje = $categoria['margen']; + } + $html .= ''; + $html .= ''; + $html .= ''; + $this->getHijosTable($categoria, $html, $num, $prefijo); + } + + $html .= '
 ' . $this->modulo->l('Margen general') . ' 
' . $this->modulo->l('Categoria') . '' . $this->modulo->l('Marcar para Exportar') . '' . $this->modulo->l('Margen') . '
' . $categoria['name'] . '
'; + + $html .= ''; + + $html .= ''; + $this->formulario .= $html; + return $this; + } + + private function getHijosTable($categoria, &$html, &$num, $prefijo) { + $numInterno = $num; + $sqlHijos = ' SELECT ' + . ' c.id_category, c.id_parent, cl.name, s.id_category AS checked, s.margen ' + . ' FROM ' + . ' ' . _DB_PREFIX_ . 'category AS c ' + . ' INNER JOIN ' . _DB_PREFIX_ . 'category_lang AS cl ' + . ' ON ' + . ' cl.id_category = c.id_category ' + . ' AND cl.id_lang = ' . $this->idLang . ' ' + . ' AND c.id_shop_default = cl.id_shop ' + . ' AND c.id_shop_default = ' . $this->idShop . ' ' + . ' LEFT JOIN ' . _DB_PREFIX_ . $prefijo . 'categorias AS s ' + . ' ON s.id_category = c.id_category ' + . ' WHERE ' + . ' c.id_parent=' . $categoria['id_category']; + + $categoriasHijos = Db::getInstance()->executeS($sqlHijos); + $num++; + foreach ($categoriasHijos AS $categoriaHijo) { + $checked = ""; + $porcentaje = ""; + if (!empty($categoriaHijo['checked']) && $categoriaHijo['checked'] != null) { + $checked = ' checked="checked"'; + $porcentaje = $categoriaHijo['margen']; + } + $numClase = $num; + $html .= ''; + $html .= '' . str_repeat(" ", $num * 2) . $categoriaHijo['name'] . ''; + $html .= ''; + $html .= ''; + $html .= ''; + $this->getHijos($categoriaHijo, $html, $num); + } + $num = $numInterno; + } + + /** + * + * @param string $name + * @param string $text + * @param int $defaultValue + * @param string $title + * @param boolean $active + * @param boolean $chosen + * @return $this + */ + public function createSelectCategory($name, $text, $defaultValue, $title = '', $active = true, $chosen = false) { + $categories = Category::getHomeCategories($this->idLang, $active); + $html = ''; + $html .= '
'; + $html .= ''; + $html .= '
'; + $html .= ''; + $html .= '
'; + $html .= '
'; + if ($chosen) { + $html .= ''; + } + $this->formulario .= $html; + + return $this; + } + + private function getHijos($id_parent, $defaultValue, &$html, &$num, $active) { + $numInterno = $num; + $categories = Category::getChildren($id_parent, $this->idLang, $active); + if (!$categories) { + return; + } + $num++; + foreach ($categories AS $category) { + $selected = ''; + if ($category['id_category'] == $defaultValue) { + $selected = ' selected="selected"'; + } + $html .= ''; + $this->getHijos($category['id_category'], $defaultValue, $html, $num, $active); + } + $num = $numInterno; + return true; + } + + /** + * Crea un upload File. + * @param string $name Nombre del boton + * @param string $text Texto informativo + * @param string $title Titulo + * @return $this + */ + public function createFormUploadFile($name, $text, $title = '') { + $html = ''; + $html .= '
'; + $html .= ''; + $html .= '
'; + $html .= ''; + $html .= '
'; + $html .= '
'; + $this->formulario .= $html; + + return $this; + } + + /** + * Crea una tabla dinamica. + * @param string $name Identificador de la tabla. + * @param string $table Nombre de la tabla en la base de datos. + * @param string[] $campos Nombres de los campos en base de datos. + * @param string[] $camposBusqueda Nombres de los campos en base de datos para las busquedas. + * @param string $url Ruta base. + * @param string $serverfile Archivo de destino en el servidor. + * @param string $contenidoCabecera Los "tr" para la cabecera. + * @param string[] $codigoFormateadores [id del formateador => Contenido de la funcion formateadora, recibe los parametros column y row]. + * @param string $codigoEventoLoad Contenido de la funcion del evento load. La tabla viene en la variable grid. Tambien se dispone de e. + * @return $this + */ + function createTableAjax($name, $table, $campos, $camposBusqueda, $url, $serverfile, $contenidoCabecera, $codigoFormateadores = array(), $codigoEventoLoad = '') { + $html = '
'; + $html .= '' + . '' + . ' + + + ' . $contenidoCabecera . ' + +
'; + + $campos = urlencode(serialize($campos)); + $camposBusqueda = urlencode(serialize($camposBusqueda)); + $table = urlencode(trim($table)); + $codigoFormateadoresString = ''; + foreach ($codigoFormateadores as $idFormateador => $codigoFormateador) { + $codigoFormateadoresString .= <<'; + $html .= << + $(function() { + var grid = $("#$name").bootgrid( + { + ajax:true, + post: function() { + return { + id: "b0df282a-0d67-40e5-8558-c9e93b7befed" + }; + }, + url: "{$url}bootgrid/php/$serverfile?tabla=$table&campos=$campos&camposBusqueda=$camposBusqueda", + formatters: { + $codigoFormateadoresString + } + }).on("loaded.rs.jquery.bootgrid", function(e) + { + $codigoEventoLoad + }); + }); + +EOT; + $html .= '
'; + $this->formulario .= $html; + + return $this; + } + + private function addExtras($extras) { + $html = ''; + if ($extras && is_array($extras)) { + foreach ($extras AS $indice => $valor) { + $html .= $indice . '="' . $valor . '"'; + } + } + return $html; + } + + public function __toString() { + return $this->renderForm(true); + } + + public function createCheckBoxManufacturer($name, $defaultValue) { + $manufacturers = Manufacturer::getManufacturers(); + $html = ''; + $numElementos = count($manufacturers); + $elementos = ceil($numElementos / 3); + $intercambio = array_flip($defaultValue); + $i = 0; + $html .= '
'; + $html .= '
'; + foreach ($manufacturers as $m) { + $checked = ''; + if ($i == 0) { + $html .= '
    '; + } + $html .= '
  • '; + $html .= ''; + $html .= '
    '; + if (array_key_exists($m['id_manufacturer'], $intercambio)) { + $checked = "checked='checked'"; + } + + $html .= ''; + $html .= '
  • '; + $i++; + if ($i >= $elementos) { + $html .= '
'; + $i = 0; + } + } + $html .= ''; + $html .= '
'; + $html .= '
'; + + $this->formulario .= $html; + + return $this; + } + + /** + * + * @param int $id_lang + * @param string $name + * @param string $text + * @param array $values + * @param string $title + * @return $this + */ + public function createOptionStatuses($id_lang, $name, $text, $values, $title = '') { + $status = OrderState::getOrderStates($id_lang); + $html .= '
'; + $html .= ''; + $html .= '
'; + $html .= ''; + $html .= '
'; + $html .= '
'; + + $this->formulario .= $html; + return $this; + } + + /** + * + * @param string $name + * @param string $text + * @param int $defaultValue + * @param string $title + * @return $this + */ + public function createSelectStatuses($idLang, $name, $text, $defaultValue, $title = '') { + $status = OrderState::getOrderStates($idLang); + $html = '
'; + $html .= ''; + $html .= '
'; + $html .= ''; + $html .= '
'; + $html .= '
'; + $this->formulario .= $html; + + return $this; + } + + /** + * + * @param string $name + * @param string $text + * @param int $defaultValue + * @param string $title + * @return $this + */ + public function createSelectFeatures($idLang, $name, $text, $defaultValue, $title = '') { + $features = Feature::getFeatures($idLang); + + $html = '
'; + $html .= ''; + $html .= '
'; + $html .= ''; + $html .= '
'; + $html .= '
'; + $this->formulario .= $html; + + return $this; + } + + /** + * + * @param string $name + * @param string $text + * @param int $defaultValue + * @param string $title + * @return $this + */ + public function createSelectFeaturesValues($idLang, $name, $text, $defaultValue, $value, $title = '') { + $features = FeatureValueCore::getFeatureValuesWithLang($idLang, $value); + $html .= '
'; + $html .= ''; + $html .= '
'; + $html .= ''; + $html .= '
'; + $html .= '
'; + $this->formulario .= $html; + + return $this; + } + + /** + * Genera un select a partir de un array asociativo. + * @param string $name + * @param string $text + * @param array $datos + * @param string $claveId + * @param string $claveValores + * @param mixed $selectedValue + * @param string $title + * @param array $extras + * @return $this + */ + public function createFormSelectFromArray($name, $text, $datos, $claveId, $claveValores, $selectedValue, $title = '', $extras = null) { + $datosFormateados = array(); + foreach ($datos as $dato) { + $datosFormateados[$dato[$claveId]] = $dato[$claveValores]; + } + + return $this->createFormSelect($name, $text, $datosFormateados, $selectedValue, $title, $extras); + } + +} diff --git a/imaxAcordeon.php b/imaxAcordeon.php new file mode 100644 index 0000000..713665b --- /dev/null +++ b/imaxAcordeon.php @@ -0,0 +1,58 @@ +context = Context::getContext(); + $this->_path = $modulePath; + $this->addCSS('acordeon.css'); + $this->addJS('acordeon.js'); + } + + /** + * CREA UN ACORDEN + * @param string $titulo Titulo del acordeon + * @param string $contenido Html con todo el contenido + * @param boolean $interno True si va a estar dentro de otro acordeon + */ + function renderAcordeon($titulo, $contenido, $interno = false) { + $class = 'acordeon'; + if ($interno != false) { + $class = 'acordeonInterno'; + } + $html = ''; + $html = '
'; + $html .= '
' . $titulo . '
'; + $html .= '
'; + $html .= $contenido; + $html .= '
'; + $html .= '
'; + return $html; + } + + private function addCSS($css) { + $tab = Tools::getValue('tab', 0); + if (!$tab || ($tab && $tab != 'AdminSelfUpgrade')) { + if ($this->context->controller instanceof stdClass) { + $this->context->controller = new AdminModulesController(); + } + $this->context->controller->addCss($this->_path . 'acordeon/' . $css, 'all'); + } + return; + } + + private function addJS($js) { + $tab = Tools::getValue('tab', 0); + if (!$tab || ($tab && $tab != 'AdminSelfUpgrade')) { + if ($this->context->controller instanceof stdClass) { + $this->context->controller = new AdminModulesController(); + } + $this->context->controller->addJs($this->_path . 'acordeon/' . $js); + } + return; + } + +} diff --git a/imaxaddcatbyfeature.php b/imaxaddcatbyfeature.php new file mode 100644 index 0000000..0f766d6 --- /dev/null +++ b/imaxaddcatbyfeature.php @@ -0,0 +1,394 @@ +name = 'imaxaddcatbyfeature'; + $this->tab = 'administration'; + $this->version = '1.1'; + $this->author = 'Informax'; + $this->need_instance = 0; + $this->idManual = ''; + $this->forceCheck = 0; + $this->sufijo = self::prefijo; + parent::__construct(); + $this->displayName = $this->l('Informax add to category by feature'); + $this->description = $this->l('Informax add to category by feature'); + + if (version_compare(_PS_VERSION_, '1.7.0.0 ', '>=')) { + $this->versionPS = 17; + $context = Context::getContext(); + $this->idShop = $context->shop->id; + $this->idLang = $context->language->id; + } elseif (version_compare(_PS_VERSION_, '1.6.0.0 ', '>=')) { + $this->versionPS = 16; + $context = Context::getContext(); + $this->idShop = $context->shop->id; + $this->idLang = $context->language->id; + } elseif (version_compare(_PS_VERSION_, '1.5.0.0 ', '>=')) { + $this->versionPS = 15; + $context = Context::getContext(); + $this->idShop = $context->shop->id; + $this->idLang = $context->language->id; + } else { + $this->_html .= $this->l("La version minima de funcionamiento para nuestros modulos es la 1.5"); + } + } + + public function install() { + $directorioAdmin = getcwd(); + if (is_file(dirname(__FILE__) . '/' . $this->name . '_cron.php') && !@copy(dirname(__FILE__) . '/imaxaddcatbyfeature_cron.php', $directorioAdmin . '/imaxaddcatbyfeature_cron.php')) { + $this->_errors[] = $this->l('Ha fallado al copiar el fichero de cron'); + return false; + } + if (is_file(dirname(__FILE__) . '/' . $this->name . '_cron.php.imax') && !@copy(dirname(__FILE__) . '/imaxaddcatbyfeature_cron.php.imax', $directorioAdmin . '/imaxaddcatbyfeature_cron.php.imax')) { + $this->_errors[] = $this->l('Ha fallado al copiar el fichero de cron ofuscado'); + return false; + } + + include(dirname(__FILE__) . '/configuration.php'); + foreach ($configuracion AS $indice => $valor) { + if (!Configuration::updateGlobalValue($indice, $valor)) { + return false; + } + } + + if (!parent::install()) + return false; + + foreach ($hooks as $hook) { + if (!$this->registerHook($hook)) { + $this->_errors[] = $this->l('Ha fallado la instalacion del hook:') . ' ' . $hook; + return false; + } + } + + include(dirname(__FILE__) . '/sql-install.php'); + foreach ($sql as $s) { + if (!Db::getInstance()->execute($s)) { + $this->_errors[] = $this->l("Error al ejecutar") . $s; + return false; + } + } + + if (!$this->installTab()) { + $this->_errors[] = $this->l('Error al instalar el tab'); + return false; + } + + return true; + } + + public function uninstall() { + if (!parent::uninstall()) { + return false; + } + + include(dirname(__FILE__) . '/sql-unninstall.php'); + foreach ($sql as $s) { + if (!Db::getInstance()->execute($s)) { + $this->_errors[] = $this->l("Error al ejecutar") . $s; + return false; + } + } + $directorioAdmin = getcwd(); + + if (!unlink($directorioAdmin . '/imaxaddcatbyfeature_cron.php')) { + $this->_errors[] = $this->l('Error al borrar el fichero de Cron'); + return false; + } + + if (!$this->uninstallTab()) { + $this->_errors[] = $this->l('Error al eliminar el tab'); + return false; + } + + include(dirname(__FILE__) . '/configuration.php'); + foreach ($configuracion AS $indice => $valor) { + if (Configuration::getGlobalValue($indice) !== FALSE) { + if (!Configuration::deleteByName($indice)) { + return false; + } + } + } + + return true; + } + + public function getContent() { + $this->getTxtFiles(); + $this->addCSS('css.css'); + //$this->addJS('jquery.dynatree.min.js'); + $this->addJS('functions.js'); + $this->addCSS('../skin/ui.dynatree.css'); + $this->addCSS('publi.css'); + $this->_html .= $this->createHelpHeader(); + if (!empty($_POST)) + $this->_html .= $this->_postProcess(); + + $this->_displayForm(); + $this->_html .= $this->getModuleFooter(); + return $this->_html; + } + + private function _postProcess() { + $accion = Tools::getValue("accion"); + $this->idTab = Tools::getValue("idTab"); + $html = ""; + switch ($accion) { + case 'gestionLicencia': + $this->forceCheck = 1; + if (Configuration::updateGlobalValue(self::prefijo . 'LICENCIA', trim(Tools::getValue('licencia')))) { + $html .= $this->displayConfirmation($this->l('Licencia guardada correctamente.')); + } else { + $html .= $this->displayError($this->l('Ha ocurrido un error al guardar la licencia.')); + } + break; + + case 'configuracion': + if (Configuration::updateGlobalValue(self::prefijo . 'DIAS_NOVEDAD', trim(Tools::getValue('diasNovedad', 7))) && + Configuration::updateGlobalValue(self::prefijo . 'CATS_NOVEDAD', serialize(explode(',', Tools::getValue('catList'))))) { + $html .= $this->displayConfirmation($this->l('Configuracion guardada correctamente.')); + } else { + $html .= $this->displayError($this->l('Ha ocurrido un error al guardar la configuracion.')); + } + break; + + default: + break; + } + + return $html; + } + + public function _displayForm() { + return $this->displayFormTrait(array('_configuracion' => $this->l('Configuracion'), '_mostrarLicencia' => $this->l('Licencia')), ''); + } + + private function _mostrarLicencia() { + return $this->mostrarLicenciaTrait(2); + } + + private function _configuracion() { + include_once(dirname(__FILE__) . '/functionsForm.php'); + include_once(dirname(__FILE__) . '/imaxAcordeon.php'); + $diasNovedad = Configuration::getGlobalValue(self::prefijo . 'DIAS_NOVEDAD'); + $catsNovedad = unserialize(Configuration::getGlobalValue(self::prefijo . 'CATS_NOVEDAD')); + $token = Configuration::getGlobalValue(self::prefijo . 'TOKEN'); + $arbol = ''; + // + + $acordeon = new imaxAcordeon($this->_path); + + $form = new imaxForm($this, $this->_path); + $form->createHidden("accion", "configuracion"); + $form->createHidden("idTab", "1"); + $form->createHidden("catList", ""); + $form->addToForm($this->l('Buscador:') .$this->crearSelectCategorias()); + + $form->createSubmitButton('opcionesConfiguracion', $this->l('Guardar')); + $html = $acordeon->renderAcordeon($this->l('Configuracion'), $form->renderForm()); + + unset($form); + $form = new imaxForm($this, $this->_path); + $form->createHidden("accion", "generar_token"); + $form->createHidden("idTab", "1"); + + $text = '' . $this->l('ATENCION:') . ' ' . $this->l('Si cambia el token, tiene que cambiarlo tambien en las tareas de cron'); + $form->createFormInfomationText($text); + $urlTienda = self::getUrlAdmin(); + $form->createFormInfomationText($this->l('Debe enviar por get a la url de servicio, ya sea con curl o wget el que soporte su servidor, con esta opción se cambian todos los productos independientemente de si usa o no un actualizador de productos')); + $url = '' . $urlTienda . $this->name . '_cron.php?token=' . $token . ''; + $form->createFormInfomationText($url); + $form->createSubmitButton('opcionesConfiguracion', $this->l('Regenerar Token')); + $html .= $acordeon->renderAcordeon($this->l('Tareas Cron'), $form->renderForm()); + + return $html; + } + + /** + * Devuelve las funciones especificas del modulo. + * @return FuncionesImaxNovedades + */ + public function getFunciones() { + if (!self::$funciones) { + self::$funciones = new FuncionesImaxAddCatbyFeature($this); + } + + return self::$funciones; + } + + public function hookActionObjectProductAddAfter($params) { + //Si el producto es nuevo le agregamos categorias + $cats = unserialize(Configuration::getGlobalValue(self::prefijo . 'CATS_NOVEDAD')); + die(); + /* if($cats && time() - strtotime($params['object']->date_add) <= Configuration::getGlobalValue(self::prefijo.'DIAS_NOVEDAD') * 3600) { + $this->getFunciones()->agregarCategorias($params['object'], $cats); + } */ + } + + /** + * Elimina las categorias agregadas a los productos que ya no son novedad. + * @return int La cantidad de productos procesados. + */ + /* public function procesar() { + $dias = (int)Configuration::getGlobalValue(self::prefijo.'DIAS_NOVEDAD'); + $productos = Db::getInstance()->executeS(' + SELECT DISTINCT m.id_product FROM `'._DB_PREFIX_.self::prefijo.'movimiento` m + INNER JOIN `'._DB_PREFIX_."product` p ON m.id_product = p.id_product + WHERE DATEDIFF(NOW(), date_add) > $dias"); + foreach($productos as $producto) { + $this->getFunciones()->deshacerMovimientos(new Product($producto['id_product'])); + } + + return count($productos); + } */ + + public function procesar() { + if (!function_exists('procesar_')) { + $function = $this->getFunction(); + eval(gzuncompress(base64_decode($function))); + } + if (function_exists('procesar_')) { + return procesar_($this); + } + + echo $this->l('Este modulo no tiene una licencia valida: ') . $this->name; + echo '
'; + echo $this->l('Contacte con nosotros para obtener una licencia valida'); + die(); + } + + public function l($msg, $modulo = '', $locale = null) { + if ($modulo == '') { + $modulo = 'traducciones' . strtolower($this->name); + } + return parent::l($msg, $modulo, $locale); + } + + /** + * Devuelve el formulario para los criterios de desactivacion. + * @param int $idTab + * @return imaxForm + */ + public function getFormCriteriosNovedades($idTab) { + //Datos para js + $caracteristicas = Feature::getFeatures($this->idLang); + $caracteristicasFormateadas = array(0 => $this->modulo->l('- Seleccione uno -')); + $valoresCaracteristicaFormateados = array(); + foreach ($caracteristicas as $caracteristica) { + $caracteristicasFormateadas[$caracteristica['id_feature']] = $caracteristica['name']; + $valoresCaracteristica = FeatureValue::getFeatureValuesWithLang($this->idLang, $caracteristica['id_feature']); + if ($valoresCaracteristica) { + foreach ($valoresCaracteristica as $valorCaracteristica) { + if (!isset($valoresCaracteristicaFormateados[$caracteristica['id_feature']])) { + $valoresCaracteristicaFormateados[$caracteristica['id_feature']] = array(0 => $this->modulo->l('- Seleccione uno -')); + } + + $valoresCaracteristicaFormateados[$caracteristica['id_feature']][$valorCaracteristica['id_feature_value']] = $valorCaracteristica['value']; + } + } else { + $valoresCaracteristicaFormateados[$caracteristica['id_feature']] = array(0 => $this->modulo->l('- Seleccione uno -')); + } + } + $cats = $form = new imaxForm($this, $this->modulo->getPathUri()); + $form->createHidden("accion", "configurarCriteriosNovedad"); + $form->createHidden("idTab", $idTab); + $form->createFormTextGroup('numDiasNovedad', $numDiasNovedad, $this->modulo->l('Numero de dias a restar para los productos no nuevos')); + // $form->addToForm($this->crearSelectCategorias()); + /* $form->addToForm(' + + + + + + +
' . $this->modulo->l('Caracteristica') . '' . $this->modulo->l('Valor caracteristica') . '' . $this->modulo->l('Accion') . '
'); */ + + $form->createButton('agregarCriterioNovedad', $this->modulo->l('Nuevo')); + $form->createSubmitButton('save', $this->modulo->l('Guardar')); + return $form; + } + + /** + * Devuelve el html de las option de categorias. + * @return string + */ + public function crearSelectCategorias() { + $html = ''; + //$html .= ''; + $num = 0; + $categorias = $this->getHomeCategories($this->idLang); + foreach ($categorias AS $categoria) { + $html .= ''; + $this->getHijos($categoria, $html, $this->idLang, $num); + } + + return $html; + } + + private function getHijos($categoria, &$html, $id_lang = 1, &$num) { + $numInterno = $num; + $sqlHijos = "SELECT + DISTINCT c.id_category, c.id_parent, cl.name + FROM + " . _DB_PREFIX_ . "category AS c + INNER JOIN " . _DB_PREFIX_ . "category_lang AS cl + ON + cl.id_category = c.id_category AND + cl.id_lang = " . $this->idLang . " AND + cl.id_shop = c.id_shop_default + WHERE + c.id_parent=" . $categoria['id_category'] . " + AND c.id_shop_default = " . $this->idShop; + $categoriasHijos = Db::getInstance()->executeS($sqlHijos); + $num++; + foreach ($categoriasHijos AS $categoriaHijo) { + $html .= "'; + $objRespueta = $this->getHijos($categoriaHijo, $html, $id_lang, $num); + } + $num = $numInterno; + } + + public function getHomeCategories($id_lang, $id_shop = false, $active = true) { + if (!Validate::isBool($active)) + die(Tools::displayError()); + $query = 'SELECT ' + . ' c.`id_category`, cl.`name`, cl.`link_rewrite`, cs.`id_shop` ' + . ' FROM ' + . ' `' . _DB_PREFIX_ . 'category` c ' + . ' LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl ' + . ' ON (c.`id_category` = cl.`id_category`) ' + . ' INNER JOIN `' . _DB_PREFIX_ . 'category_shop` cs ' + . ' ON (cs.`id_category` = c.`id_category` ) ' + . ' WHERE ' + . ' `id_lang` = ' . $id_lang . ' ' + . ($id_shop ? ' AND cs.id_shop=' . $id_shop : ' ') + . ' AND c.`is_root_category` = 1 ' + . ' AND `active` = ' . $active + . ' GROUP BY c.`id_category` ' + . ' ORDER BY cs.`position` ASC '; + $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query); + return $result; + } + +} diff --git a/imaxaddcatbyfeature_cron.php b/imaxaddcatbyfeature_cron.php new file mode 100644 index 0000000..a9dfe5b --- /dev/null +++ b/imaxaddcatbyfeature_cron.php @@ -0,0 +1,15 @@ +procesar(); +echo $imaxaddcatbyfeature->l('Se han procesado').' '.$resultado.' '.$imaxaddcatbyfeature->l('producto(s)'); \ No newline at end of file diff --git a/img/abrir-ticket.png b/img/abrir-ticket.png new file mode 100644 index 0000000..2032f64 Binary files /dev/null and b/img/abrir-ticket.png differ diff --git a/img/borrar.png b/img/borrar.png new file mode 100644 index 0000000..0da306d Binary files /dev/null and b/img/borrar.png differ diff --git a/img/close.png b/img/close.png new file mode 100644 index 0000000..fcc23c6 Binary files /dev/null and b/img/close.png differ diff --git a/img/help.jpg b/img/help.jpg new file mode 100644 index 0000000..cabe1bd Binary files /dev/null and b/img/help.jpg differ diff --git a/img/help.png b/img/help.png new file mode 100644 index 0000000..383020d Binary files /dev/null and b/img/help.png differ diff --git a/img/help__.png b/img/help__.png new file mode 100644 index 0000000..7afebd6 Binary files /dev/null and b/img/help__.png differ diff --git a/img/informax.png b/img/informax.png new file mode 100644 index 0000000..74a176a Binary files /dev/null and b/img/informax.png differ diff --git a/img/ir-a-manuales.png b/img/ir-a-manuales.png new file mode 100644 index 0000000..206a8fb Binary files /dev/null and b/img/ir-a-manuales.png differ diff --git a/img/manual.jpg b/img/manual.jpg new file mode 100644 index 0000000..5a40dde Binary files /dev/null and b/img/manual.jpg differ diff --git a/img/manual.png b/img/manual.png new file mode 100644 index 0000000..2955a7f Binary files /dev/null and b/img/manual.png differ diff --git a/img/manual__.png b/img/manual__.png new file mode 100644 index 0000000..3ee274c Binary files /dev/null and b/img/manual__.png differ diff --git a/img/open.png b/img/open.png new file mode 100644 index 0000000..6f034d0 Binary files /dev/null and b/img/open.png differ diff --git a/js/functions.js b/js/functions.js new file mode 100644 index 0000000..6ad7c49 --- /dev/null +++ b/js/functions.js @@ -0,0 +1,134 @@ +$(function () { + $("#arbolCategorias").dynatree({ + checkbox: true, + selectMode: 2, + debugLevel: 0, + onDblClick: function (node, event) { + //Marcar una opción al hacerle doble click + node.toggleSelect(); + }, + onKeydown: function (node, event) { + //Marcar la opción activa usando la barra espaciadora + if (event.which == 32) { + node.toggleSelect(); + return false; + } + }, + // The following options are only required, if we have more than one tree on one page: + // initId: "treeData", + cookieId: "dynatree-Cb3", + idPrefix: "dynatree-Cb3-" + }); + + //Expandir los nodos activos + var arbol = $("#arbolCategorias").dynatree("getTree"); + var marcados = arbol.getSelectedNodes(false); + for (var i = 0, len = marcados.length; i < len; i++) { + marcados[i].makeVisible(); + } + + //Buscador + $('input[name="buscador"]').keyup(function () { + var texto = $(this).val(); + var arbol = $("#arbolCategorias").dynatree("getTree"); + arbol.getRoot().toDict(true, function (dict) { + if (dict.title !== null) { + var nodo = arbol.getNodeByKey(dict.key); + if (texto !== '' && dict.title.toLowerCase().search(texto.toLowerCase()) >= 0) { + //Lo marcamos + nodo.makeVisible(); + $(nodo.span).addClass('imax_marcado'); + } + else { + //Lo desmarcamos + $(nodo.span).removeClass('imax_marcado'); + } + } + }); + }); + + //Botón enviar + $('button[name="opcionesConfiguracion"]').click(function () { + //Así accedo a los ids de los check marcados + var arbolCat = $("#arbolCategorias").dynatree("getTree"); + var marcadosCat = arbolCat.getSelectedNodes(false); + + var catString = ""; + for (var x in marcadosCat) { + catString += marcadosCat[x].data.key + ","; + } + if (catString.length > 0) { + catString = catString.substring(0, catString.length - 1); + } + $('[name="catList"]').val(catString); + $(this).parent().submit(); + }); +}); + + + +//Agregamos los criterios de desactivacion + $('#tablaCriteriosDesactivacion tbody').sortable({ + stop: rellenarOrden + }); + for(var i in criteriosSeleccionados) { + agregarFilaCriterioDesactivacion(criteriosSeleccionados[i]['caracteristicaSeleccionada'], criteriosSeleccionados[i]['valorCaracteristicaSeleccionado'], criteriosSeleccionados[i]['tipoSeleccionado']); + } + $('button[name="agregarCriterio"]').click(function() { + agregarFilaCriterioDesactivacion(); + }); + + +/** + * Pone valor al input de orden. + */ +function rellenarOrden() { + var orden = 0; + $('#tablaCriteriosDesactivacion input[name*="orden"]').each(function() { + $(this).val(orden); + orden++; + }); +} + +/** + * Agrega una fila de desactivacion en la tabla. + * @param {int} caracteristicaSeleccionada + * @param {int} valorCaracteristicaSeleccionado + * @param {int} tipoSeleccionado + */ +function agregarFilaCriterioDesactivacion(caracteristicaSeleccionada, valorCaracteristicaSeleccionado, tipoSeleccionado) { + var indice = -1; + $('#tablaCriteriosDesactivacion').find('td:first-child').children('select[name^="desactivacion"]').each(function() { + var nombreTemp = $(this).attr('name').split('['); + var indiceTemp = nombreTemp[1].substr(0, nombreTemp[1].length - 1); + if(indiceTemp > indice) { + indice = indiceTemp; + } + }); + indice++; + + var html = ''; + html += '' + generarSelectDesactivacion('caracteristicaSeleccionada', indice, caracteristicasFormateadas, caracteristicaSeleccionada) + ''; + html += '' + generarSelectDesactivacion('valorCaracteristicaSeleccionado', indice, (typeof valoresCaracteristicaFormateados[caracteristicaSeleccionada] !== 'undefined' ? valoresCaracteristicaFormateados[caracteristicaSeleccionada] : { 0: '- Seleccione uno -' }), valorCaracteristicaSeleccionado) + ''; + html += '' + generarSelectDesactivacion('tipoSeleccionado', indice, tiposFormateados, tipoSeleccionado) + ''; + html += ' '; + html += ''; + + var fila = $(html); + //Eliminar fila + fila.find('input[name="eliminarFilaCriterioDesactivacion"]').click(function() { + $(this).parent().parent().remove(); + }); + //Modificar el select de valores + fila.find('select[name*="caracteristicaSeleccionada"]').change(function() { + var parent = fila.find('select[name*="valorCaracteristicaSeleccionado"]').parent(); + var nombreTemp = $(this).attr('name').split('['); + var indiceTemp = nombreTemp[1].substr(0, nombreTemp[1].length - 1); + fila.find('select[name*="valorCaracteristicaSeleccionado"]').remove(); + parent.append(generarSelectDesactivacion('valorCaracteristicaSeleccionado', indiceTemp, (typeof valoresCaracteristicaFormateados[$(this).val()] !== 'undefined' ? valoresCaracteristicaFormateados[$(this).val()] : { 0: '- Seleccione uno -' }))); + }); + + $('#tablaCriteriosDesactivacion tbody').append(fila); + + rellenarOrden(); +} diff --git a/js/jquery.dynatree.min.js b/js/jquery.dynatree.min.js new file mode 100644 index 0000000..0dc3853 --- /dev/null +++ b/js/jquery.dynatree.min.js @@ -0,0 +1,4 @@ +/*! jQuery Dynatree Plugin - v1.2.4 - 2013-02-12 +* http://dynatree.googlecode.com/ +* Copyright (c) 2013 Martin Wendt; Licensed MIT, GPL */ +function _log(e,t){if(!_canLog)return;var n=Array.prototype.slice.apply(arguments,[1]),r=new Date,i=r.getHours()+":"+r.getMinutes()+":"+r.getSeconds()+"."+r.getMilliseconds();n[0]=i+" - "+n[0];try{switch(e){case"info":window.console.info.apply(window.console,n);break;case"warn":window.console.warn.apply(window.console,n);break;default:window.console.log.apply(window.console,n)}}catch(s){window.console?s.number===-2146827850&&window.console.log(n.join(", ")):_canLog=!1}}function _checkBrowser(){function n(e){e=e.toLowerCase();var t=/(chrome)[ \/]([\w.]+)/.exec(e)||/(webkit)[ \/]([\w.]+)/.exec(e)||/(opera)(?:.*version|)[ \/]([\w.]+)/.exec(e)||/(msie) ([\w.]+)/.exec(e)||e.indexOf("compatible")<0&&/(mozilla)(?:.*? rv:([\w.]+)|)/.exec(e)||[];return{browser:t[1]||"",version:t[2]||"0"}}var e,t;return e=n(navigator.userAgent),t={},e.browser&&(t[e.browser]=!0,t.version=e.version),t.chrome?t.webkit=!0:t.webkit&&(t.safari=!0),t}function logMsg(e){Array.prototype.unshift.apply(arguments,["debug"]),_log.apply(this,arguments)}var _canLog=!0,BROWSER=jQuery.browser||_checkBrowser(),getDynaTreePersistData=null,DTNodeStatus_Error=-1,DTNodeStatus_Loading=1,DTNodeStatus_Ok=0;(function($){function getDtNodeFromElement(e){return alert("getDtNodeFromElement is deprecated"),$.ui.dynatree.getNode(e)}function noop(){}function versionCompare(e,t){var n=(""+e).split("."),r=(""+t).split("."),i=Math.min(n.length,r.length),s,o,u;for(u=0;uo?1:s
"},start:function(e,t){var n=t.helper.data("dtSourceNode");return!!n},_last:null}),t&&t.onDrop&&e.$tree.droppable({addClasses:!1,tolerance:"intersect",greedy:!1,_last:null})}var Class={create:function(){return function(){this.initialize.apply(this,arguments)}}},DynaTreeNode=Class.create();DynaTreeNode.prototype={initialize:function(e,t,n){this.parent=e,this.tree=t,typeof n=="string"&&(n={title:n}),n.key?n.key=""+n.key:n.key="_"+t._nodeCount++,this.data=$.extend({},$.ui.dynatree.nodedatadefaults,n),this.li=null,this.span=null,this.ul=null,this.childList=null,this._isLoading=!1,this.hasSubSel=!1,this.bExpanded=!1,this.bSelected=!1},toString:function(){return"DynaTreeNode<"+this.data.key+">: '"+this.data.title+"'"},toDict:function(e,t){var n=$.extend({},this.data);n.activate=this.tree.activeNode===this,n.focus=this.tree.focusNode===this,n.expand=this.bExpanded,n.select=this.bSelected,t&&t(n);if(e&&this.childList){n.children=[];for(var r=0,i=this.childList.length;r1&&(s+=n.tagConnector):this.hasChildren()!==!1?s+=n.tagExpander:s+=n.tagConnector,t.checkbox&&i.hideCheckbox!==!0&&!i.isStatusNode&&(s+=n.tagCheckbox),i.icon?(i.icon.charAt(0)==="/"?o=i.icon:o=t.imagePath+i.icon,s+=""):i.icon!==!1&&(i.iconClass?s+="":s+=n.tagNodeIcon);var u="";t.onCustomRender&&(u=t.onCustomRender.call(e,this)||"");if(!u){var a=i.tooltip?' title="'+i.tooltip.replace(/\"/g,""")+'"':"",f=i.href||"#";t.noLink||i.noLink?u='"+i.title+"":u='"+i.title+""}return s+=u,s},_fixOrder:function(){var e=this.childList;if(!e||!this.ul)return;var t=this.ul.firstChild;for(var n=0,r=e.length-1;n1?this.ul.className=o.container+" "+o.noConnector:this.ul.className=o.container;else if(r){this.li||(a=!0,this.li=document.createElement("li"),this.li.dtnode=this,i.key&&s.generateIds&&(this.li.id=s.idPrefix+i.key),this.span=document.createElement("span"),this.span.className=o.title,this.li.appendChild(this.span),r.ul||(r.ul=document.createElement("ul"),r.ul.style.display="none",r.li.appendChild(r.ul)),r.ul.appendChild(this.li)),this.span.innerHTML=this._getInnerHtml();var f=[];f.push(o.node),i.isFolder&&f.push(o.folder),this.bExpanded&&f.push(o.expanded),this.hasChildren()!==!1&&f.push(o.hasChildren),i.isLazy&&this.childList===null&&f.push(o.lazy),u&&f.push(o.lastsib),this.bSelected&&f.push(o.selected),this.hasSubSel&&f.push(o.partsel),n.activeNode===this&&f.push(o.active),i.addClass&&f.push(i.addClass),f.push(o.combinedExpanderPrefix+(this.bExpanded?"e":"c")+(i.isLazy&&this.childList===null?"d":"")+(u?"l":"")),f.push(o.combinedIconPrefix+(this.bExpanded?"e":"c")+(i.isFolder?"f":"")),this.span.className=f.join(" "),this.li.className=u?o.lastsib:"",a&&s.onCreate&&s.onCreate.call(n,this,this.span),s.onRender&&s.onRender.call(n,this,this.span)}if((this.bExpanded||t===!0)&&this.childList){for(var l=0,c=this.childList.length;lr?1:-1},n.sort(e);if(t)for(var r=0,i=n.length;r0?this.childList[0].focus():this.focus());break;case DTNodeStatus_Loading:this._isLoading=!0,$(this.span).addClass(this.tree.options.classNames.nodeLoading),this.parent||this._setStatusNode({title:this.tree.options.strings.loading+r,tooltip:n,addClass:this.tree.options.classNames.nodeWait});break;case DTNodeStatus_Error:this._isLoading=!1,this._setStatusNode({title:this.tree.options.strings.loadError+r,tooltip:n,addClass:this.tree.options.classNames.nodeError});break;default:throw"Bad LazyNodeStatus: '"+e+"'."}},_parentList:function(e,t){var n=[],r=t?this:this.parent;while(r)(e||r.parent)&&n.unshift(r),r=r.parent;return n},getLevel:function(){var e=0,t=this.parent;while(t)e++,t=t.parent;return e},_getTypeForOuterNodeEvent:function(e){var t=this.tree.options.classNames,n=e.target;if(n.className.indexOf(t.node)<0)return null;var r=e.pageX-n.offsetLeft,i=e.pageY-n.offsetTop;for(var s=0,o=n.childNodes.length;s=a&&r<=a+l&&i>=f&&i<=f+c){if(u.className==t.title)return"title";if(u.className==t.expander)return"expander";if(u.className==t.checkbox)return"checkbox";if(u.className==t.nodeIcon)return"icon"}}return"prefix"},getEventTargetType:function(e){var t=e&&e.target?e.target.className:"",n=this.tree.options.classNames;return t===n.title?"title":t===n.expander?"expander":t===n.checkbox?"checkbox":t===n.nodeIcon?"icon":t===n.empty||t===n.vline||t===n.connector?"prefix":t.indexOf(n.node)>=0?this._getTypeForOuterNodeEvent(e):null},isVisible:function(){var e=this._parentList(!0,!1);for(var t=0,n=e.length;ta").focus()}catch(e){}},isFocused:function(){return this.tree.tnFocused===this},_activate:function(e,t){this.tree.logDebug("dtnode._activate(%o, fireEvents=%o) - %o",e,t,this);var n=this.tree.options;if(this.data.isStatusNode)return;if(t&&n.onQueryActivate&&n.onQueryActivate.call(this.tree,e,this)===!1)return;if(e){if(this.tree.activeNode){if(this.tree.activeNode===this)return;this.tree.activeNode.deactivate()}n.activeVisible&&this.makeVisible(),this.tree.activeNode=this,n.persist&&$.cookie(n.cookieId+"-active",this.data.key,n.cookie),this.tree.persistence.activeKey=this.data.key,$(this.span).addClass(n.classNames.active),t&&n.onActivate&&n.onActivate.call(this.tree,this)}else if(this.tree.activeNode===this){if(n.onQueryActivate&&n.onQueryActivate.call(this.tree,!1,this)===!1)return;$(this.span).removeClass(n.classNames.active),n.persist&&$.cookie(n.cookieId+"-active","",n.cookie),this.tree.persistence.activeKey=null,this.tree.activeNode=null,t&&n.onDeactivate&&n.onDeactivate.call(this.tree,this)}},activate:function(){this._activate(!0,!0)},activateSilently:function(){this._activate(!0,!1)},deactivate:function(){this._activate(!1,!0)},isActive:function(){return this.tree.activeNode===this},_userActivate:function(){var e=!0,t=!1;if(this.data.isFolder)switch(this.tree.options.clickFolderMode){case 2:e=!1,t=!0;break;case 3:e=t=!0}this.parent===null&&(t=!1),t&&(this.toggleExpand(),this.focus()),e&&this.activate()},_setSubSel:function(e){e?(this.hasSubSel=!0,$(this.span).addClass(this.tree.options.classNames.partsel)):(this.hasSubSel=!1,$(this.span).removeClass(this.tree.options.classNames.partsel))},_updatePartSelectionState:function(){var e;if(!this.hasChildren())return e=this.bSelected&&!this.data.unselectable&&!this.data.isStatusNode,this._setSubSel(!1),e;var t,n,r=this.childList,i=!0,s=!0;for(t=0,n=r.length;t=0;i--){n=r[i].getNextSibling();if(n)break}}n&&n.focus();break;default:t=!1}t&&e.preventDefault()},_onKeypress:function(e){},_onFocus:function(e){var t=this.tree.options;if(e.type=="blur"||e.type=="focusout")t.onBlur&&t.onBlur.call(this.tree,this),this.tree.tnFocused&&$(this.tree.tnFocused.span).removeClass(t.classNames.focused),this.tree.tnFocused=null,t.persist&&$.cookie(t.cookieId+"-focus","",t.cookie);else if(e.type=="focus"||e.type=="focusin")this.tree.tnFocused&&this.tree.tnFocused!==this&&(this.tree.logDebug("dtnode.onFocus: out of sync: curFocus: %o",this.tree.tnFocused),$(this.tree.tnFocused.span).removeClass(t.classNames.focused)),this.tree.tnFocused=this,t.onFocus&&t.onFocus.call(this.tree,this),$(this.tree.tnFocused.span).addClass(t.classNames.focused),t.persist&&$.cookie(t.cookieId+"-focus",this.data.key,t.cookie)},visit:function(e,t){var n=!0;if(t===!0){n=e(this);if(n===!1||n=="skip")return n}if(this.childList)for(var r=0,i=this.childList.length;r reloading %s...",this,e,u);var a=this;u.reloadChildren(function(i,s){s?(n.logDebug("%s._loadKeyPath(%s) -> reloaded %s.",i,e,i),t.call(n,u,"loaded"),i._loadKeyPath(r.join(n.options.keyPathSeparator),t)):(n.logWarning("%s._loadKeyPath(%s) -> reloadChildren() failed.",a,e),t.call(n,u,"error"))})}return}}t.call(n,undefined,"notfound",i,r.length===0),n.logWarning("Node not found: "+i);return},resetLazy:function(){if(this.parent===null)throw"Use tree.reload() instead";if(!this.data.isLazy)throw"node.resetLazy() requires lazy nodes.";this.expand(!1),this.removeChildren()},_addChildNode:function(e,t){var n=this.tree,r=n.options,i=n.persistence;e.parent=this,this.childList===null?this.childList=[]:t||this.childList.length>0&&$(this.childList[this.childList.length-1].span).removeClass(r.classNames.lastsib);if(t){var s=$.inArray(t,this.childList);if(s<0)throw" must be a child of ";this.childList.splice(s,0,e)}else this.childList.push(e);var o=n.isInitializing();r.persist&&i.cookiesFound&&o?(i.activeKey===e.data.key&&(n.activeNode=e),i.focusedKey===e.data.key&&(n.focusNode=e),e.bExpanded=$.inArray(e.data.key,i.expandedKeyList)>=0,e.bSelected=$.inArray(e.data.key,i.selectedKeyList)>=0):(e.data.activate&&(n.activeNode=e,r.persist&&(i.activeKey=e.data.key)),e.data.focus&&(n.focusNode=e,r.persist&&(i.focusedKey=e.data.key)),e.bExpanded=e.data.expand===!0,e.bExpanded&&r.persist&&i.addExpand(e.data.key),e.bSelected=e.data.select===!0,e.bSelected&&r.persist&&i.addSelect(e.data.key)),r.minExpandLevel>=e.getLevel()&&(this.bExpanded=!0);if(e.bSelected&&r.selectMode==3){var u=this;while(u)u.hasSubSel||u._setSubSel(!0),u=u.parent}return n.bEnableUpdate&&this.render(),e},addChild:function(e,t){if(typeof e=="string")throw"Invalid data type for "+e;if(!e||e.length===0)return;if(e instanceof DynaTreeNode)return this._addChildNode(e,t);e.length||(e=[e]);var n=this.tree.enableUpdate(!1),r=null;for(var i=0,s=e.length;i=0&&(this.expandedKeyList.splice(t,1),$.cookie(this.cookieId+"-expand",this.expandedKeyList.join(","),this.cookieOpts))},addSelect:function(e){$.inArray(e,this.selectedKeyList)<0&&(this.selectedKeyList.push(e),$.cookie(this.cookieId+"-select",this.selectedKeyList.join(","),this.cookieOpts))},clearSelect:function(e){var t=$.inArray(e,this.selectedKeyList);t>=0&&(this.selectedKeyList.splice(t,1),$.cookie(this.cookieId+"-select",this.selectedKeyList.join(","),this.cookieOpts))},isReloading:function(){return this.cookiesFound===!0},toDict:function(){return{cookiesFound:this.cookiesFound,activeKey:this.activeKey,focusedKey:this.activeKey,expandedKeyList:this.expandedKeyList,selectedKeyList:this.selectedKeyList}},lastentry:undefined};var DynaTree=Class.create();DynaTree.version="$Version:$",DynaTree.prototype={initialize:function(e){this.phase="init",this.$widget=e,this.options=e.options,this.$tree=e.element,this.timer=null,this.divTree=this.$tree.get(0),_initDragAndDrop(this)},_load:function(e){var t=this.$widget,n=this.options,r=this;this.bEnableUpdate=!0,this._nodeCount=1,this.activeNode=null,this.focusNode=null,n.rootVisible!==undefined&&this.logWarning("Option 'rootVisible' is no longer supported."),n.minExpandLevel<1&&(this.logWarning("Option 'minExpandLevel' must be >= 1."),n.minExpandLevel=1),n.classNames!==$.ui.dynatree.prototype.options.classNames&&(n.classNames=$.extend({},$.ui.dynatree.prototype.options.classNames,n.classNames)),n.ajaxDefaults!==$.ui.dynatree.prototype.options.ajaxDefaults&&(n.ajaxDefaults=$.extend({},$.ui.dynatree.prototype.options.ajaxDefaults,n.ajaxDefaults)),n.dnd!==$.ui.dynatree.prototype.options.dnd&&(n.dnd=$.extend({},$.ui.dynatree.prototype.options.dnd,n.dnd)),n.imagePath||$("script").each(function(){var e=/.*dynatree[^\/]*\.js$/i;if(this.src.search(e)>=0)return this.src.indexOf("/")>=0?n.imagePath=this.src.slice(0,this.src.lastIndexOf("/"))+"/skin/":n.imagePath="skin/",r.logDebug("Guessing imagePath from '%s': '%s'",this.src,n.imagePath),!1}),this.persistence=new DynaTreeStatus(n.cookieId,n.cookie),n.persist&&($.cookie||_log("warn","Please include jquery.cookie.js to use persistence."),this.persistence.read()),this.logDebug("DynaTree.persistence: %o",this.persistence.toDict()),this.cache={tagEmpty:"",tagVline:"",tagExpander:"",tagConnector:"",tagNodeIcon:"",tagCheckbox:"",lastentry:undefined},(n.children||n.initAjax&&n.initAjax.url||n.initId)&&$(this.divTree).empty();var i=this.$tree.find(">ul:first").hide();this.tnRoot=new DynaTreeNode(null,this,{}),this.tnRoot.bExpanded=!0,this.tnRoot.render(),this.divTree.appendChild(this.tnRoot.ul);var s=this.tnRoot,o=n.persist&&this.persistence.isReloading(),u=!1,a=this.enableUpdate(!1);this.logDebug("Dynatree._load(): read tree structure..."),n.children?s.addChild(n.children):n.initAjax&&n.initAjax.url?(u=!0,s.data.isLazy=!0,this._reloadAjax(e)):n.initId?this._createFromTag(s,$("#"+n.initId)):(this._createFromTag(s,i),i.remove()),this._checkConsistency(),!u&&n.selectMode==3&&s._updatePartSelectionState(),this.logDebug("Dynatree._load(): render nodes..."),this.enableUpdate(a),this.logDebug("Dynatree._load(): bind events..."),this.$widget.bind(),this.logDebug("Dynatree._load(): postInit..."),this.phase="postInit",n.persist&&this.persistence.write(),this.focusNode&&this.focusNode.isVisible()&&(this.logDebug("Focus on init: %o",this.focusNode),this.focusNode.focus()),u||(n.onPostInit&&n.onPostInit.call(this,o,!1),e&&e.call(this,"ok")),this.phase="idle"},_reloadAjax:function(e){var t=this.options;if(!t.initAjax||!t.initAjax.url)throw"tree.reload() requires 'initAjax' mode.";var n=this.persistence,r=$.extend({},t.initAjax);r.addActiveKey&&(r.data.activeKey=n.activeKey),r.addFocusedKey&&(r.data.focusedKey=n.focusedKey),r.addExpandedKeyList&&(r.data.expandedKeyList=n.expandedKeyList.join(",")),r.addSelectedKeyList&&(r.data.selectedKeyList=n.selectedKeyList.join(",")),r.success&&this.logWarning("initAjax: success callback is ignored; use onPostInit instead."),r.error&&this.logWarning("initAjax: error callback is ignored; use onPostInit instead.");var i=n.isReloading();r.success=function(n,r,s){t.selectMode==3&&n.tree.tnRoot._updatePartSelectionState(),t.onPostInit&&t.onPostInit.call(n.tree,i,!1),e&&e.call(n.tree,"ok")},r.error=function(n,r,s,o){t.onPostInit&&t.onPostInit.call(n.tree,i,!0,r,s,o),e&&e.call(n.tree,"error",r,s,o)},this.logDebug("Dynatree._init(): send Ajax request..."),this.tnRoot.appendAjax(r)},toString:function(){return"Dynatree '"+this.$tree.attr("id")+"'"},toDict:function(){return this.tnRoot.toDict(!0)},serializeArray:function(e){var t=this.getSelectedNodes(e),n=this.$tree.attr("name")||this.$tree.attr("id"),r=[];for(var i=0,s=t.length;i=2&&(Array.prototype.unshift.apply(arguments,["debug"]),_log.apply(this,arguments))},logInfo:function(e){this.options.debugLevel>=1&&(Array.prototype.unshift.apply(arguments,["info"]),_log.apply(this,arguments))},logWarning:function(e){Array.prototype.unshift.apply(arguments,["warn"]),_log.apply(this,arguments)},isInitializing:function(){return this.phase=="init"||this.phase=="postInit"},isReloading:function(){return(this.phase=="init"||this.phase=="postInit")&&this.options.persist&&this.persistence.cookiesFound},isUserEvent:function(){return this.phase=="userEvent"},redraw:function(){this.tnRoot.render(!1,!1)},renderInvisibleNodes:function(){this.tnRoot.render(!1,!0)},reload:function(e){this._load(e)},getRoot:function(){return this.tnRoot},enable:function(){this.$widget.enable()},disable:function(){this.$widget.disable()},getNodeByKey:function(e){var t=document.getElementById(this.options.idPrefix+e);if(t)return t.dtnode?t.dtnode:null;var n=null;return this.visit(function(t){if(t.data.key===e)return n=t,!1},!0),n},getActiveNode:function(){return this.activeNode},reactivate:function(e){var t=this.activeNode;t&&(this.activeNode=null,t.activate(),e&&t.focus())},getSelectedNodes:function(e){var t=[];return this.tnRoot.visit(function(n){if(n.bSelected){t.push(n);if(e===!0)return"skip"}}),t},activateKey:function(e){var t=e===null?null:this.getNodeByKey(e);return t?(t.focus(),t.activate(),t):(this.activeNode&&this.activeNode.deactivate(),this.activeNode=null,null)},loadKeyPath:function(e,t){var n=e.split(this.options.keyPathSeparator);return n[0]===""&&n.shift(),n[0]==this.tnRoot.data.key&&(this.logDebug("Removed leading root key."),n.shift()),e=n.join(this.options.keyPathSeparator),this.tnRoot._loadKeyPath(e,t)},selectKey:function(e,t){var n=this.getNodeByKey(e);return n?(n.select(t),n):null},enableUpdate:function(e){return this.bEnableUpdate==e?e:(this.bEnableUpdate=e,e&&this.redraw(),!e)},count:function(){return this.tnRoot.countChildren()},visit:function(e,t){return this.tnRoot.visit(e,t)},_createFromTag:function(parentTreeNode,$ulParent){var self=this;$ulParent.find(">li").each(function(){var $li=$(this),$liSpan=$li.find(">span:first"),$liA=$li.find(">a:first"),title,href=null,target=null,tooltip;if($liSpan.length)title=$liSpan.html();else if($liA.length)title=$liA.html(),href=$liA.attr("href"),target=$liA.attr("target"),tooltip=$liA.attr("title");else{title=$li.html();var iPos=title.search(/
    =0?title=$.trim(title.substring(0,iPos)):title=$.trim(title)}var data={title:title,tooltip:tooltip,isFolder:$li.hasClass("folder"),isLazy:$li.hasClass("lazy"),expand:$li.hasClass("expanded"),select:$li.hasClass("selected"),activate:$li.hasClass("active"),focus:$li.hasClass("focused"),noLink:$li.hasClass("noLink")};href&&(data.href=href,data.target=target),$li.attr("title")&&(data.tooltip=$li.attr("title")),$li.attr("id")&&(data.key=""+$li.attr("id"));if($li.attr("data")){var dataAttr=$.trim($li.attr("data"));if(dataAttr){dataAttr.charAt(0)!="{"&&(dataAttr="{"+dataAttr+"}");try{$.extend(data,eval("("+dataAttr+")"))}catch(e){throw"Error parsing node data: "+e+"\ndata:\n'"+dataAttr+"'"}}}var childNode=parentTreeNode.addChild(data),$ul=$li.find(">ul:first");$ul.length&&self._createFromTag(childNode,$ul)})},_checkConsistency:function(){},_setDndStatus:function(e,t,n,r,i){var s=e?$(e.span):null,o=$(t.span);this.$dndMarker||(this.$dndMarker=$("
    ").hide().css({"z-index":1e3}).prependTo($(this.divTree).parent()));if(r==="after"||r==="before"||r==="over"){var u="0 0";switch(r){case"before":this.$dndMarker.removeClass("dynatree-drop-after dynatree-drop-over"),this.$dndMarker.addClass("dynatree-drop-before"),u="0 -8";break;case"after":this.$dndMarker.removeClass("dynatree-drop-before dynatree-drop-over"),this.$dndMarker.addClass("dynatree-drop-after"),u="0 8";break;default:this.$dndMarker.removeClass("dynatree-drop-after dynatree-drop-before"),this.$dndMarker.addClass("dynatree-drop-over"),o.addClass("dynatree-drop-target"),u="8 0"}this.$dndMarker.show().position({my:"left top",at:"left top",of:o,offset:u})}else o.removeClass("dynatree-drop-target"),this.$dndMarker.hide();r==="after"?o.addClass("dynatree-drop-after"):o.removeClass("dynatree-drop-after"),r==="before"?o.addClass("dynatree-drop-before"):o.removeClass("dynatree-drop-before"),i===!0?(s&&s.addClass("dynatree-drop-accept"),o.addClass("dynatree-drop-accept"),n.addClass("dynatree-drop-accept")):(s&&s.removeClass("dynatree-drop-accept"),o.removeClass("dynatree-drop-accept"),n.removeClass("dynatree-drop-accept")),i===!1?(s&&s.addClass("dynatree-drop-reject"),o.addClass("dynatree-drop-reject"),n.addClass("dynatree-drop-reject")):(s&&s.removeClass("dynatree-drop-reject"),o.removeClass("dynatree-drop-reject"),n.removeClass("dynatree-drop-reject"))},_onDragEvent:function(e,t,n,r,i,s){var o=this.options,u=this.options.dnd,a=null,f=$(t.span),l,c;switch(e){case"helper":var h=$("
    ").append($(r.target).closest(".dynatree-title").clone());$("ul.dynatree-container",t.tree.divTree).append(h),h.data("dtSourceNode",t),a=h;break;case"start":t.isStatusNode()?a=!1:u.onDragStart&&(a=u.onDragStart(t)),a===!1?(this.logDebug("tree.onDragStart() cancelled"),i.helper.trigger("mouseup"),i.helper.hide()):f.addClass("dynatree-drag-source");break;case"enter":a=u.onDragEnter?u.onDragEnter(t,n):null,a?a={over:a===!0||a==="over"||$.inArray("over",a)>=0,before:a===!0||a==="before"||$.inArray("before",a)>=0,after:a===!0||a==="after"||$.inArray("after",a)>=0}:a=!1,i.helper.data("enterResponse",a);break;case"over":c=i.helper.data("enterResponse"),l=null;if(c!==!1)if(typeof c=="string")l=c;else{var p=f.offset(),d={x:r.pageX-p.left,y:r.pageY-p.top},v={x:d.x/f.width(),y:d.y/f.height()};c.after&&v.y>.75?l="after":!c.over&&c.after&&v.y>.5?l="after":c.before&&v.y<=.25?l="before":!c.over&&c.before&&v.y<=.5?l="before":c.over&&(l="over"),u.preventVoidMoves&&(t===n?l=null:l==="before"&&n&&t===n.getNextSibling()?l=null:l==="after"&&n&&t===n.getPrevSibling()?l=null:l==="over"&&n&&n.parent===t&&n.isLastSibling()&&(l=null)),i.helper.data("hitMode",l)}l==="over"&&u.autoExpandMS&&t.hasChildren()!==!1&&!t.bExpanded&&t.scheduleAction("expand",u.autoExpandMS);if(l&&u.onDragOver){a=u.onDragOver(t,n,l);if(a==="over"||a==="before"||a==="after")l=a}this._setDndStatus(n,t,i.helper,l,a!==!1&&l!==null);break;case"drop":var m=i.helper.hasClass("dynatree-drop-reject");l=i.helper.data("hitMode"),l&&u.onDrop&&!m&&u.onDrop(t,n,l,i,s);break;case"leave":t.scheduleAction("cancel"),i.helper.data("enterResponse",null),i.helper.data("hitMode",null),this._setDndStatus(n,t,i.helper,"out",undefined),u.onDragLeave&&u.onDragLeave(t,n);break;case"stop":f.removeClass("dynatree-drag-source"),u.onDragStop&&u.onDragStop(t);break;default:throw"Unsupported drag event: "+e}return a},cancelDrag:function(){var e=$.ui.ddmanager.current;e&&e.cancel()},lastentry:undefined},$.widget("ui.dynatree",{_init:function(){if(versionCompare($.ui.version,"1.8")<0)return this.options.debugLevel>=0&&_log("warn","ui.dynatree._init() was called; you should upgrade to jquery.ui.core.js v1.8 or higher."),this._create();this.options.debugLevel>=2&&_log("debug","ui.dynatree._init() was called; no current default functionality.")},_create:function(){var e=this.options;e.debugLevel>=1&&logMsg("Dynatree._create(): version='%s', debugLevel=%o.",$.ui.dynatree.version,this.options.debugLevel),this.options.event+=".dynatree";var t=this.element.get(0);this.tree=new DynaTree(this),this.tree._load(),this.tree.logDebug("Dynatree._init(): done.")},bind:function(){function t(e){e=$.event.fix(e||window.event);var t=$.ui.dynatree.getNode(e.target);return t?t._onFocus(e):!1}this.unbind();var e="click.dynatree dblclick.dynatree";this.options.keyboard&&(e+=" keypress.dynatree keydown.dynatree"),this.element.bind(e,function(e){var t=$.ui.dynatree.getNode(e.target);if(!t)return!0;var n=t.tree,r=n.options;n.logDebug("event(%s): dtnode: %s",e.type,t);var i=n.phase;n.phase="userEvent";try{switch(e.type){case"click":return r.onClick&&r.onClick.call(n,t,e)===!1?!1:t._onClick(e);case"dblclick":return r.onDblClick&&r.onDblClick.call(n,t,e)===!1?!1:t._onDblClick(e);case"keydown":return r.onKeydown&&r.onKeydown.call(n,t,e)===!1?!1:t._onKeydown(e);case"keypress":return r.onKeypress&&r.onKeypress.call(n,t,e)===!1?!1:t._onKeypress(e)}}catch(s){var o=null;n.logWarning("bind(%o): dtnode: %o, error: %o",e,t,s)}finally{n.phase=i}});var n=this.tree.divTree;n.addEventListener?(n.addEventListener("focus",t,!0),n.addEventListener("blur",t,!0)):n.onfocusin=n.onfocusout=t},unbind:function(){this.element.unbind(".dynatree")},enable:function(){this.bind(),$.Widget.prototype.enable.apply(this,arguments)},disable:function(){this.unbind(),$.Widget.prototype.disable.apply(this,arguments)},getTree:function(){return this.tree},getRoot:function(){return this.tree.getRoot()},getActiveNode:function(){return this.tree.getActiveNode()},getSelectedNodes:function(){return this.tree.getSelectedNodes()},lastentry:undefined}),versionCompare($.ui.version,"1.8")<0&&($.ui.dynatree.getter="getTree getRoot getActiveNode getSelectedNodes"),$.ui.dynatree.version="$Version:$",$.ui.dynatree.getNode=function(e){if(e instanceof DynaTreeNode)return e;e.selector!==undefined&&(e=e[0]);while(e){if(e.dtnode)return e.dtnode;e=e.parentNode}return null},$.ui.dynatree.getPersistData=DynaTreeStatus._getTreePersistData,$.ui.dynatree.prototype.options={title:"Dynatree",minExpandLevel:1,imagePath:null,children:null,initId:null,initAjax:null,autoFocus:!0,keyboard:!0,persist:!1,autoCollapse:!1,clickFolderMode:3,activeVisible:!0,checkbox:!1,selectMode:2,fx:null,noLink:!1,onClick:null,onDblClick:null,onKeydown:null,onKeypress:null,onFocus:null,onBlur:null,onQueryActivate:null,onQuerySelect:null,onQueryExpand:null,onPostInit:null,onActivate:null,onDeactivate:null,onSelect:null,onExpand:null,onLazyRead:null,onCustomRender:null,onCreate:null,onRender:null,postProcess:null,dnd:{onDragStart:null,onDragStop:null,autoExpandMS:1e3,preventVoidMoves:!0,onDragEnter:null,onDragOver:null,onDrop:null,onDragLeave:null},ajaxDefaults:{cache:!1,timeout:0,dataType:"json"},strings:{loading:"Loading…",loadError:"Load error!"},generateIds:!1,idPrefix:"dynatree-id-",keyPathSeparator:"/",cookieId:"dynatree",cookie:{expires:null},classNames:{container:"dynatree-container",node:"dynatree-node",folder:"dynatree-folder",empty:"dynatree-empty",vline:"dynatree-vline",expander:"dynatree-expander",connector:"dynatree-connector",checkbox:"dynatree-checkbox",nodeIcon:"dynatree-icon",title:"dynatree-title",noConnector:"dynatree-no-connector",nodeError:"dynatree-statusnode-error",nodeWait:"dynatree-statusnode-wait",hidden:"dynatree-hidden",combinedExpanderPrefix:"dynatree-exp-",combinedIconPrefix:"dynatree-ico-",nodeLoading:"dynatree-loading",hasChildren:"dynatree-has-children",active:"dynatree-active",selected:"dynatree-selected",expanded:"dynatree-expanded",lazy:"dynatree-lazy",focused:"dynatree-focused",partsel:"dynatree-partsel",lastsib:"dynatree-lastsib"},debugLevel:2,lastentry:undefined},versionCompare($.ui.version,"1.8")<0&&($.ui.dynatree.defaults=$.ui.dynatree.prototype.options),$.ui.dynatree.nodedatadefaults={title:null,key:null,isFolder:!1,isLazy:!1,tooltip:null,href:null,icon:null,addClass:null,noLink:!1,activate:!1,focus:!1,expand:!1,select:!1,hideCheckbox:!1,unselectable:!1,children:null,lastentry:undefined};var didRegisterDnd=!1,_registerDnd=function(){if(didRegisterDnd)return;$.ui.plugin.add("draggable","connectToDynatree",{start:function(e,t){var n=$(this).data("ui-draggable")||$(this).data("draggable"),r=t.helper.data("dtSourceNode")||null;if(r)return n.offset.click.top=-2,n.offset.click.left=16,r.tree._onDragEvent("start",r,null,e,t,n)},drag:function(e,t){var n=$(this).data("ui-draggable")||$(this).data("draggable"),r=t.helper.data("dtSourceNode")||null,i=t.helper.data("dtTargetNode")||null,s=$.ui.dynatree.getNode(e.target);if(e.target&&!s){var o=$(e.target).closest("div.dynatree-drag-helper,#dynatree-drop-marker").length>0;if(o)return}t.helper.data("dtTargetNode",s),i&&i!==s&&i.tree._onDragEvent("leave",i,r,e,t,n),s&&(!s.tree.options.dnd.onDrop||(s===i?s.tree._onDragEvent("over",s,r,e,t,n):s.tree._onDragEvent("enter",s,r,e,t,n)))},stop:function(e,t){var n=$(this).data("ui-draggable")||$(this).data("draggable"),r=t.helper.data("dtSourceNode")||null,i=t.helper.data("dtTargetNode")||null,s=n._mouseDownEvent,o=e.type,u=o=="mouseup"&&e.which==1;logMsg("draggable-connectToDynatree.stop: targetNode(from event): %s, dtTargetNode: %s",i,t.helper.data("dtTargetNode")),u||logMsg("Drag was cancelled"),i&&(u&&i.tree._onDragEvent("drop",i,r,e,t,n),i.tree._onDragEvent("leave",i,r,e,t,n)),r&&r.tree._onDragEvent("stop",r,null,e,t,n)}}),didRegisterDnd=!0}})(jQuery); diff --git a/logo.gif b/logo.gif new file mode 100644 index 0000000..dc437a5 Binary files /dev/null and b/logo.gif differ diff --git a/logo.jpg b/logo.jpg new file mode 100644 index 0000000..b35f2ed Binary files /dev/null and b/logo.jpg differ diff --git a/logo.png b/logo.png new file mode 100644 index 0000000..dc0a0f0 Binary files /dev/null and b/logo.png differ diff --git a/skin/digits.png b/skin/digits.png new file mode 100644 index 0000000..eb7c467 Binary files /dev/null and b/skin/digits.png differ diff --git a/skin/icons-rtl.gif b/skin/icons-rtl.gif new file mode 100644 index 0000000..a29b5fb Binary files /dev/null and b/skin/icons-rtl.gif differ diff --git a/skin/icons.gif b/skin/icons.gif new file mode 100644 index 0000000..a58eb93 Binary files /dev/null and b/skin/icons.gif differ diff --git a/skin/loading.gif b/skin/loading.gif new file mode 100644 index 0000000..251df05 Binary files /dev/null and b/skin/loading.gif differ diff --git a/skin/ui.dynatree.css b/skin/ui.dynatree.css new file mode 100644 index 0000000..29679b4 --- /dev/null +++ b/skin/ui.dynatree.css @@ -0,0 +1,440 @@ +/******************************************************************************* + * Tree container + */ +ul.dynatree-container +{ + font-family: tahoma, arial, helvetica; + font-size: 10pt; /* font size should not be too big */ + white-space: nowrap; + padding: 3px; + margin: 0; /* issue 201 */ + background-color: white; + border: 1px dotted gray; + overflow: auto; + height: 100%; /* issue 263 */ +} + +ul.dynatree-container ul +{ + padding: 0 0 0 16px; + margin: 0; +} + +ul.dynatree-container li +{ + list-style-image: none; + list-style-position: outside; + list-style-type: none; + -moz-background-clip:border; + -moz-background-inline-policy: continuous; + -moz-background-origin: padding; + background-attachment: scroll; + background-color: transparent; + background-repeat: repeat-y; + background-image: url("vline.gif"); + background-position: 0 0; + /* + background-image: url("icons_96x256.gif"); + background-position: -80px -64px; + */ + margin: 0; + padding: 1px 0 0 0; +} +/* Suppress lines for last child node */ +ul.dynatree-container li.dynatree-lastsib +{ + background-image: none; +} +/* Suppress lines if level is fixed expanded (option minExpandLevel) */ +ul.dynatree-no-connector > li +{ + background-image: none; +} + +/* Style, when control is disabled */ +.ui-dynatree-disabled ul.dynatree-container +{ + opacity: 0.5; +/* filter: alpha(opacity=50); /* Yields a css warning */ + background-color: silver; +} + +/******************************************************************************* + * Common icon definitions + */ +span.dynatree-empty, +span.dynatree-vline, +span.dynatree-connector, +span.dynatree-expander, +span.dynatree-icon, +span.dynatree-checkbox, +span.dynatree-radio, +span.dynatree-drag-helper-img, +#dynatree-drop-marker +{ + width: 16px; + height: 16px; +/* display: -moz-inline-box; /* @ FF 1+2 removed for issue 221 */ +/* -moz-box-align: start; /* issue 221 */ + display: inline-block; /* Required to make a span sizeable */ + vertical-align: top; + background-repeat: no-repeat; + background-position: left; + background-image: url("icons.gif"); + background-position: 0 0; +} + +/** Used by 'icon' node option: */ +ul.dynatree-container img +{ + width: 16px; + height: 16px; + margin-left: 3px; + vertical-align: top; + border-style: none; +} + + +/******************************************************************************* + * Lines and connectors + */ + +span.dynatree-connector +{ + background-position: -16px -64px; +} + +/******************************************************************************* + * Expander icon + * Note: IE6 doesn't correctly evaluate multiples class names, + * so we create combined class names that can be used in the CSS. + * + * Prefix: dynatree-exp- + * 1st character: 'e': expanded, 'c': collapsed + * 2nd character (optional): 'd': lazy (Delayed) + * 3rd character (optional): 'l': Last sibling + */ + +span.dynatree-expander +{ + background-position: 0px -80px; + cursor: pointer; +} +.dynatree-exp-cl span.dynatree-expander /* Collapsed, not delayed, last sibling */ +{ + background-position: 0px -96px; +} +.dynatree-exp-cd span.dynatree-expander /* Collapsed, delayed, not last sibling */ +{ + background-position: -64px -80px; +} +.dynatree-exp-cdl span.dynatree-expander /* Collapsed, delayed, last sibling */ +{ + background-position: -64px -96px; +} +.dynatree-exp-e span.dynatree-expander, /* Expanded, not delayed, not last sibling */ +.dynatree-exp-ed span.dynatree-expander /* Expanded, delayed, not last sibling */ +{ + background-position: -32px -80px; +} +.dynatree-exp-el span.dynatree-expander, /* Expanded, not delayed, last sibling */ +.dynatree-exp-edl span.dynatree-expander /* Expanded, delayed, last sibling */ +{ + background-position: -32px -96px; +} +.dynatree-loading span.dynatree-expander /* 'Loading' status overrides all others */ +{ + background-position: 0 0; + background-image: url("loading.gif"); +} + + +/******************************************************************************* + * Checkbox icon + */ +span.dynatree-checkbox +{ + margin-left: 3px; + background-position: 0px -32px; +} +span.dynatree-checkbox:hover +{ + background-position: -16px -32px; +} + +.dynatree-partsel span.dynatree-checkbox +{ + background-position: -64px -32px; +} +.dynatree-partsel span.dynatree-checkbox:hover +{ + background-position: -80px -32px; +} + +.dynatree-selected span.dynatree-checkbox +{ + background-position: -32px -32px; +} +.dynatree-selected span.dynatree-checkbox:hover +{ + background-position: -48px -32px; +} + +/******************************************************************************* + * Radiobutton icon + * This is a customization, that may be activated by overriding the 'checkbox' + * class name as 'dynatree-radio' in the tree options. + */ +span.dynatree-radio +{ + margin-left: 3px; + background-position: 0px -48px; +} +span.dynatree-radio:hover +{ + background-position: -16px -48px; +} + +.dynatree-partsel span.dynatree-radio +{ + background-position: -64px -48px; +} +.dynatree-partsel span.dynatree-radio:hover +{ + background-position: -80px -48px; +} + +.dynatree-selected span.dynatree-radio +{ + background-position: -32px -48px; +} +.dynatree-selected span.dynatree-radio:hover +{ + background-position: -48px -48px; +} + +/******************************************************************************* + * Node type icon + * Note: IE6 doesn't correctly evaluate multiples class names, + * so we create combined class names that can be used in the CSS. + * + * Prefix: dynatree-ico- + * 1st character: 'e': expanded, 'c': collapsed + * 2nd character (optional): 'f': folder + */ + +span.dynatree-icon /* Default icon */ +{ + margin-left: 3px; + background-position: 0px 0px; +} + +.dynatree-ico-cf span.dynatree-icon /* Collapsed Folder */ +{ + background-position: 0px -16px; +} + +.dynatree-ico-ef span.dynatree-icon /* Expanded Folder */ +{ + background-position: -64px -16px; +} + +/* Status node icons */ + +.dynatree-statusnode-wait span.dynatree-icon +{ + background-image: url("loading.gif"); +} + +.dynatree-statusnode-error span.dynatree-icon +{ + background-position: 0px -112px; +/* background-image: url("ltError.gif");*/ +} + +/******************************************************************************* + * Node titles + */ + +/* @Chrome: otherwise hit area of node titles is broken (issue 133) + Removed again for issue 165; (133 couldn't be reproduced) */ +span.dynatree-node +{ +/* display: -moz-inline-box; /* issue 133, 165, 172, 192. removed for issue 221*/ +/* -moz-box-align: start; /* issue 221 */ +/* display: inline-block; /* Required to make a span sizeable */ +} + + +/* Remove blue color and underline from title links */ +ul.dynatree-container a +/*, ul.dynatree-container a:visited*/ +{ + color: black; /* inherit doesn't work on IE */ + text-decoration: none; + vertical-align: top; + margin: 0px; + margin-left: 3px; +/* outline: 0; /* @ Firefox, prevent dotted border after click */ +} + +ul.dynatree-container a:hover +{ +/* text-decoration: underline; */ + background-color: #F2F7FD; /* light blue */ + border-color: #B8D6FB; /* darker light blue */ +} + +span.dynatree-node a +{ + font-size: 10pt; /* required for IE, quirks mode */ + display: inline-block; /* Better alignment, when title contains
    */ +/* vertical-align: top;*/ + padding-left: 3px; + padding-right: 3px; /* Otherwise italic font will be outside bounds */ + /* line-height: 16px; /* should be the same as img height, in case 16 px */ +} +span.dynatree-folder a +{ + font-weight: bold; +} + +ul.dynatree-container a:focus, +span.dynatree-focused a:link /* @IE */ +{ + background-color: #EFEBDE; /* gray */ +} + +span.dynatree-has-children a +{ +} + +span.dynatree-expanded a +{ +} + +span.dynatree-selected a +{ + color: green; + font-style: italic; +} + +span.dynatree-active a +{ + background-color: #3169C6 !important; + color: white !important; /* @ IE6 */ +} + +/******************************************************************************* + * Drag'n'drop support + */ + +/*** Helper object ************************************************************/ +div.dynatree-drag-helper +{ +} +div.dynatree-drag-helper a +{ + border: 1px solid gray; + background-color: white; + padding-left: 5px; + padding-right: 5px; + opacity: 0.8; +} +span.dynatree-drag-helper-img +{ + /* + position: relative; + left: -16px; + */ +} +div.dynatree-drag-helper /*.dynatree-drop-accept*/ +{ + +/* border-color: green; + background-color: red;*/ +} +div.dynatree-drop-accept span.dynatree-drag-helper-img +{ + background-position: -32px -112px; +} +div.dynatree-drag-helper.dynatree-drop-reject +{ + border-color: red; +} +div.dynatree-drop-reject span.dynatree-drag-helper-img +{ + background-position: -16px -112px; +} + +/*** Drop marker icon *********************************************************/ + +#dynatree-drop-marker +{ + width: 24px; + position: absolute; + background-position: 0 -128px; + margin: 0; +/* border: 1px solid red; */ +} +#dynatree-drop-marker.dynatree-drop-after, +#dynatree-drop-marker.dynatree-drop-before +{ + width:64px; + background-position: 0 -144px; +} +#dynatree-drop-marker.dynatree-drop-copy +{ + background-position: -64px -128px; +} +#dynatree-drop-marker.dynatree-drop-move +{ + background-position: -64px -128px; +} + +/*** Source node while dragging ***********************************************/ + +span.dynatree-drag-source +{ + /* border: 1px dotted gray; */ + background-color: #e0e0e0; +} +span.dynatree-drag-source a +{ + color: gray; +} + +/*** Target node while dragging cursor is over it *****************************/ + +span.dynatree-drop-target +{ + /*border: 1px solid gray;*/ +} +span.dynatree-drop-target a +{ +} +span.dynatree-drop-target.dynatree-drop-accept a +{ + /*border: 1px solid green;*/ + background-color: #3169C6 !important; + color: white !important; /* @ IE6 */ + text-decoration: none; +} +span.dynatree-drop-target.dynatree-drop-reject +{ + /*border: 1px solid red;*/ +} +span.dynatree-drop-target.dynatree-drop-after a +{ +} + + +/******************************************************************************* + * Custom node classes (sample) + */ + +span.custom1 a +{ + background-color: maroon; + color: yellow; +} diff --git a/skin/vline-rtl.gif b/skin/vline-rtl.gif new file mode 100644 index 0000000..0400cb3 Binary files /dev/null and b/skin/vline-rtl.gif differ diff --git a/skin/vline.gif b/skin/vline.gif new file mode 100644 index 0000000..1b00ae5 Binary files /dev/null and b/skin/vline.gif differ diff --git a/sql-install.php b/sql-install.php new file mode 100644 index 0000000..68c6bed --- /dev/null +++ b/sql-install.php @@ -0,0 +1,19 @@ +