From 71793c38b842038852ec3dbe647dceb9e50a315b Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Tue, 29 May 2012 22:56:14 -0300 Subject: [PATCH] Move js code from editor to mymaps.js --- wise-webapp/src/main/webapp/css/mymaps.less | 5 +- wise-webapp/src/main/webapp/js/mymaps.js | 244 +++++++++++++++- .../src/main/webapp/jsp/mindmapList.jsp | 260 ++---------------- 3 files changed, 257 insertions(+), 252 deletions(-) diff --git a/wise-webapp/src/main/webapp/css/mymaps.less b/wise-webapp/src/main/webapp/css/mymaps.less index 1de4082d..cc861333 100644 --- a/wise-webapp/src/main/webapp/css/mymaps.less +++ b/wise-webapp/src/main/webapp/css/mymaps.less @@ -140,7 +140,6 @@ input#selectAll { text-align: center; } -/* New styles */ .row-selected { background-color: #f5f5f5; } @@ -197,4 +196,8 @@ span.starredOn{ span.starredOn:hover{ background: url('../images/star-on-hover.png') no-repeat center left; +} + +abbr[title] { + cursor:default; } \ No newline at end of file diff --git a/wise-webapp/src/main/webapp/js/mymaps.js b/wise-webapp/src/main/webapp/js/mymaps.js index 3580547e..7b451590 100644 --- a/wise-webapp/src/main/webapp/js/mymaps.js +++ b/wise-webapp/src/main/webapp/js/mymaps.js @@ -56,7 +56,7 @@ $.fn.dataTableExt.oApi.fnReloadAjax = function (oSettings, sNewSource, fnCallbac fnCallback(oSettings); } }, oSettings); -} +}; jQuery.fn.dataTableExt.selectAllMaps = function() { var total = $('.select input:checkbox[id!="selectAll"]').size(); @@ -75,16 +75,15 @@ jQuery.fn.dataTableExt.selectAllMaps = function() { }; jQuery.fn.dataTableExt.getSelectedMapsIds = function() { - var ids = []; - $('.select input:checked[id!="selectAll"]').each(function() { - var id = $(this).attr("id"); - ids.push(id); + console.log(this) + var selectedRows = $('#mindmapListTable').dataTableExt.getSelectedRows(); + var dataTable = $('#mindmapListTable').dataTable(); + return selectedRows.map(function() { + return dataTable.fnGetData(this).id; }); - - return ids; }; -jQuery.fn.dataTableExt.getSelectedRows = function() { +jQuery.fn.dataTableExt.getSelectedRows = function(oSettings) { return $('.select input:checked[id!="selectAll"]').parent().parent(); }; @@ -251,6 +250,235 @@ function updateStarred(spanElem) { rowData.starred = starred; } +function callbackOnTableInit() { + // Register starred events ... + console.log($('#mindmapListTable .starredOff, #mindmapListTable .starredOn')); + $('#mindmapListTable .starredOff, #mindmapListTable .starredOn').click(function() { + updateStarred(this); + }); +} + +$(function() { + $('#mindmapListTable').dataTable({ + bProcessing : true, + sAjaxSource : "../service/maps", + sAjaxDataProp: 'mindmapsInfo', + fnInitComplete: function() { + $('#mindmapListTable tbody').change(updateStatusToolbar); + callbackOnTableInit(); + }, + aoColumns: [ + { + sTitle : '', + sWidth : "55px", + sClass : "select", + bSortable : false, + bSearchable : false, + mDataProp: "starred", + bUseRendered : false, + fnRender : function(obj) { + return ''; + } + }, + { + sTitle : "Name", + sWidth:"270px", + bUseRendered : false, + mDataProp: "title", + fnRender : function(obj) { + return '' + obj.aData.title + ''; + } + }, + { + sTitle : "Owner", + mDataProp :"owner" + }, + { + bSearchable : false, + sTitle : "Last Modified", + bUseRendered: false, + sType: "date", + mDataProp: "lastModificationTime", + fnRender : function(obj) { + var time = obj.aData.lastModificationTime; + return '' + jQuery.timeago(time) + '' + ' ' + '' + obj.aData.lastModifierUser + ''; + } + } + ], + bAutoWidth : false, + oLanguage : { + "sSearch" : "", + "sInfo" : "_START_-_END_ of _TOTAL_", + "sEmptyTable": "No mindmap available for the selected filter criteria." + }, + bStateSave:true + }); + + // Customize search action ... + $('#mindmapListTable_filter').appendTo("#tableActions"); + $('#mindmapListTable_filter input').addClass('input-medium search-query'); + $('#mindmapListTable_filter input').attr('placeholder', 'Search'); + $("#mindmapListTable_info").appendTo("#pageInfo"); + + // Re-arrange pagination actions ... + $("#tableFooter").appendTo("#mindmapListTable_wrapper"); + $("#mindmapListTable_length").appendTo("#tableFooter"); + $('#mindmapListTable_length select').addClass('span1'); + + + $('input:checkbox[id="selectAll"]').click(function() { + $("#mindmapListTable").dataTableExt.selectAllMaps(); + }); + + // Hack for changing the pagination buttons ... + $('#nPageBtn').click(function() { + $('#mindmapListTable_next').click(); + }); + $('#pPageBtn').click(function() { + $('#mindmapListTable_previous').click(); + }); +}); + +$(function() { + // Creation buttons actions ... + $("#newBtn").click( + function() { + $("#new-dialog-modal").dialogForm({ + redirect: "c/maps/{header.resourceId}/edit.htm", + url : "../service/maps" + }); + }); + + $("#importBtn").click(function() { + window.open('c/maps/import.htm'); + }); + + $("#duplicateBtn").click(function() { + // Map to be cloned ... + var tableElem = $('#mindmapListTable'); + var rows = tableElem.dataTableExt.getSelectedRows(); + if (rows.length > 0) { + + // Obtain map name ... + var rowData = tableElem.dataTable().fnGetData(rows[0]); + $('#dupDialogTitle').text("Duplicate '" + rowData.title + "'"); + + // Obtains map id ... + var mapId = rowData.id; + + // Initialize dialog ... + $("#duplicate-dialog-modal").dialogForm({ + redirect: "c/maps/{header.resourceId}/edit.htm", + url : "../service/maps/" + mapId + }); + } + }); + + $("#renameBtn").click(function() { + // Map to be cloned ... + var tableElem = $('#mindmapListTable'); + var rows = tableElem.dataTableExt.getSelectedRows(); + if (rows.length > 0) { + + // Obtain map name ... + var dataTable = tableElem.dataTable(); + var rowData = dataTable.fnGetData(rows[0]); + + // Fill dialog with default values ... + var mapId = rowData.id; + $("#rename-dialog-modal input[name='title']").attr('value', rowData.title); + $("#rename-dialog-modal input[name='description']").attr('value', rowData.description); + + // Set title ... + $('#renameDialogTitle').text("Rename '" + rowData.title + "'"); + + // Initialize dialog ... + $("#rename-dialog-modal").dialogForm({ + type: 'PUT', + clearForm: false, + postUpdate: function(reqBodyData) { + tableElem.dataTableExt.removeSelectedRows(); + + rowData.title = reqBodyData.title; + rowData.description = reqBodyData.description; + dataTable.fnAddData(JSON.parse(JSON.stringify(rowData))); + }, + url : "../service/maps/" + mapId + }); + } + }); + + $("#deleteBtn").click(function() { + var tableUI = $('#mindmapListTable'); + + var mapIds = tableUI.dataTableExt.getSelectedMapsIds(); + if (mapIds.length > 0) { + // Initialize dialog ... + $("#delete-dialog-modal").dialogForm({ + type: 'DELETE', + postUpdate: function(reqBodyData) { + // Remove old entry ... + tableUI.dataTableExt.removeSelectedRows(); + }, + url : "../service/maps/batch?ids=" + mapIds.join(',') + }); + } + }); + + $("#printBtn").click(function() { + var mapIds = $('#mindmapListTable').dataTableExt.getSelectedMapsIds(); + if (mapIds.length > 0) { + window.open('c/maps/' + mapIds[0] + '/print.htm'); + } + }); + + $("#infoBtn").click(function() { + var mapIds = $('#mindmapListTable').dataTableExt.getSelectedMapsIds(); + if (mapIds.length > 0) { + $('#info-dialog-modal .modal-body').load("c/maps/" + mapIds[0] + "/details.htm", function() { + $('#info-dialog-modal').modal(); + }); + + } + }); + + $("#publishBtn").click(function() { + var mapIds = $('#mindmapListTable').dataTableExt.getSelectedMapsIds(); + if (mapIds.length > 0) { + $('#publish-dialog-modal .modal-body').load("c/maps/" + mapIds[0] + "/publish.htm", + function() { + $('#publish-dialog-modal .btn-accept').click(function() { + submitDialogForm(); + }); + $('#publish-dialog-modal').modal(); + }); + } + }); + + $("#actionButtons .shareMap").click(function() { + }); + + + $('#foldersContainer li').click(function(event) { + // Deselect previous option ... + $('#foldersContainer li').removeClass('active'); + $('#foldersContainer i').removeClass('icon-white'); + + // Select the new item ... + var dataTable = $('#mindmapListTable').dataTable(); + $(this).addClass('active'); + $('#foldersContainer .active i').addClass('icon-white'); + + // Reload the table data ... + dataTable.fnReloadAjax("../service/maps?q=" + $(this).attr('data-filter'), callbackOnTableInit, true); + event.preventDefault(); + }); +}); + +// Register time update functions .... +setTimeout(function() { + jQuery("abbr.timeago").timeago() +}, 50000); diff --git a/wise-webapp/src/main/webapp/jsp/mindmapList.jsp b/wise-webapp/src/main/webapp/jsp/mindmapList.jsp index 413afe3b..6a35cd80 100644 --- a/wise-webapp/src/main/webapp/jsp/mindmapList.jsp +++ b/wise-webapp/src/main/webapp/jsp/mindmapList.jsp @@ -3,257 +3,31 @@ <%@ include file="/jsp/init.jsp" %> - -<spring:message code="SITE.TITLE"/> - + + <spring:message code="SITE.TITLE"/> + - - + + - + - - - + + + - - - + + + - - - - - $('input:checkbox[id="selectAll"]').click(function() { - $("#mindmapListTable").dataTableExt.selectAllMaps(); - }); + - // Hack for changing the lagination buttons ... - $('#nPageBtn').click(function() { - $('#mindmapListTable_next').click(); - }); - $('#pPageBtn').click(function() { - $('#mindmapListTable_previous').click(); - }); - }); - - - -