2015-01-23 13:09:30 +00:00
|
|
|
Htk.ColumnImage = new Class
|
|
|
|
({
|
|
|
|
Extends: Htk.Column
|
|
|
|
,Tag: 'htk-column-image'
|
|
|
|
,Properties:
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The directory where the images are allocated.
|
|
|
|
**/
|
|
|
|
directory:
|
|
|
|
{
|
|
|
|
type: String
|
|
|
|
,set: function (x)
|
|
|
|
{
|
|
|
|
this._directory = x;
|
2015-11-26 12:30:04 +00:00
|
|
|
this._basedir = Vn.Config['image_dir'] +'/'+ x;
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
,get: function ()
|
|
|
|
{
|
|
|
|
return this._directory;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* The directory where the images are allocated.
|
|
|
|
**/
|
|
|
|
subdir:
|
|
|
|
{
|
|
|
|
type: String
|
|
|
|
,value: null
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Whether to show the full image when mouse hover.
|
|
|
|
**/
|
|
|
|
showFull:
|
|
|
|
{
|
|
|
|
type: Boolean
|
|
|
|
,value: false
|
2015-08-21 14:13:21 +00:00
|
|
|
},
|
|
|
|
/**
|
2015-08-25 09:16:13 +00:00
|
|
|
* Subdirectory where full images are allocated.
|
2015-08-21 14:13:21 +00:00
|
|
|
**/
|
|
|
|
fullDir:
|
|
|
|
{
|
|
|
|
type: String
|
|
|
|
,set: function (x)
|
|
|
|
{
|
|
|
|
this._fullDir = x;
|
|
|
|
}
|
|
|
|
,get: function ()
|
|
|
|
{
|
|
|
|
return this._fullDir;
|
|
|
|
}
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
,_directory: null
|
2015-11-26 12:30:04 +00:00
|
|
|
,_basedir: null
|
2015-01-23 13:09:30 +00:00
|
|
|
|
|
|
|
,initialize: function (props)
|
|
|
|
{
|
2015-11-26 12:30:04 +00:00
|
|
|
this._cssClass = 'cell-image';
|
|
|
|
this._fullImage = new Htk.FullImage ();
|
2015-01-23 13:09:30 +00:00
|
|
|
this.parent (props);
|
|
|
|
}
|
|
|
|
|
|
|
|
,render: function (tr)
|
|
|
|
{
|
|
|
|
var td = this.parent (tr);
|
|
|
|
|
|
|
|
var img = document.createElement ('img');
|
|
|
|
img.alt = ''
|
|
|
|
td.appendChild (img);
|
|
|
|
|
|
|
|
var cell =
|
|
|
|
{
|
|
|
|
img: img
|
|
|
|
,value: this.value
|
|
|
|
,tr: tr
|
|
|
|
,error: false
|
2015-09-04 08:50:06 +00:00
|
|
|
,stamp: null
|
2015-01-23 13:09:30 +00:00
|
|
|
};
|
|
|
|
|
2015-12-10 13:48:43 +00:00
|
|
|
this._setSrc (cell);
|
2015-01-23 13:09:30 +00:00
|
|
|
|
|
|
|
if (this.showFull)
|
|
|
|
{
|
2015-12-10 13:48:43 +00:00
|
|
|
img.addEventListener ('mouseover', this._onMouseOver.bind (this, cell));
|
|
|
|
img.addEventListener ('mouseout', this._onMouseOut.bind (this));
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
if (this.editable)
|
|
|
|
{
|
|
|
|
img.className = 'editable';
|
2015-12-10 13:48:43 +00:00
|
|
|
img.addEventListener ('dblclick', this._onDoubleClick.bind (this, cell));
|
|
|
|
img.addEventListener ('error', this._onImageError.bind (this, cell));
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return td;
|
|
|
|
}
|
|
|
|
|
2015-12-10 13:48:43 +00:00
|
|
|
,_setSrc: function (cell)
|
2015-01-23 13:09:30 +00:00
|
|
|
{
|
|
|
|
if (cell.value)
|
|
|
|
{
|
2015-11-26 12:30:04 +00:00
|
|
|
var url = this._basedir +'/';
|
2015-01-23 13:09:30 +00:00
|
|
|
|
|
|
|
if (this.subdir)
|
|
|
|
url += this.subdir +'/';
|
|
|
|
|
|
|
|
url += cell.value;
|
|
|
|
|
2015-09-04 08:50:06 +00:00
|
|
|
if (cell.stamp)
|
|
|
|
url += '?'+ cell.stamp;
|
2015-01-23 13:09:30 +00:00
|
|
|
|
|
|
|
cell.img.src = url;
|
|
|
|
}
|
|
|
|
else
|
2015-12-10 13:48:43 +00:00
|
|
|
this._onImageError (cell);
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
|
2015-12-10 13:48:43 +00:00
|
|
|
,_onImageError: function (cell)
|
2015-01-23 13:09:30 +00:00
|
|
|
{
|
|
|
|
if (!cell.error)
|
|
|
|
{
|
|
|
|
cell.error = true;
|
2015-12-10 13:48:43 +00:00
|
|
|
cell.img.src = 'image/unknown.svg';
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-10 13:48:43 +00:00
|
|
|
,_onMouseOver: function (cell)
|
2015-01-23 13:09:30 +00:00
|
|
|
{
|
2015-12-10 13:48:43 +00:00
|
|
|
if (cell.error)
|
|
|
|
return;
|
|
|
|
|
2015-09-04 08:50:06 +00:00
|
|
|
var src = this._fullDir ? this._fullDir : 'full';
|
|
|
|
src += '/'+ cell.value;
|
|
|
|
|
|
|
|
if (cell.stamp)
|
|
|
|
src += '?'+ cell.stamp;
|
2015-08-21 14:13:21 +00:00
|
|
|
|
2015-12-10 13:48:43 +00:00
|
|
|
this._fullImage.show (this._basedir +'/'+ src);
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
|
2015-12-10 13:48:43 +00:00
|
|
|
,_onMouseOut: function ()
|
2015-01-23 13:09:30 +00:00
|
|
|
{
|
2015-11-26 12:30:04 +00:00
|
|
|
this._fullImage.hide ();
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
|
2015-12-10 13:48:43 +00:00
|
|
|
,_onDoubleClick: function (cell)
|
2015-01-23 13:09:30 +00:00
|
|
|
{
|
|
|
|
var editor = new Htk.ImageEditor ();
|
|
|
|
editor.setData (cell.value, this._directory);
|
|
|
|
|
2015-12-10 13:48:43 +00:00
|
|
|
this.nameChangedHandler = this._onNameChange.bind (this, cell);
|
2015-01-23 13:09:30 +00:00
|
|
|
editor.on ('name-changed', this.nameChangedHandler);
|
|
|
|
|
2015-12-10 13:48:43 +00:00
|
|
|
this.fileUploadedHandler = this._onFileUpload.bind (this, cell);
|
2015-01-23 13:09:30 +00:00
|
|
|
editor.on ('file-uploaded', this.fileUploadedHandler);
|
|
|
|
|
2015-12-10 13:48:43 +00:00
|
|
|
this.editorClosedHandler = this._onEditorClose.bind (this);
|
2015-01-23 13:09:30 +00:00
|
|
|
editor.on ('closed', this.editorClosedHandler);
|
2015-12-15 16:08:24 +00:00
|
|
|
|
|
|
|
this.popup = new Htk.Popup
|
|
|
|
({
|
|
|
|
modal: true,
|
|
|
|
child: editor
|
|
|
|
});
|
2015-03-06 23:33:54 +00:00
|
|
|
this.popup.show (cell.img);
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
|
2015-12-10 13:48:43 +00:00
|
|
|
,_onNameChange: function (cell, editor, value)
|
2015-01-23 13:09:30 +00:00
|
|
|
{
|
|
|
|
cell.value = value;
|
2015-12-10 13:48:43 +00:00
|
|
|
this._setSrc (cell);
|
2015-01-23 13:09:30 +00:00
|
|
|
this.changed (cell.tr, value);
|
|
|
|
}
|
|
|
|
|
2015-12-10 13:48:43 +00:00
|
|
|
,_onFileUpload: function (cell, editor)
|
2015-01-23 13:09:30 +00:00
|
|
|
{
|
2015-09-04 08:50:06 +00:00
|
|
|
cell.stamp = new Date ().getTime ();
|
2015-12-10 13:48:43 +00:00
|
|
|
this._setSrc (cell);
|
2015-03-06 23:33:54 +00:00
|
|
|
this.popup.hide ();
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
|
2015-12-10 13:48:43 +00:00
|
|
|
,_onEditorClose: function (editor)
|
2015-01-23 13:09:30 +00:00
|
|
|
{
|
|
|
|
editor.disconnect ('name-changed', this.nameChangedHandler);
|
|
|
|
editor.disconnect ('file-uploaded', this.fileUploadedHandler);
|
|
|
|
editor.disconnect ('closed', this.editorClosedHandler);
|
|
|
|
}
|
|
|
|
});
|