| Current Path : /home/balossw/www/temp/common/cms/media/js/ |
| Current File : /home/balossw/www/temp/common/cms/media/js/abstract-module.inc.js |
/*---------------------------------------------------------------------------
File name ............ content/js/module.inc.js
Project .............. Gestion
Author ............... Antoine Lemoine
Creation date ........ 18.01.2008
Modification date .... 22.05.2008
---------------------------------------------------------------------------*/
var ModuleHelper = function ()
{
this.images_cache = new Array();
this.submitForm = function (form_id)
{
$('#'+form_id).submit();
}
this.confirm = function (owner, message)
{
app.confirm(message,null,
new DialogButton(
'Oui',
function ()
{
location = $(owner).attr('href')+'&confirm=true';
},
'ok-button'
)
);
}
this.getImage = function (path)
{
if (this.images_cache[path]==undefined)
{
this.images_cache[path] = new Image();
this.images_cache[path].src = path;
}
return this.images_cache[path];
}
this.showImagePreview = function (index, path)
{
var jimage_selection = $('#image_selection_'+index);
var jimage_preview = $('#image_preview_'+index);
var jimage_preview_loading = $('#image_preview_loading_'+index);
var value = jimage_selection.val();
if (jimage_selection[0].selectedIndex==-1 || jimage_selection.val()=='')
{
jimage_preview.hide();
jimage_preview_loading.hide();
}
else
{
jimage_preview.hide();
jimage_preview_loading.show();
var src = path+'/'+value;
var img = this.getImage(src);
jimage_preview.attr('src',src);
if (!img.complete)
{
var _self = this;
setTimeout(function () { _self.showImagePreview(index,path); },20);
return;
}
var ih = img.naturalHeight ? img.naturalHeight : img.height;
var iw = img.naturalWidth ? img.naturalWidth : img.width;
var mh = 200, mw = 300;
var h = ih, w = iw;
if (ih>mh && ih/mh>=iw/mw)
{
h = mh;
w = (iw*h)/ih;
}
else if (iw>mw && ih/mh<iw/mw)
{
w = mw;
h = (ih*w)/iw;
}
jimage_preview.width(w).height(h);
jimage_preview.css({'margin-left':parseInt((mw-w)/2)+'px','margin-top':parseInt((mh-h)/2)+'px'});
jimage_preview_loading.hide();
jimage_preview.show();
}
}
this.addImg = function (index)
{
var jselect = $('#allowed-img-'+index);
var jselected_img = $('#selected-img-'+index);
var jtextarea = $('#hidden-img-list-'+index);
if (jselect[0].selectedIndex!=-1)
{
var image = jselect.val();
var exist = false;
for (i=0; i<jselected_img[0].length; i++)
{
if (jselected_img[0].options[i].text==image) { exist = true; }
}
if (!exist)
{
jtextarea.val(jtextarea.val()+image+"\n");
var myOption = new Option(image);
jselected_img[0].options[jselected_img[0].length] = myOption;
}
else { app.alert("L'image est déjà dans la liste."); }
}
else { app.alert("Vous devez sélectionner une image à ajouter."); }
}
this.delImg = function (index)
{
var jselect = $('#allowed-img-'+index);
var jselected_img = $('#selected-img-'+index);
var jtextarea = $('#hidden-img-list-'+index);
if (jselected_img[0].selectedIndex!=-1)
{
var image = jselect.val();
jselected_img[0].options[jselected_img[0].selectedIndex] = null;
var value = '';
for (i=0; i<jselected_img[0].length; i++)
{
value += jselected_img[0].options[i].text + "\n";
}
jtextarea.val(value);
}
else { app.alert("Vous devez sélectionner une image à supprimer."); }
}
this.changeButtonValue = function (id, value)
{
$('#'+id).val(value);
}
this.changeColor = function changeColor(id, increment)
{
var jinput = $('#'+id);
var value = jinput.val();
if (value.length>=6)
{
jinput.val(value.substr(0,6));
value = jinput.val();
if (!value.match(/[0-9A-F]+/)) { jinput.val('000000'); }
var r = parseInt(value.substr(0,2),16);
var g = parseInt(value.substr(2,2),16);
var b = parseInt(value.substr(4,2),16);
var r2 = r;
var g2 = g;
var b2 = b;
if (Math.abs(increment)>=parseInt('FFFF',16))
{
r2 += increment/parseInt('FFFF',16);
if (r2<=parseInt('FF',16) && r2>=0) { r = r2; }
}
else if (Math.abs(increment)>=parseInt('FF',16))
{
g2 += increment/parseInt('FF',16);
if (g2<=parseInt('FF',16) && g2>=0) { g = g2; }
}
else
{
b2 += increment;
if (b2<=parseInt('FF',16) && b2>=0) { b = b2; }
}
var r_string = r.toString(16).toUpperCase();
while (r_string.length<2)
{
r_string = '0' + r_string;
}
var g_string = g.toString(16).toUpperCase();
while (g_string.length<2)
{
g_string = '0' + g_string;
}
var b_string = b.toString(16).toUpperCase();
while (b_string.length<2)
{
b_string = '0' + b_string;
}
value = r_string + g_string + b_string;
jinput.val(value);
jinput.css({'background-color':'#'+value,'color':(r<parseInt('7F',16) && g<parseInt('7F',16) && b<parseInt('7F',16) ? '#FFF' : '#000')});
}
else
{
jinput.css({'background-color':'#FFF','color':'#000'});
}
}
this.gotoSelectedValue = function (select)
{
var url = $(select).val();
if (url!='') { document.location = url; }
}
}
var module = new ModuleHelper();