/*
* Common støff
*/
Ext.lib.Ajax.defaultPostHeader = "application/x-www-form-urlencoded; charset=UTF-8";
Ext.BLANK_IMAGE_URL = "/util/ext-3.3/resources/images/default/s.gif";
Ext.namespace('Ext.gt');
var getEntity = function(recordDef, data, id) {
var fi = recordDef.prototype.fields.items;
for (var i = 0; i < fi.length; i++) {
var f = fi[i];
var v = data[f.name];
data[f.name] = f.convert((v !== undefined) ? v : f.defaultValue);
}
var r = new recordDef(data, id);
return r;
}
var getDocumentParent = function() {
var topWindow = window.parent;
while (topWindow.parent && topWindow.parent != topWindow) {
try {
if (topWindow.parent.document.domain != document.domain)
break;
if (topWindow.parent.document.getElementsByTagName('frameset').length > 0)
break;
} catch (e) {
break;
}
topWindow = topWindow.parent;
}
return {
window: topWindow,
document: topWindow.document
}
}
var getMimeIconFromMimetype = function(mimetype) {
var delimiter = mimetype.indexOf("/");
var commonType = mimetype.substring(0, delimiter);
var type = mimetype.substring(delimiter + 1);
var ret;
switch(type) {
case "pdf":
ret = "util/admin/images/mime/pdf.png";
break;
case "vnd.ms-word":
ret = "util/admin/images/mime/document.png";
break;
}
switch (commonType) {
case "audio":
ret = "util/admin/images/mime/audio.png";
break;
case "video":
ret = "util/admin/images/mime/video.png";
break;
case "image":
ret = "util/admin/images/mime/image.png";
break;
}
if (ret == null) {
ret = "util/admin/images/mime/unknown.png";
}
return ret;
}
var getSessionId = function() {
var retval = "";
var offset = document.cookie.indexOf("JSESSIONID=");
if (offset >= 0) {
var end = document.cookie.indexOf(";", offset);
if (end < 0) {
end = document.cookie.length;
}
retval = document.cookie.substring(offset + 11, end);
}
return retval;
}
var getAdminBaseUrl = function() {
var loc = window.location.pathname;
loc = loc.substring(0, loc.lastIndexOf("admin"));
return loc + "admin/";
}
var getServletBaseUrl = function() {
return "";
}
var servletBase = getServletBaseUrl();
var getApplicationBaseUrl = function() {
//var loc = window.location.pathname;
//loc = loc.substring(0, loc.indexOf("/", 1));
return "";
}
var applicationBaseUrl = getApplicationBaseUrl();
var getQueryParam = function(name) {
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^]*)";
var regex = new RegExp( regexS );
var results = regex.exec( window.location.href );
if( results == null )
return "";
else
return results[1];
}
function checkFlashVersion() {
var x;
var pluginversion;
if(navigator.plugins && navigator.mimeTypes.length){
x = navigator.plugins["Shockwave Flash"];
if(x && x.description) x = x.description;
} else if (Ext.isIE){
try {
x = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
x = x.GetVariable("$version");
} catch(e){}
}
pluginVersion = (typeof(x) == 'string') ? parseInt(x.match(/\d+/)[0]) : 0;
return pluginVersion;
}
Ext.override(Ext.Toolbar, {
insertField : function(position, field){
var td = document.createElement("td");
this.tr.insertBefore(td, this.tr.childNodes[position]);
field.render(td);
var ti = new Ext.Toolbar.Item(td.firstChild);
ti.render(td);
this.items.insert(position, field);
return ti;
},
insertItem : function(position, item){
var td = document.createElement("td");
this.tr.insertBefore(td, this.tr.childNodes[position]);
item.render(td);
this.items.insert(position, item);
return item;
},
insertSeparator : function(position){
this.insertItem(position, new Ext.Toolbar.Separator());
},
insertSpacing : function(position){
this.insertItem(position, new Ext.Toolbar.Spacer());
},
insertFill : function(position){
this.insertItem(position, new Ext.Toolbar.Fill());
}
});
// http://extjs.com/learn/Tutorial:Extending_Ext2_Class
Ext.gt.IconCombo = Ext.extend(Ext.form.ComboBox, {
initComponent:function() {
Ext.apply(this, {
tpl: ''
+ '
'
+ '{' + this.displayField + '}'
+ '
'
});
Ext.gt.IconCombo.superclass.initComponent.call(this);
},
onRender:function(ct, position) {
Ext.gt.IconCombo.superclass.onRender.call(this, ct, position);
this.wrap.applyStyles({position:'relative'});
this.el.addClass('x-icon-combo-input');
this.icon = Ext.DomHelper.append(this.el.up('div.x-form-field-wrap'), {
tag: 'div', style:'position:absolute'
});
},
setIconCls:function() {
var rec = this.store.query(this.valueField, this.getValue()).itemAt(0);
if(rec) {
this.icon.className = 'x-icon-combo-icon x-flag-' + rec.get(this.valueField);
}
},
setValue: function(value) {
Ext.gt.IconCombo.superclass.setValue.call(this, value);
this.setIconCls();
}
});
Ext.reg('iconcombo', Ext.gt.IconCombo);
var sessionKeepAlive = function(url, interval){
var sessionDropped = function() {
Ext.Msg.show({
title: "Logged out",
msg: "You have been logged out. Any changes made in the current document will be discarded. "
+ "Press OK to redirect to the login page. "
+ "Press Cancel to close this message (if you need to copy unsaved changes from the current document, before reloading manually).",
buttons: Ext.Msg.OKCANCEL,
icon: Ext.Msg.ERROR,
fn: function(btn) {
if (btn == 'ok') {
window.location.reload(true);
}
Ext.TaskMgr.stop(t);
}
});
}
var failToContactServer = function() {
Ext.Msg.show({
title: "Connection interrupted",
msg: "Connection to the server is interrupted. "
+ "Press OK to try and establish a new connection with the server. "
+ "Press Cancel to close this message.",
buttons: Ext.Msg.OKCANCEL,
icon: Ext.Msg.ERROR,
fn: function(btn) {
if (btn == 'ok') {
window.location.reload(true);
}
Ext.TaskMgr.stop(t);
}
});
}
var t = {
run: function() {
Ext.Ajax.request({
url: url,
success: function(res, o) {
if (res.responseText.indexOf("") < 0) {
sessionDropped();
}
},
failure: function(){
failToContactServer();
}
});
},
interval: interval
}
Ext.TaskMgr.start(t);
}
if (Ext.ux.UploadForm) {
Ext.override(Ext.ux.UploadForm, {
getProgressTemplate : function(){
var tpl = new Ext.Template(
'
'
, '
' + this.pgSizeText + ':
'
, '
{bytes_uploaded}/{bytes_total}
'
, '
' + this.pgSpeedAvgText + ':
'
, '
{speed_average}
'
, '
' + this.pgEtaText + ':
'
, '
{est_sec}
'
, '
'
);
tpl.compile();
return tpl;
}
});
}
if (Ext.gt.SWFUpload) {
Ext.override(Ext.gt.SWFUpload, {
getProgressTemplate : function(){
var tpl = new Ext.Template(
'