wisemapping-open-source/wise-webapp/src/main/webapp/js/mymaps.js

210 lines
6.9 KiB
JavaScript
Raw Normal View History

2012-04-06 22:05:42 +02:00
jQuery.fn.dataTableExt.oSort['es_date-asc'] = function(a, b) {
var esDatea = a.split('/');
var esDateb = b.split('/');
var x = (esDatea[2] + esDatea[1] + esDatea[0]) * 1;
var y = (esDateb[2] + esDateb[1] + esDateb[0]) * 1;
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
};
jQuery.fn.dataTableExt.oSort['es_date-desc'] = function(a, b) {
var esDatea = a.split('/');
var esDateb = b.split('/');
var x = (esDatea[2] + esDatea[1] + esDatea[0]) * 1;
var y = (esDateb[2] + esDateb[1] + esDateb[0]) * 1;
return ((x < y) ? 1 : ((x > y) ? -1 : 0));
};
2012-05-24 02:54:03 +02:00
$.fn.dataTableExt.oApi.fnReloadAjax = function (oSettings, sNewSource, fnCallback, bStandingRedraw) {
if (typeof sNewSource != 'undefined' && sNewSource != null) {
oSettings.sAjaxSource = sNewSource;
}
this.oApi._fnProcessingDisplay(oSettings, true);
var that = this;
var iStart = oSettings._iDisplayStart;
var aData = [];
this.oApi._fnServerParams(oSettings, aData);
oSettings.fnServerData(oSettings.sAjaxSource, aData, function(json) {
/* Clear the old information from the table */
that.oApi._fnClearTable(oSettings);
/* Got the data - add it to the table */
var aData = (oSettings.sAjaxDataProp !== "") ?
that.oApi._fnGetObjectDataFn(oSettings.sAjaxDataProp)(json) : json;
for (var i = 0; i < aData.length; i++) {
that.oApi._fnAddData(oSettings, aData[i]);
}
oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
that.fnDraw();
if (typeof bStandingRedraw != 'undefined' && bStandingRedraw === true) {
oSettings._iDisplayStart = iStart;
that.fnDraw(false);
}
that.oApi._fnProcessingDisplay(oSettings, false);
/* Callback user function - for event handlers etc */
if (typeof fnCallback == 'function' && fnCallback != null) {
fnCallback(oSettings);
}
}, oSettings);
}
2012-04-06 22:05:42 +02:00
jQuery.fn.dataTableExt.selectAllMaps = function() {
var total = $('.select input:checkbox[id!="selectAll"]').size();
var selected = $('.select input:checked[id!="selectAll"]').size();
if (selected < total) {
$('.select input:!checked[id!="selectAll"]').each(function() {
$(this).prop("checked", true);
});
}
else {
$('.select input:!checked[id!="selectAll"]').each(function() {
$(this).prop("checked", false);
});
}
2012-05-21 02:46:55 +02:00
updateStatus();
2012-04-06 22:05:42 +02:00
};
jQuery.fn.dataTableExt.getSelectedMapsIds = function() {
var ids = [];
$('.select input:checked[id!="selectAll"]').each(function() {
var id = $(this).attr("id");
ids.push(id);
});
return ids;
};
2012-04-08 01:05:50 +02:00
jQuery.fn.dataTableExt.getSelectedRows = function() {
return $('.select input:checked[id!="selectAll"]').parent().parent();
};
2012-04-06 22:05:42 +02:00
jQuery.fn.dataTableExt.removeSelectedRows = function() {
2012-04-08 01:05:50 +02:00
var trs = this.getSelectedRows();
2012-05-23 06:13:00 +02:00
trs.each(function() {
$('#mindmapListTable').dataTable().fnDeleteRow(this);
2012-04-06 22:05:42 +02:00
});
2012-05-24 01:05:16 +02:00
updateStatus();
2012-04-06 22:05:42 +02:00
};
2012-04-08 01:05:50 +02:00
jQuery.fn.dialogForm = function(options) {
var containerId = this[0].id;
var url = options.url;
2012-05-20 02:36:34 +02:00
// Clear previous state ...
2012-05-24 01:05:16 +02:00
$("#" + containerId).find('.errorMessage').text("").removeClass("alert alert-error");
$("#" + containerId).find('.control-group').removeClass('error');
2012-05-20 02:36:34 +02:00
2012-05-24 01:05:16 +02:00
// Clear form values ...
if (options.clearForm == undefined || options.clearForm) {
$("#" + containerId).find('input').attr('value', '');
}
2012-04-08 01:05:50 +02:00
2012-05-24 02:54:03 +02:00
// Clear button "Saving..." state ...
2012-05-19 05:13:06 +02:00
var acceptBtn = $('#' + containerId + ' .btn-accept');
2012-05-24 01:05:16 +02:00
acceptBtn.button('reset');
2012-05-19 05:13:06 +02:00
acceptBtn.click(function() {
2012-04-08 01:05:50 +02:00
var formData = {};
$('#' + containerId + ' input').each(function(index, elem) {
formData[elem.name] = elem.value;
});
2012-05-24 01:05:16 +02:00
$(acceptBtn).button('loading');
2012-05-23 06:13:00 +02:00
var dialogElem = this;
2012-04-08 01:05:50 +02:00
jQuery.ajax(url, {
async:false,
dataType: 'json',
data: JSON.stringify(formData),
type: options.type ? options.type : 'POST',
contentType:"application/json; charset=utf-8",
success : function(data, textStatus, jqXHR) {
if (options.redirect) {
2012-04-15 11:59:32 +02:00
var resourceId = jqXHR.getResponseHeader("ResourceId");
var redirectUrl = options.redirect;
redirectUrl = redirectUrl.replace("{header.resourceId}", resourceId);
window.location = redirectUrl;
2012-04-08 01:05:50 +02:00
} else if (options.postUpdate) {
options.postUpdate(formData);
}
2012-05-23 06:13:00 +02:00
dialogElem.modal('hide');
2012-04-08 01:05:50 +02:00
},
error: function(jqXHR, textStatus, errorThrown) {
if (jqXHR.status == 400) {
var errors = JSON.parse(jqXHR.responseText);
// Mark fields with errors ...
var fieldErrors = errors.fieldErrors;
if (fieldErrors) {
for (var fieldName in fieldErrors) {
2012-05-24 02:54:03 +02:00
// Mark the field with errors ...
2012-04-08 01:05:50 +02:00
var message = fieldErrors[fieldName];
var inputField = $("#" + containerId + " input[name='" + fieldName + "']");
2012-05-20 02:36:34 +02:00
2012-05-24 01:05:16 +02:00
$("#" + containerId).find(".errorMessage").text(message).addClass("alert alert-error");
2012-05-20 02:36:34 +02:00
inputField.parent().addClass('error');
2012-04-08 01:05:50 +02:00
}
}
} else {
2012-05-24 01:05:16 +02:00
console.log(errorThrown);
console.log(jqXHR);
dialogElem.modal('hide');
$('#messagesPanel div').text(errorThrown).parent().show();
2012-04-08 01:05:50 +02:00
}
}
});
}.bind(this));
2012-04-08 01:05:50 +02:00
$('#' + containerId + ' .btn-cancel').click(function() {
this.modal('hide');
}.bind(this));
2012-04-08 01:05:50 +02:00
// Open the modal dialog ...
2012-05-23 06:13:00 +02:00
this.modal();
2012-04-08 01:05:50 +02:00
};
// Update toolbar events ...
2012-05-21 02:46:55 +02:00
function updateStatus() {
2012-05-20 07:25:54 +02:00
2012-05-21 02:46:55 +02:00
// Mark column row selection values ...
2012-05-20 07:25:54 +02:00
$("#mindmapListTable tbody input:checked").parent().parent().addClass('row-selected');
$("#mindmapListTable tbody input:not(:checked)").parent().parent().removeClass('row-selected');
2012-05-24 01:05:16 +02:00
$('#buttonsToolbar').find('.act-single').hide().end().find('.act-multiple').hide();
2012-05-21 02:46:55 +02:00
var tableElem = $('#mindmapListTable');
var selectedRows = tableElem.dataTableExt.getSelectedRows();
2012-05-21 02:46:55 +02:00
if (selectedRows.length > 0) {
if (selectedRows.length == 1) {
2012-05-24 01:05:16 +02:00
$('#buttonsToolbar').find('.act-single').show().end().find('.act-multiple').show();
2012-05-21 02:46:55 +02:00
// Can be executed by the owner ?
var rowData = tableElem.dataTable().fnGetData(selectedRows[0]);
if (rowData.ownerEmail != principalEmail) {
2012-05-24 01:05:16 +02:00
$("#buttonsToolbar").find('#publishBtn').hide().end().find('#shareBtn').hide();
2012-05-21 02:46:55 +02:00
}
} else {
$("#buttonsToolbar .act-multiple").show();
}
}
}