- IE window.open does not support base href tag. Fixed.

This commit is contained in:
Paulo Gustavo Veiga 2012-08-15 21:05:44 -03:00
parent 70cebe97fc
commit dde7806b38
2 changed files with 63 additions and 57 deletions

View File

@ -223,7 +223,8 @@ mindplot.widget.Menu = new Class({
this._registerTooltip('export', $msg('EXPORT')); this._registerTooltip('export', $msg('EXPORT'));
this._addButton('print', false, false, function () { this._addButton('print', false, false, function () {
window.open('c/maps/' + mapId + '/print'); var baseUrl = window.location.href.substring(0, window.location.href.lastIndexOf("c/maps/"));
window.open(baseUrl + 'c/maps/' + mapId + '/print');
}); });
this._registerTooltip('print', $msg('PRINT')); this._registerTooltip('print', $msg('PRINT'));

View File

@ -1,4 +1,4 @@
jQuery.fn.dataTableExt.oSort['es_date-asc'] = function(a, b) { jQuery.fn.dataTableExt.oSort['es_date-asc'] = function (a, b) {
var esDatea = a.split('/'); var esDatea = a.split('/');
var esDateb = b.split('/'); var esDateb = b.split('/');
@ -8,7 +8,7 @@ jQuery.fn.dataTableExt.oSort['es_date-asc'] = function(a, b) {
return ((x < y) ? -1 : ((x > y) ? 1 : 0)); return ((x < y) ? -1 : ((x > y) ? 1 : 0));
}; };
jQuery.fn.dataTableExt.oSort['es_date-desc'] = function(a, b) { jQuery.fn.dataTableExt.oSort['es_date-desc'] = function (a, b) {
var esDatea = a.split('/'); var esDatea = a.split('/');
var esDateb = b.split('/'); var esDateb = b.split('/');
@ -29,7 +29,7 @@ $.fn.dataTableExt.oApi.fnReloadAjax = function (oSettings, sNewSource, fnCallbac
this.oApi._fnServerParams(oSettings, aData); this.oApi._fnServerParams(oSettings, aData);
oSettings.fnServerData(oSettings.sAjaxSource, aData, function(json) { oSettings.fnServerData(oSettings.sAjaxSource, aData, function (json) {
/* Clear the old information from the table */ /* Clear the old information from the table */
that.oApi._fnClearTable(oSettings); that.oApi._fnClearTable(oSettings);
@ -58,44 +58,44 @@ $.fn.dataTableExt.oApi.fnReloadAjax = function (oSettings, sNewSource, fnCallbac
}, oSettings); }, oSettings);
}; };
jQuery.fn.dataTableExt.selectAllMaps = function() { jQuery.fn.dataTableExt.selectAllMaps = function () {
var total = $('.select input:checkbox[id!="selectAll"]').size(); var total = $('.select input:checkbox[id!="selectAll"]').size();
var selected = $('.select input:checked[id!="selectAll"]').size(); var selected = $('.select input:checked[id!="selectAll"]').size();
if (selected < total) { if (selected < total) {
$('.select input:!checked[id!="selectAll"]').each(function() { $('.select input:!checked[id!="selectAll"]').each(function () {
$(this).prop("checked", true); $(this).prop("checked", true);
}); });
} }
else { else {
$('.select input:!checked[id!="selectAll"]').each(function() { $('.select input:!checked[id!="selectAll"]').each(function () {
$(this).prop("checked", false); $(this).prop("checked", false);
}); });
} }
updateStatusToolbar(); updateStatusToolbar();
}; };
jQuery.fn.dataTableExt.getSelectedMapsIds = function() { jQuery.fn.dataTableExt.getSelectedMapsIds = function () {
var selectedRows = $('#mindmapListTable').dataTableExt.getSelectedRows(); var selectedRows = $('#mindmapListTable').dataTableExt.getSelectedRows();
var dataTable = $('#mindmapListTable').dataTable(); var dataTable = $('#mindmapListTable').dataTable();
return selectedRows.map(function() { return selectedRows.map(function () {
return dataTable.fnGetData(this).id; return dataTable.fnGetData(this).id;
}); });
}; };
jQuery.fn.dataTableExt.getSelectedRows = function(oSettings) { jQuery.fn.dataTableExt.getSelectedRows = function (oSettings) {
return $('.select input:checked[id!="selectAll"]').parent().parent(); return $('.select input:checked[id!="selectAll"]').parent().parent();
}; };
jQuery.fn.dataTableExt.removeSelectedRows = function() { jQuery.fn.dataTableExt.removeSelectedRows = function () {
var trs = this.getSelectedRows(); var trs = this.getSelectedRows();
trs.each(function() { trs.each(function () {
$('#mindmapListTable').dataTable().fnDeleteRow(this); $('#mindmapListTable').dataTable().fnDeleteRow(this);
}); });
updateStatusToolbar(); updateStatusToolbar();
}; };
jQuery.fn.dialogForm = function(options) { jQuery.fn.dialogForm = function (options) {
var containerId = this[0].id; var containerId = this[0].id;
var url = options.url; var url = options.url;
@ -113,32 +113,35 @@ jQuery.fn.dialogForm = function(options) {
var acceptBtn = $('#' + containerId + ' .btn-accept'); var acceptBtn = $('#' + containerId + ' .btn-accept');
acceptBtn.button('reset'); acceptBtn.button('reset');
acceptBtn.click(function() { acceptBtn.click(function () {
var formData = {}; var formData = {};
$('#' + containerId + ' input').each(function(index, elem) { $('#' + containerId + ' input').each(function (index, elem) {
formData[elem.name] = elem.value; formData[elem.name] = elem.value;
}); });
$(acceptBtn).button('loading'); $(acceptBtn).button('loading');
var dialogElem = this; var dialogElem = this;
jQuery.ajax(url, { jQuery.ajax(url, {
async:false, async:false,
dataType: 'json', dataType:'json',
data: JSON.stringify(formData), data:JSON.stringify(formData),
type: options.type ? options.type : 'POST', type:options.type ? options.type : 'POST',
contentType:"application/json; charset=utf-8", contentType:"application/json; charset=utf-8",
success : function(data, textStatus, jqXHR) { success:function (data, textStatus, jqXHR) {
if (options.redirect) { if (options.redirect) {
var resourceId = jqXHR.getResponseHeader("ResourceId"); var resourceId = jqXHR.getResponseHeader("ResourceId");
var redirectUrl = options.redirect; var redirectUrl = options.redirect;
redirectUrl = redirectUrl.replace("{header.resourceId}", resourceId); redirectUrl = redirectUrl.replace("{header.resourceId}", resourceId);
window.location = redirectUrl;
// Hack: IE ignore the base href tag ...
var baseUrl = window.location.href.substring(0, window.location.href.lastIndexOf("c/maps/"));
window.open(baseUrl + redirectUrl, '_self');
} else if (options.postUpdate) { } else if (options.postUpdate) {
options.postUpdate(formData); options.postUpdate(formData);
} }
dialogElem.modal('hide'); dialogElem.modal('hide');
}, },
error: function(jqXHR, textStatus, errorThrown) { error:function (jqXHR, textStatus, errorThrown) {
if (jqXHR.status == 400) { if (jqXHR.status == 400) {
var errors = JSON.parse(jqXHR.responseText); var errors = JSON.parse(jqXHR.responseText);
// Mark fields with errors ... // Mark fields with errors ...
@ -167,7 +170,7 @@ jQuery.fn.dialogForm = function(options) {
}); });
}.bind(this)); }.bind(this));
$('#' + containerId + ' .btn-cancel').click(function() { $('#' + containerId + ' .btn-cancel').click(function () {
this.modal('hide'); this.modal('hide');
}.bind(this)); }.bind(this));
@ -228,11 +231,11 @@ function updateStarred(spanElem) {
jQuery.ajax("service/maps/" + mapId + "/starred", { jQuery.ajax("service/maps/" + mapId + "/starred", {
async:false, async:false,
dataType: 'json', dataType:'json',
data: "" + starred, data:"" + starred,
type: 'PUT', type:'PUT',
contentType:"text/plain", contentType:"text/plain",
success : function() { success:function () {
if (starred) { if (starred) {
$(spanElem).removeClass('starredOff'); $(spanElem).removeClass('starredOff');
$(spanElem).addClass('starredOn'); $(spanElem).addClass('starredOn');
@ -241,7 +244,7 @@ function updateStarred(spanElem) {
$(spanElem).addClass('starredOff'); $(spanElem).addClass('starredOff');
} }
}, },
error: function(jqXHR, textStatus, errorThrown) { error:function (jqXHR, textStatus, errorThrown) {
$('#messagesPanel div').text(errorThrown).parent().show(); $('#messagesPanel div').text(errorThrown).parent().show();
} }
}); });
@ -252,23 +255,23 @@ function updateStarred(spanElem) {
function callbackOnTableInit() { function callbackOnTableInit() {
// Register starred events ... // Register starred events ...
$('#mindmapListTable .starredOff, #mindmapListTable .starredOn').click(function() { $('#mindmapListTable .starredOff, #mindmapListTable .starredOn').click(function () {
updateStarred(this); updateStarred(this);
}); });
updateStatusToolbar(); updateStatusToolbar();
} }
$(function() { $(function () {
// Creation buttons actions ... // Creation buttons actions ...
$("#newBtn").click( $("#newBtn").click(
function() { function () {
$("#new-dialog-modal").dialogForm({ $("#new-dialog-modal").dialogForm({
redirect: "/c/maps/{header.resourceId}/edit", redirect:"c/maps/{header.resourceId}/edit",
url : "service/maps" url:"service/maps"
}); });
}); });
$("#duplicateBtn").click(function() { $("#duplicateBtn").click(function () {
// Map to be cloned ... // Map to be cloned ...
var tableElem = $('#mindmapListTable'); var tableElem = $('#mindmapListTable');
var rows = tableElem.dataTableExt.getSelectedRows(); var rows = tableElem.dataTableExt.getSelectedRows();
@ -283,13 +286,13 @@ $(function() {
// Initialize dialog ... // Initialize dialog ...
$("#duplicate-dialog-modal").dialogForm({ $("#duplicate-dialog-modal").dialogForm({
redirect: "/c/maps/{header.resourceId}/edit", redirect:"c/maps/{header.resourceId}/edit",
url : "service/maps/" + mapId url:"service/maps/" + mapId
}); });
} }
}); });
$("#renameBtn").click(function() { $("#renameBtn").click(function () {
// Map to be cloned ... // Map to be cloned ...
var tableElem = $('#mindmapListTable'); var tableElem = $('#mindmapListTable');
var rows = tableElem.dataTableExt.getSelectedRows(); var rows = tableElem.dataTableExt.getSelectedRows();
@ -309,21 +312,21 @@ $(function() {
// Initialize dialog ... // Initialize dialog ...
$("#rename-dialog-modal").dialogForm({ $("#rename-dialog-modal").dialogForm({
type: 'PUT', type:'PUT',
clearForm: false, clearForm:false,
postUpdate: function(reqBodyData) { postUpdate:function (reqBodyData) {
tableElem.dataTableExt.removeSelectedRows(); tableElem.dataTableExt.removeSelectedRows();
rowData.title = reqBodyData.title; rowData.title = reqBodyData.title;
rowData.description = reqBodyData.description; rowData.description = reqBodyData.description;
dataTable.fnAddData(JSON.parse(JSON.stringify(rowData))); dataTable.fnAddData(JSON.parse(JSON.stringify(rowData)));
}, },
url : "service/maps/" + mapId url:"service/maps/" + mapId
}); });
} }
}); });
$("#deleteBtn").click(function() { $("#deleteBtn").click(function () {
var tableUI = $('#mindmapListTable'); var tableUI = $('#mindmapListTable');
var mapIds = tableUI.dataTableExt.getSelectedMapsIds(); var mapIds = tableUI.dataTableExt.getSelectedMapsIds();
@ -331,54 +334,56 @@ $(function() {
if (mapIds.length > 0) { if (mapIds.length > 0) {
// Initialize dialog ... // Initialize dialog ...
$("#delete-dialog-modal").dialogForm({ $("#delete-dialog-modal").dialogForm({
type: 'DELETE', type:'DELETE',
postUpdate: function() { postUpdate:function () {
// Remove old entry ... // Remove old entry ...
tableUI.dataTableExt.removeSelectedRows(); tableUI.dataTableExt.removeSelectedRows();
}, },
url : "service/maps/batch?ids=" + jQuery.makeArray(mapIds).join(',') url:"service/maps/batch?ids=" + jQuery.makeArray(mapIds).join(',')
}); });
} }
}); });
$("#printBtn").click(function() { $("#printBtn").click(function () {
var mapIds = $('#mindmapListTable').dataTableExt.getSelectedMapsIds(); var mapIds = $('#mindmapListTable').dataTableExt.getSelectedMapsIds();
if (mapIds.length > 0) { if (mapIds.length > 0) {
window.open('c/maps/' + mapIds[0] + '/print'); // Hack: IE ignore the base href tag ...
var baseUrl = window.location.href.substring(0, window.location.href.lastIndexOf("c/maps/"));
window.open(baseUrl + 'c/maps/' + mapIds[0] + '/print');
} }
}); });
$("#infoBtn").click(function() { $("#infoBtn").click(function () {
showEmbeddedDialog("c/maps/{mapId}/details", 'info-dialog-modal'); showEmbeddedDialog("c/maps/{mapId}/details", 'info-dialog-modal');
}); });
$("#historyBtn").click(function() { $("#historyBtn").click(function () {
showEmbeddedDialog("c/maps/{mapId}/history", 'history-dialog-modal'); showEmbeddedDialog("c/maps/{mapId}/history", 'history-dialog-modal');
}); });
$("#publishBtn").click(function() { $("#publishBtn").click(function () {
showEmbeddedDialog("c/maps/{mapId}/publish", "publish-dialog-modal"); showEmbeddedDialog("c/maps/{mapId}/publish", "publish-dialog-modal");
}); });
$("#exportBtn").click(function() { $("#exportBtn").click(function () {
showEmbeddedDialog("c/maps/{mapId}/export", 'export-dialog-modal'); showEmbeddedDialog("c/maps/{mapId}/export", 'export-dialog-modal');
}); });
$("#importBtn").click(function() { $("#importBtn").click(function () {
showEmbeddedDialog("c/maps/import", 'import-dialog-modal', true); showEmbeddedDialog("c/maps/import", 'import-dialog-modal', true);
}); });
$("#shareBtn").click(function() { $("#shareBtn").click(function () {
showEmbeddedDialog("c/maps/{mapId}/share", 'share-dialog-modal', true); showEmbeddedDialog("c/maps/{mapId}/share", 'share-dialog-modal', true);
}); });
var showEmbeddedDialog = function(urlTemplate, dialogElemId, ignore) { var showEmbeddedDialog = function (urlTemplate, dialogElemId, ignore) {
var mapIds = $('#mindmapListTable').dataTableExt.getSelectedMapsIds(); var mapIds = $('#mindmapListTable').dataTableExt.getSelectedMapsIds();
if (mapIds.length > 0 || ignore) { if (mapIds.length > 0 || ignore) {
var mapId = mapIds[0]; var mapId = mapIds[0];
$('#' + dialogElemId + ' .modal-body').load(urlTemplate.replace("{mapId}", mapId), $('#' + dialogElemId + ' .modal-body').load(urlTemplate.replace("{mapId}", mapId),
function() { function () {
$('#' + dialogElemId + ' .btn-accept').unbind('click').click(function() { $('#' + dialogElemId + ' .btn-accept').unbind('click').click(function () {
submitDialogForm(); submitDialogForm();
}); });
$('#' + dialogElemId).modal(); $('#' + dialogElemId).modal();
@ -386,7 +391,7 @@ $(function() {
} }
}; };
$('#foldersContainer li').click(function(event) { $('#foldersContainer li').click(function (event) {
// Deselect previous option ... // Deselect previous option ...
$('#foldersContainer li').removeClass('active'); $('#foldersContainer li').removeClass('active');
$('#foldersContainer i').removeClass('icon-white'); $('#foldersContainer i').removeClass('icon-white');
@ -403,7 +408,7 @@ $(function() {
}); });
// Register time update functions .... // Register time update functions ....
setTimeout(function() { setTimeout(function () {
jQuery("abbr.timeago").timeago() jQuery("abbr.timeago").timeago()
}, 50000); }, 50000);