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

175 lines
5.6 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));
};
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() {
var mapIds = this.getSelectedMapsIds();
2012-04-08 01:05:50 +02:00
var trs = this.getSelectedRows();
2012-04-06 22:05:42 +02:00
jQuery.ajax({
async:false,
url: "../service/maps/batch?ids=" + mapIds.join(","),
type:"DELETE",
success : function(data, textStatus, jqXHR) {
trs.each(function() {
$('#mindmapListTable').dataTable().fnDeleteRow(this);
});
},
2012-04-08 01:05:50 +02:00
error: function() {
2012-04-06 22:05:42 +02:00
alert("Unexpected error removing maps. Refresh before continue.");
}
});
};
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 ...
$("#" + containerId + " .errorMessage").text("").removeClass("alert alert-error");
$("#" + containerId + " .control-group").removeClass('error');
2012-05-20 07:25:54 +02:00
$("#" + containerId + " input").attr('value', '');
2012-05-20 02:36:34 +02:00
2012-04-08 01:05:50 +02:00
2012-05-19 05:13:06 +02:00
var acceptBtn = $('#' + containerId + ' .btn-accept');
acceptBtn.click(function() {
2012-04-08 01:05:50 +02:00
var formData = {};
$('#' + containerId + ' input').each(function(index, elem) {
formData[elem.name] = elem.value;
});
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);
2012-05-19 05:13:06 +02:00
$(acceptBtn).button('loading');
2012-04-15 11:59:32 +02:00
window.location = redirectUrl;
2012-04-08 01:05:50 +02:00
} else if (options.postUpdate) {
2012-05-19 05:13:06 +02:00
2012-04-08 01:05:50 +02:00
options.postUpdate(formData);
}
},
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) {
// Mark the field ...
var message = fieldErrors[fieldName];
var inputField = $("#" + containerId + " input[name='" + fieldName + "']");
2012-05-20 02:36:34 +02:00
$("#" + containerId + " .errorMessage").text(message).addClass("alert alert-error");
inputField.parent().addClass('error');
2012-04-08 01:05:50 +02:00
}
}
} else {
alert("Unexpected error removing maps. Refresh before continue.");
}
}
});
}.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 ...
this.modal(options);
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-21 02:46:55 +02:00
// Update toolbar ...
$("#buttonsToolbar .act-multiple").hide();
$("#buttonsToolbar .act-single").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) {
$("#buttonsToolbar .act-single").show();
$("#buttonsToolbar .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) {
$("#buttonsToolbar #publishBtn").hide();
$("#buttonsToolbar #shareBtn").hide();
}
} else {
$("#buttonsToolbar .act-multiple").show();
}
}
}