0
1
Fork 0

Merge with master

This commit is contained in:
Juan Ferrer Toribio 2017-05-09 15:33:02 +02:00
commit 45f5cc3deb
45 changed files with 535 additions and 232 deletions

View File

@ -2,20 +2,5 @@
Hedera.Items = new Class
({
Extends: Hedera.Form
,activate: function ()
{
this.$('lot').assign ({
warehouse: 7,
realm: null
});
}
,onShowClick: function ()
{
var lot = this.$('lot');
lot.assign ({rate: this.$('rate').value});
this.gui.openReport ('items-report', lot.params);
}
});

View File

@ -0,0 +1,4 @@
{
"Items": "Artícles",
"Enter a search term": "Introdueix un terme de cerca"
}

9
forms/admin/items/locale/en.json Normal file → Executable file
View File

@ -1,9 +1,4 @@
{
"Item list": "Item list"
,"Store": "Store"
,"Realm": "Realm"
,"Rate": "Rate"
,"Show": "Show"
"Items": "Items",
"Enter a search term": "Enter a search term"
}

9
forms/admin/items/locale/es.json Normal file → Executable file
View File

@ -1,9 +1,4 @@
{
"Item list": "Listado de artículos"
,"Store": "Almacén"
,"Realm": "Reino"
,"Rate": "Tarifa"
,"Show": "Mostrar"
"Items": "Artículos",
"Enter a search term": "Introduce un término de búsqueda"
}

View File

@ -0,0 +1,4 @@
{
"Items": "Articles",
"Enter a search term": "Entrez un terme de recherche"
}

9
forms/admin/items/locale/mn.json Normal file → Executable file
View File

@ -1,9 +1,4 @@
{
"Item list": "Item list"
,"Store": "Store"
,"Realm": "Realm"
,"Rate": "Rate"
,"Show": "Show"
"Items": "Items",
"Enter a search term": "Enter a search term"
}

View File

@ -1,9 +1,4 @@
{
"Item list": "Lista de Ítens"
,"Store": "Armazém"
,"Realm": "Reino"
,"Rate": "Tarifa"
,"Show": "Mostrar"
"Items": "Artigos",
"Enter a search term": "Digite um termo de pesquisa"
}

View File

@ -0,0 +1,23 @@
/* Row */
.items .list-row > .photo
{
margin-right: 1em;
float: left;
border-radius: 50%;
height: 3.2em;
width: 3.2em;
}
.items .list-row > p
{
margin: .1em 0;
margin-left: 5em;
}
/* Topbar */
.action-bar .htk-search-entry
{
margin: .8em .6em;
}

View File

@ -1,42 +1,47 @@
<vn>
<vn-lot id="lot"/>
<h1 id="title">
<t>Item list</t>
<t>Items</t>
</h1>
<div id="actions" class="action-bar">
<htk-bar-button
icon="show"
tip="_Show"
on-click="onShowClick"/>
<div id="actions">
<htk-search-entry
param="filter"/>
</div>
<div id="main" class="items">
<div class="card form">
<div>
<label><t>Store</t></label>
<htk-combo lot="lot" name="warehouse">
<db-model property="model">
SELECT id, name FROM vn2008.warehouse
WHERE reserve ORDER BY name
<div class="card list">
<htk-repeater form-id="iter" empty-message="_Enter a search term">
<db-model property="model" batch="hash">
SELECT Id_Article, Article, Medida, Categoria, Foto
FROM vn2008.Articles
WHERE Article LIKE CONCAT('%', #filter, '%')
OR Id_Article = #filter
ORDER BY Article LIMIT 50
</db-model>
</htk-combo>
</div>
<div>
<label><t>Realm</t></label>
<htk-combo lot="lot" name="realm" not-null="false">
<db-model property="model">
SELECT id, reino FROM vn2008.reinos
WHERE display != FALSE ORDER BY reino
</db-model>
</htk-combo>
</div>
<div>
<label><t>Rate</t></label>
<select id="rate">
<option>3</option>
<option>2</option>
<option>1</option>
</select>
<custom>
<div class="list-row">
<htk-image
form="iter"
column="Foto"
class="photo"
directory="catalog"
subdir="200x200"
full-dir="900x900"
editable="true"
conn="conn"/>
<p class="concept">
<htk-text form="iter" column="Article"/>
<htk-text form="iter" column="Medida"/>
<htk-text form="iter" column="Categoria"/>
</p>
<p>
<htk-text form="iter" column="Id_Article"/>
</p>
<p>
<htk-text form="iter" column="Foto"/>
</p>
<div class="clear"/>
</div>
</custom>
</htk-repeater>
</div>
</div>
</vn>

View File

@ -1,12 +1,13 @@
{
"Photos": "Fotos"
"Images": "Imatges"
,"Collection": "Colección"
,"ImageName": "Nom de la imatge"
,"Id": "Id"
,"ImageFile": "Arxiu d'imatge"
,"Collection": "Col·lecció"
,"Click or drop files here": "Prem o deixa anar els arxius aquí"
,"Upload": "Enviar"
,"Clear all": "Netejar tot"
,"Upload files": "Pujar arxius"
,"ImageUploaded": "Imatge pujada correctament"
,"Upload finished successfully": "Imatges pujades correctament"
,"Some errors happened on upload": "Van ocórrer errors en pujar alguna de les imatges"
,"There are no files to upload": "No s'ha seleccionat arxius per pujar"
}

View File

@ -1,12 +1,13 @@
{
"Photos": "Photos"
"Images": "Images"
,"Collection": "Collection"
,"ImageName": "Image name"
,"Id": "Id"
,"ImageFile": "Image file"
,"Click or drop files here": "Click or drop files here"
,"Upload": "Upload"
,"Clear all": "Clear all"
,"Upload files": "Upload files"
,"ImageUploaded": "Image uploaded successfully"
,"Upload finished successfully": "Upload finished successfully"
,"Some errors happened on upload": "Some errors happened on upload"
,"There are no files to upload": "There are no files to upload"
}

View File

@ -1,12 +1,13 @@
{
"Photos": "Fotos"
"Images": "Imágenes"
,"Collection": "Colección"
,"ImageName": "Nombre de la imagen"
,"Id": "Id"
,"ImageFile": "Archivo de imagen"
,"Click or drop files here": "Pulsa o suelta los archivos aquí"
,"Upload": "Enviar"
,"Clear all": "Limpiar todo"
,"Upload files": "Subir archivos"
,"ImageUploaded": "Imagen subida correctamente"
,"Upload finished successfully": "Imágenes subidas correctamente"
,"Some errors happened on upload": "Ocurrieron errores al subir alguna de las imágenes"
,"There are no files to upload": "No se han seleccionado archivos para subir"
}

View File

@ -1,12 +1,13 @@
{
"Photos": "Photos"
"Images": "Images"
,"Collection": "Collection"
,"ImageName": "Nom de l'image"
,"Id": "Id"
,"ImageFile": "Fichier image"
,"Click or drop files here": "Cliquez ici ou déposer des fichiers"
,"Upload": "Télécharger"
,"Clear all": "Tout effacer"
,"Upload files": "Upload Files"
,"ImageUploaded": "téléchargement correct"
,"Upload finished successfully": "Les images téléchargées correctement"
,"Some errors happened on upload": "Des erreurs sont survenues lors du téléchargement des images"
,"There are no files to upload": "Aucun fichier sélectionné pour télécharger"
}

View File

@ -1,12 +1,13 @@
{
"Photos": "Photos"
"Images": "Images"
,"Collection": "цуглуулга"
,"ImageName": "Image name"
,"Id": "Id"
,"ImageFile": "Image file"
,"Collection": "Collection"
,"Click or drop files here": "Click or drop files here"
,"Upload": "Upload"
,"Clear all": "Clear all"
,"Upload files": "Upload files"
,"ImageUploaded": "Image uploaded successfully"
,"Upload finished successfully": "Upload finished successfully"
,"Some errors happened on upload": "Some errors happened on upload"
,"There are no files to upload": "There are no files to upload"
}

View File

@ -1,12 +1,13 @@
{
"Photos": "Fotos"
"Images": "Imagens"
,"Collection": "Coleção"
,"ImageName": "Nome da imagem"
,"Id": "Id"
,"ImageFile": "Arquivo de imagem"
,"Click or drop files here": "Clique ou soltar arquivos aqui"
,"Upload": "Enviar"
,"Clear all": "Clear All"
,"Upload files": "Fazer upload de arquivos"
,"ImageUploaded": "Imagem subida correctamente"
,"Upload finished successfully": "Upload concluído com sucesso"
,"Some errors happened on upload": "Ocurrieron erros ao subir alguma das imagens"
,"There are no files to upload": "Não há arquivos selecionados para upload"
}

View File

@ -2,36 +2,203 @@
Hedera.Photos = new Class
({
Extends: Hedera.Form
,filesData: []
,uploadCount: 0
,errors: false
,activate: function ()
{
this.$('schema').value = 'catalog';
this.$('photo-id').focus ();
var self = this;
this.$('html-form').onsubmit = function ()
{ self._onSubmit (); return false; };
}
,_onSubmit: function ()
,addFiles: function (files)
{
this.$('schema-field').value = this.$('schema').value;
this.$('submit').disabled = true;
if (!files)
return;
this.conn.sendFormMultipart (this.$('html-form'),
this._onResponse.bind (this));
for (var i = 0; i < files.length; i++)
this.addFile (files[i]);
}
,_onResponse: function (json, error)
,addFile: function (file)
{
this.$('submit').disabled = false;
var doc = document;
var div = doc.createElement ('div');
if (error)
throw error;
var button = new Htk.Button ({
tip: 'Remove',
icon: 'delete'
});
button.on ('click', this.onFileRemove, this);
div.appendChild (button.node);
this.$('photo-id').value = '';
this.$('photo-id').focus ();
Htk.Toast.showMessage (_('ImageAdded'));
var thumb = doc.createElement ('img');
thumb.file = file;
thumb.className = 'thumb';
div.appendChild (thumb);
var reader = new FileReader ();
reader.onload = function (e) { thumb.src = e.target.result; };
reader.readAsDataURL(file);
var name = doc.createElement ('input');
name.type = 'text';
name.value = getFileName (file.name);
div.appendChild (name);
var status = doc.createElement ('span');
status.className = 'status';
div.appendChild (status);
var fileData = {
div: div,
file: file,
name: name,
status: status,
sent: false,
loading : false
};
this.filesData.push (fileData);
button.value = fileData;
this.$('file-list').appendChild (div);
}
,onUploadClick: function ()
{
var filesData = this.filesData;
var formData = new FormData();
var count = 0;
for (var i = 0; i < filesData.length; i++)
{
var fileData = filesData[i];
if (!(fileData.sent || fileData.loading))
{
formData.append ('image', fileData.file);
formData.append ('name', fileData.name.value);
formData.append ('schema', this.$('schema').value);
formData.append ('srv', 'json:image/upload');
this.conn.sendFormData (formData,
this.onFileUpload.bind (this, fileData));
fileData.loading = true;
this.uploadCount++;
count++;
}
}
if (count === 0)
Htk.Toast.showWarning (_('There are no files to upload'));
}
,onFileUpload: function (fileData, data, error)
{
fileData.loading = false;
if (data)
{
var iconName = 'ok';
var title = _('ImageAdded');
fileData.sent = true;
fileData.name.disabled = true;
}
else
{
var iconName = 'error';
var title = error.message;
this.errors = true;
}
var status = fileData.status;
Vn.Node.removeChilds (status);
var icon = new Htk.Icon ({icon: iconName});
status.appendChild (icon.node);
status.title = title;
this.uploadCount--;
if (this.uploadCount === 0)
{
if (!this.errors)
Htk.Toast.showMessage (_('Upload finished successfully'));
else
Htk.Toast.showError (_('Some errors happened on upload'));
this.errors = false;
}
}
,onFileRemove: function (button)
{
var fileData = button.value;
this.$('file-list').removeChild (fileData.div);
for (var i = 0; i < this.filesData.length; i++)
if (this.filesData[i] === fileData)
{
this.filesData.splice (i, 1);
break;
}
}
,onClearClick: function ()
{
this.filesData = [];
Vn.Node.removeChilds (this.$('file-list'));
}
,onDropzoneClick: function ()
{
this.$('file').click ();
}
,onFileChange: function ()
{
this.addFiles (this.$('file').files);
}
,onDragEnter: function (event)
{
Vn.Node.addClass (this.$('dropzone'), 'dragover');
}
,onDragLeave: function (event)
{
Vn.Node.removeClass (this.$('dropzone'), 'dragover');
}
,onDragOver: function (event)
{
event.preventDefault ();
}
,onDragEnd: function (event)
{
Vn.Node.removeClass (this.$('dropzone'), 'dragover');
event.dataTransfer.clearData ();
}
,onDrop: function (event)
{
event.preventDefault ();
this.addFiles (event.dataTransfer.files);
}
});
function getFileName (path)
{
var barIndex = path.lastIndexOf ('/');
if (barIndex === -1)
barIndex = path.lastIndexOf ('\\');
if (barIndex === -1)
barIndex = 0;
var dotIndex = path.lastIndexOf ('.');
if (dotIndex === -1)
dotIndex = 0;
return path.substr (barIndex, dotIndex);
}

View File

@ -1,17 +1,63 @@
.photos iframe
/* Dropzone */
.photos .dropzone
{
background-color: white;
border-style: dashed;
border-radius: .4em;
border-color: #2196F3;
padding: 2em 1em;
text-align: center;
color: #666;
cursor: pointer;
}
.photos .dropzone.dragover
{
color: #CCC;
border-style: solid;
}
.photos input[type=file]
{
display: none;
}
/* Footer */
/* File list */
.photos input[type=submit]
.photos .file-list
{
display: block;
margin-top: 1.5em;
margin-left: auto;
margin-right: auto;
font-size: 1.2em;
margin-top: 1em;
}
.photos .file-list > div
{
height: 2.5em;
}
.photos .file-list .thumb
{
max-height: 2em;
max-width: 2em;
vertical-align: middle;
margin: 0 1em;
}
.photos .file-list input
{
max-width: 10em;
}
.photos .file-list .status
{
margin-left: .5em;
cursor: pointer;
}
/* Footer */
.photos .footer
{
margin-top: 1.5em;
text-align: center;
}
.photos .footer > button
{
font-size: 1.2em;
margin-left: 1em;
}

View File

@ -1,33 +1,41 @@
<vn>
<h1 id="title">
<t>Photos</t>
<t>Images</t>
</h1>
<div id="main" class="photos">
<form
id="html-form"
enctype="multipart/form-data">
<div class="card form">
<input type="hidden" name="srv" value="json:image/upload"/>
<div>
<label><t>Id</t></label>
<input type="number" name="id" id="photo-id"/>
</div>
<div>
<label><t>ImageName</t></label>
<input type="text" name="name"/>
</div>
<div>
<div class="box">
<div class="form-group">
<label><t>Collection</t></label>
<htk-combo id="schema">
<db-model property="model">
SELECT name, `desc` FROM image_schema ORDER BY `desc`
</db-model>
</htk-combo>
<input type="hidden" name="schema" id="schema-field"/>
</div>
<div>
<label><t>ImageFile</t></label>
<input type="file" name="image"/>
<div id="dropzone" class="dropzone"
on-dragenter="onDragEnter"
on-dragleave="onDragLeave"
on-mouseout="onDragLeave"
on-dragover="onDragOver"
on-drop="onDrop"
on-dragend="onDragEnd"
on-click="onDropzoneClick">
<t>Click or drop files here</t>
</div>
<input
id="file"
type="file"
multiple="true"
name="image"
on-change="onFileChange"/>
<div id="file-list" class="file-list"/>
<div class="footer">
<button class="thin" on-click="onClearClick">
<t>Clear all</t>
</button>
<button class="thin" on-click="onUploadClick">
<t>Upload files</t>
</button>
</div>
<input id="submit" type="submit" class="thin"/>
</div>

View File

@ -0,0 +1,23 @@
Hedera.ItemsForm = new Class
({
Extends: Hedera.Form
,activate: function ()
{
this.$('warehouse').value = 7;
this.$('realm').value = null;
}
,onPreviewClick: function ()
{
var batch = new Sql.Batch ();
batch.addValues ({
'warehouse': this.$('warehouse').value
,'realm': this.$('realm').value
,'rate': this.$('rate').value
});
this.gui.openReport ('items-report', batch);
}
});

View File

@ -0,0 +1,9 @@
{
"Item list": "Item list"
,"Store": "Store"
,"Realm": "Realm"
,"Rate": "Rate"
,"Preview": "Preview"
}

View File

@ -0,0 +1,9 @@
{
"Item list": "Listado de artículos"
,"Store": "Almacén"
,"Realm": "Reino"
,"Rate": "Tarifa"
,"Preview": "Mostrar"
}

View File

@ -0,0 +1,9 @@
{
"Item list": "Item list"
,"Store": "Store"
,"Realm": "Realm"
,"Rate": "Rate"
,"Preview": "Preview"
}

View File

@ -0,0 +1,9 @@
{
"Item list": "Lista de Ítens"
,"Store": "Armazém"
,"Realm": "Reino"
,"Rate": "Tarifa"
,"Preview": "Mostrar"
}

42
forms/reports/items-form/ui.xml Executable file
View File

@ -0,0 +1,42 @@
<vn>
<vn-lot id="lot"/>
<h1 id="title">
<t>Item list</t>
</h1>
<div id="actions" class="action-bar">
<htk-bar-button
icon="show"
tip="_Show"
on-click="onShowClick"/>
</div>
<div id="main" class="items">
<div class="card form">
<div>
<label><t>Store</t></label>
<htk-combo lot="lot" name="warehouse">
<db-model property="model">
SELECT id, name FROM vn2008.warehouse
WHERE reserve ORDER BY name
</db-model>
</htk-combo>
</div>
<div>
<label><t>Realm</t></label>
<htk-combo lot="lot" name="realm" not-null="false">
<db-model property="model">
SELECT id, reino FROM vn2008.reinos
WHERE display != FALSE ORDER BY reino
</db-model>
</htk-combo>
</div>
<div>
<label><t>Rate</t></label>
<select id="rate">
<option>3</option>
<option>2</option>
<option>1</option>
</select>
</div>
</div>
</div>
</vn>

View File

View File

@ -191,7 +191,7 @@ module.exports = new Class
,loadMenu: function ()
{
var sql = 'CALL form_list ()';
var sql = 'CALL formList ()';
this._conn.execQuery (sql, this._onMenuLoad.bind (this));
}

View File

@ -50,6 +50,7 @@
,"Visits": "Visites"
,"News": "Noticies"
,"Photos": "Fotos"
,"Items": "Artícles"
,"Reports": "Informes"
,"Shelves": "Estanterías"
,"Items list": "Llistat articles"

View File

@ -50,6 +50,7 @@
,"Visits": "Visits"
,"News": "News"
,"Photos": "Photos"
,"Items": "Items"
,"Reports": "Reports"
,"Shelves": "Shelves"
,"Items list": "Items list"

View File

@ -50,6 +50,7 @@
,"Visits": "Visitas"
,"News": "Noticias"
,"Photos": "Fotos"
,"Items": "Artículos"
,"Reports": "Informes"
,"Shelves": "Estanterías"
,"Items list": "Listado artículos"

View File

@ -50,6 +50,7 @@
,"Visits": "Visites"
,"News": "Nouvelles"
,"Photos": "Photos"
,"Items": "Articles"
,"Reports": "Rapport"
,"Shelves": "Etagères"
,"Items list": "Liste des articles"

View File

@ -50,6 +50,7 @@
,"Visits": "уулзалт"
,"News": "мэдээ"
,"Photos": "Фото зураг"
,"Items": "зүйл"
,"Reports": "мэдээ"
,"Shelves": "тавиур"
,"Items list": "зүйлс жагсаалт"

View File

@ -50,6 +50,7 @@
,"Visits": "Visitas"
,"News": "Noticias"
,"Photos": "Fotos"
,"Items": "Artigos"
,"Reports": "Relatórios"
,"Shelves": "Estantes"
,"Items list": "Lista de Itens"

View File

@ -193,6 +193,20 @@ module.exports = new Class
this._addRequest ();
}
,sendFormData: function (formData, callback)
{
if (this.token)
formData.append ('token', this.token);
var request = new XMLHttpRequest ();
request.open ('post', '', true);
request.onreadystatechange =
this._onStateChange.bind (this, request, callback);
request.send (formData);
this._addRequest ();
}
/*
* Called when REST response is received.
*/

View File

@ -20,7 +20,7 @@ class Sync extends Vn\Lib\Method
function run ()
{
$db = $this->getSysConn ()
$db = $this->getSysConn ();
set_time_limit (0);
$this->$trashSubdir = date ('YmdHis');

View File

@ -65,7 +65,6 @@ class Thumb extends Vn\Web\RestRequest
// Creates the thumb.
$util = new Util ($this->app);
$baseDir = "{$util->dataDir}/$schema";
$srcFile = "$baseDir/full/$file";

View File

@ -10,77 +10,31 @@ use Vn\Lib\UserException;
*/
class Upload extends Vn\Web\JsonRequest
{
const PARAMS = [
'name',
'schema'
];
function run ($db)
{
$util = new Util ($this->app);
// Checks schema.
$regexp = '/[^a-z0-9_]/';
if (empty ($_REQUEST['schema']) || preg_match ($regexp, $_REQUEST['schema']) !== 0)
throw new UserException (s('Bad schema name'));
$schema = $_REQUEST['schema'];
$name = $_REQUEST['name'];
// Checks schema
$info = $util->loadInfo ($schema);
if (!$info)
throw new UserException (s('Schema not exists'));
// Checks file name and identifier.
// Checks file name
$query = sprintf (
'SHOW INDEX FROM `%1$s`.`%2$s` WHERE Key_name = \'PRIMARY\''
,$info['schema']
,$info['table']
);
$pk = $db->getRow ($query);
if (!empty ($_REQUEST['id']) && empty ($_REQUEST['name']))
{
$query = sprintf (
'SELECT `%3$s` FROM `%1$s`.`%2$s` WHERE `%4$s` = #id'
,$info['schema']
,$info['table']
,$info['column']
,$pk['Column_name']
);
$_REQUEST['name'] = $db->getValue ($query,
['id' => $_REQUEST['id']]);
}
if (empty ($_REQUEST['name']) || preg_match ($regexp, $_REQUEST['name']) !== 0)
if (preg_match ('/[^a-z0-9_]/', $_REQUEST['name']) !== 0)
throw new UserException (s('Bad file name'));
// Checks permissions.
if (!empty ($_REQUEST['id']))
{
$filterColumn = $pk['Column_name'];
$filterValue = $_REQUEST['id'];
}
else
{
$filterColumn = $info['column'];
$filterValue = $_REQUEST['name'];
}
$query = sprintf (
'UPDATE `%1$s`.`%2$s` SET `%3$s` = #name WHERE `%4$s` = #filter LIMIT 1'
,$info['schema']
,$info['table']
,$info['column']
,$filterColumn
);
$params = [
'name' => $_REQUEST['name'],
'filter' => $filterValue
];
if (!$db->query ($query, $params))
throw new UserException (s('Permission denied'));
// Checks for file errors.
// Checks for file errors
if (empty ($_FILES['image']['name']))
throw new UserException (s('File not choosed'));
@ -123,14 +77,15 @@ class Upload extends Vn\Web\JsonRequest
if ($_FILES['image']['size'] > $maxSize * 1048576)
throw new UserException (sprintf (s('File size error'), $maxSize));
// Resizes and saves the image.
// Resizes and saves the image
$fileName = "{$_REQUEST['name']}.png";
$tmpName = $_FILES['image']['tmp_name'];
$fileName = "{$name}.png";
$schemaPath = "{$util->dataDir}/$schema";
$fullFile = "$schemaPath/full/$fileName";
$symbolicSrc = "../full/$fileName";
$image = Image::create ($_FILES['image']['tmp_name']);
$image = Image::create ($tmpName);
Image::resizeSave ($image, $fullFile, $info['max_height'], $info['max_width']);
foreach ($info['sizes'] as $size => $i)
@ -140,7 +95,7 @@ class Upload extends Vn\Web\JsonRequest
}
imagedestroy ($image);
unlink ($_FILES['image']['tmp_name']);
unlink ($tmpName);
return TRUE;
}
}