java: different edit/view options
@ -70,10 +70,7 @@ public class EditorServlet extends HttpServlet
|
||||
CookieManager cm = new CookieManager(request);
|
||||
|
||||
FileModel file = new FileModel(fileName, cm.getCookie("ulang"), cm.getCookie("uid"), cm.getCookie("uname"));
|
||||
if ("embedded".equals(request.getParameter("mode")))
|
||||
file.InitDesktop();
|
||||
if ("view".equals(request.getParameter("mode")))
|
||||
file.editorConfig.mode = "view";
|
||||
file.changeType(request.getParameter("mode"), request.getParameter("type"));
|
||||
|
||||
if (DocumentManager.TokenEnabled())
|
||||
{
|
||||
|
||||
@ -82,6 +82,9 @@ public class IndexServlet extends HttpServlet
|
||||
case "track":
|
||||
Track(request, response, writer);
|
||||
break;
|
||||
case "remove":
|
||||
Remove(request, response, writer);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -332,6 +335,25 @@ public class IndexServlet extends HttpServlet
|
||||
writer.write("{\"error\":" + saved + "}");
|
||||
}
|
||||
|
||||
private static void Remove(HttpServletRequest request, HttpServletResponse response, PrintWriter writer)
|
||||
{
|
||||
try
|
||||
{
|
||||
String fileName = request.getParameter("filename");
|
||||
String path = DocumentManager.StoragePath(fileName, null);
|
||||
|
||||
File f = new File(path);
|
||||
if (f.exists()) {
|
||||
f.delete();
|
||||
}
|
||||
|
||||
writer.write("{ \"success\": true }");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
writer.write("{ \"error\": \"" + e.getMessage() + "\"}");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||
|
||||
@ -24,9 +24,9 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
package entities;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import helpers.DocumentManager;
|
||||
@ -37,6 +37,7 @@ import com.google.gson.Gson;
|
||||
public class FileModel
|
||||
{
|
||||
public String type = "desktop";
|
||||
public String mode = "edit";
|
||||
public String documentType;
|
||||
public Document document;
|
||||
public EditorConfig editorConfig;
|
||||
@ -53,11 +54,9 @@ public class FileModel
|
||||
document.title = fileName;
|
||||
document.url = DocumentManager.GetFileUri(fileName);
|
||||
document.fileType = FileUtility.GetFileExtension(fileName).replace(".", "");
|
||||
document.key = ServiceConverter.GenerateRevisionId(DocumentManager.CurUserHostAddress(null) + "/" + fileName);
|
||||
document.key = ServiceConverter.GenerateRevisionId(DocumentManager.CurUserHostAddress(null) + "/" + fileName + "/" + Long.toString(new File(DocumentManager.StoragePath(fileName, null)).lastModified()));
|
||||
|
||||
editorConfig = new EditorConfig();
|
||||
if (!DocumentManager.GetEditedExts().contains(FileUtility.GetFileExtension(fileName)))
|
||||
editorConfig.mode = "view";
|
||||
editorConfig.callbackUrl = DocumentManager.GetCallback(fileName);
|
||||
if (lang != null) editorConfig.lang = lang;
|
||||
|
||||
@ -65,11 +64,26 @@ public class FileModel
|
||||
if (uname != null) editorConfig.user.name = uname;
|
||||
|
||||
editorConfig.customization.goback.url = DocumentManager.GetServerUrl() + "/IndexServlet";
|
||||
|
||||
changeType(mode, type);
|
||||
}
|
||||
|
||||
public void changeType(String _mode, String _type)
|
||||
{
|
||||
if (_mode != null) mode = _mode;
|
||||
if (_type != null) type = _type;
|
||||
|
||||
Boolean canEdit = DocumentManager.GetEditedExts().contains(FileUtility.GetFileExtension(document.title));
|
||||
|
||||
editorConfig.mode = canEdit && !mode.equals("view") ? "edit" : "view";
|
||||
|
||||
document.permissions = new Permissions(mode, type, canEdit);
|
||||
|
||||
if (type.equals("embedded")) InitDesktop();
|
||||
}
|
||||
|
||||
public void InitDesktop()
|
||||
{
|
||||
type = "embedded";
|
||||
editorConfig.InitDesktop(document.url);
|
||||
}
|
||||
|
||||
@ -90,6 +104,27 @@ public class FileModel
|
||||
public String url;
|
||||
public String fileType;
|
||||
public String key;
|
||||
public Permissions permissions;
|
||||
}
|
||||
|
||||
public class Permissions
|
||||
{
|
||||
public Boolean comment;
|
||||
public Boolean download;
|
||||
public Boolean edit;
|
||||
public Boolean fillForms;
|
||||
public Boolean modifyFilter;
|
||||
public Boolean review;
|
||||
|
||||
public Permissions(String mode, String type, Boolean canEdit)
|
||||
{
|
||||
comment = !mode.equals("view") && !mode.equals("fillForms") && !mode.equals("embedded");
|
||||
download = true;
|
||||
edit = canEdit && (mode.equals("edit") || mode.equals("filter"));
|
||||
fillForms = !mode.equals("view") && !mode.equals("comment") && !mode.equals("embedded");
|
||||
modifyFilter = !mode.equals("filter");
|
||||
review = mode.equals("edit") || mode.equals("review");
|
||||
}
|
||||
}
|
||||
|
||||
public class EditorConfig
|
||||
|
||||
|
After Width: | Height: | Size: 127 B |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.0 KiB |
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 152 B |
|
After Width: | Height: | Size: 118 B |
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 145 B |
@ -305,8 +305,53 @@ label .checkbox {
|
||||
line-height: 26px;
|
||||
}
|
||||
|
||||
.stored-edit {
|
||||
background-color: transparent;
|
||||
background-position: left center;
|
||||
background-repeat: no-repeat;
|
||||
display: inline-block;
|
||||
line-height: 16px;
|
||||
max-width: 450px;
|
||||
margin-bottom: -6px;
|
||||
overflow: hidden;
|
||||
padding: 4px 0 1px 34px;
|
||||
text-decoration: none;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.stored-edit.text {
|
||||
background-image: url("img/icon_docx.png");
|
||||
}
|
||||
|
||||
.stored-edit.spreadsheet {
|
||||
background-image: url("img/icon_xlsx.png");
|
||||
}
|
||||
|
||||
.stored-edit.presentation {
|
||||
background-image: url("img/icon_pptx.png");
|
||||
}
|
||||
|
||||
.stored-edit span {
|
||||
font-size: 12px;
|
||||
line-height: 12px;
|
||||
}
|
||||
|
||||
.stored-edit:hover span {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.stored-download {
|
||||
color: #787878;
|
||||
float: right;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
|
||||
.stored-download:hover {
|
||||
color: #787878;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.blockTitle {
|
||||
background-color: #E2E2E2 !important;
|
||||
@ -361,6 +406,95 @@ label .checkbox {
|
||||
padding: 12px 0;
|
||||
}
|
||||
|
||||
#tableRow {
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
.tableRow {
|
||||
background: transparent;
|
||||
-moz-transition: all 0.2s ease-in-out;
|
||||
-webkit-transition: all 0.2s ease-in-out;
|
||||
-o-transition: all 0.2s ease-in-out;
|
||||
-ms-transition: all 0.2s ease-in-out;
|
||||
transition: all 0.2s ease-in-out;
|
||||
}
|
||||
|
||||
.tableRow:hover {
|
||||
background-color: #ebebeb;
|
||||
}
|
||||
|
||||
.tableHeader {
|
||||
background: transparent;
|
||||
color: #333;
|
||||
cursor: default;
|
||||
font-family: 'Open Sans', sans-serif;
|
||||
font-size: 13px;
|
||||
height: 40px;
|
||||
-khtml-user-select: none;
|
||||
user-select: none;
|
||||
-moz-user-select: none;
|
||||
-webkit-user-select: none;
|
||||
}
|
||||
|
||||
.tableHeaderCell {
|
||||
padding: 2px 1px 2px 5px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.tableHeaderCellFileName {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.contentCells {
|
||||
padding: 4px 1px 4px 5px;
|
||||
font-family: 'Open Sans', sans-serif;
|
||||
font-size: 16px;
|
||||
border-bottom: 1px solid #e5e5e5;
|
||||
white-space: nowrap;
|
||||
-khtml-user-select: none;
|
||||
user-select: none;
|
||||
-moz-user-select: none;
|
||||
-webkit-user-select: none;
|
||||
}
|
||||
|
||||
.contentCells a {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.contentCells-shift {
|
||||
padding-right: 30px;
|
||||
}
|
||||
|
||||
.contentCells-icon {
|
||||
width: 6%;
|
||||
}
|
||||
|
||||
.contentCellsSmall {
|
||||
padding: 5px 1px 5px 6px;
|
||||
font-family: 'Open Sans', sans-serif;
|
||||
font-size: 13px;
|
||||
border-bottom: 1px solid #e5e5e5;
|
||||
white-space: nowrap;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.primaryRow {
|
||||
background-color: #e9e9e9;
|
||||
}
|
||||
|
||||
.secondaryRow {
|
||||
background-color: #F9F9F9;
|
||||
}
|
||||
|
||||
#user, #language {
|
||||
width: 130px;
|
||||
}
|
||||
|
||||
.icon-download {
|
||||
margin-bottom: -5px;
|
||||
}
|
||||
|
||||
.icon-delete {
|
||||
cursor: pointer;
|
||||
margin-bottom: -6px;
|
||||
}
|
||||
@ -25,9 +25,11 @@
|
||||
*-->
|
||||
|
||||
<%@page import="helpers.DocumentManager"%>
|
||||
<%@page import="helpers.FileUtility"%>
|
||||
<%@page import="helpers.ConfigManager"%>
|
||||
<%@page import="java.util.Calendar"%>
|
||||
<%@page import="java.io.File"%>
|
||||
<%@page import="java.net.URLEncoder"%>
|
||||
<%@page contentType="text/html" pageEncoding="UTF-8"%>
|
||||
|
||||
<!DOCTYPE html>
|
||||
@ -124,16 +126,96 @@
|
||||
</div>
|
||||
|
||||
<% DocumentManager.Init(request, response); %>
|
||||
<% File[] files = DocumentManager.GetStoredFiles(null);
|
||||
if (files.length > 0) {
|
||||
for (Integer i = 0; i < files.length; i++)
|
||||
{ %>
|
||||
<div>
|
||||
<%= files[i].getName() %>
|
||||
<div>
|
||||
<% }
|
||||
}
|
||||
%>
|
||||
<% File[] files = DocumentManager.GetStoredFiles(null); %>
|
||||
<% if (files.length > 0) { %>
|
||||
|
||||
<div class="help-block">
|
||||
<span>Your documents</span>
|
||||
<br />
|
||||
<br />
|
||||
|
||||
<div class="stored-list">
|
||||
<table width="100%" cellspacing="0" cellpadding="0">
|
||||
<thead>
|
||||
<tr class="tableHeader">
|
||||
<td class="tableHeaderCell tableHeaderCellFileName">Filename</td>
|
||||
<td colspan="5" class="tableHeaderCell contentCells-shift">Editors</td>
|
||||
<td colspan="3" class="tableHeaderCell">Viewers</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% for (Integer i = 0; i < files.length; i++) { %>
|
||||
<% String docType = FileUtility.GetFileType(files[i].getName()).toString().toLowerCase(); %>
|
||||
<tr class="tableRow" title="<%= files[i].getName() %>">
|
||||
<td class="contentCells">
|
||||
<a class="stored-edit <%= docType %>" href="EditorServlet?fileName=<%= URLEncoder.encode(files[i].getName(), "UTF-8") %>" target="_blank">
|
||||
<span title="<%= files[i].getName() %>"><%= files[i].getName() %></span>
|
||||
</a>
|
||||
<a href="<%= DocumentManager.GetFileUri(files[i].getName()) %>">
|
||||
<img class="icon-download" src="css/img/download-24.png" alt="Download" title="Download" />
|
||||
</a>
|
||||
<a class="delete-file" data-filename="<%= files[i].getName() %>">
|
||||
<img class="icon-delete" src="css/img/delete-24.png" alt="Delete" title="Delete" />
|
||||
</a>
|
||||
</td>
|
||||
|
||||
<td class="contentCells contentCells-icon">
|
||||
<a href="EditorServlet?fileName=<%= URLEncoder.encode(files[i].getName(), "UTF-8") %>&type=desktop&mode=edit" target="_blank">
|
||||
<img src="css/img/desktop-24.png" alt="Open in editor for full size screens" title="Open in editor for full size screens"/>
|
||||
</a>
|
||||
</td>
|
||||
<td class="contentCells contentCells-icon">
|
||||
<a href="EditorServlet?fileName=<%= URLEncoder.encode(files[i].getName(), "UTF-8") %>&type=mobile&mode=edit" target="_blank">
|
||||
<img src="css/img/mobile-24.png" alt="Open in editor for mobile devices" title="Open in editor for mobile devices"/>
|
||||
</a>
|
||||
</td>
|
||||
<td class="contentCells contentCells-icon">
|
||||
<% if (docType.equals("text")) { %>
|
||||
<a href="EditorServlet?fileName=<%= URLEncoder.encode(files[i].getName(), "UTF-8") %>&type=desktop&mode=review" target="_blank">
|
||||
<img src="css/img/review-24.png" alt="Open in editor for review" title="Open in editor for review"/>
|
||||
</a>
|
||||
<% } else if (docType.equals("spreadsheet")) { %>
|
||||
<a href="EditorServlet?fileName=<%= URLEncoder.encode(files[i].getName(), "UTF-8") %>&type=desktop&mode=filter" target="_blank">
|
||||
<img src="css/img/filter-24.png" alt="Open in editor without access to change the filter" title="Open in editor without access to change the filter" />
|
||||
</a>
|
||||
<% } %>
|
||||
</td>
|
||||
<td class="contentCells contentCells-icon">
|
||||
<a href="EditorServlet?fileName=<%= URLEncoder.encode(files[i].getName(), "UTF-8") %>&type=desktop&mode=comment" target="_blank">
|
||||
<img src="css/img/comment-24.png" alt="Open in editor for comment" title="Open in editor for comment"/>
|
||||
</a>
|
||||
</td>
|
||||
<td class="contentCells contentCells-shift contentCells-icon">
|
||||
<% if (docType.equals("text")) { %>
|
||||
<a href="EditorServlet?fileName=<%= URLEncoder.encode(files[i].getName(), "UTF-8") %>&type=desktop&mode=fillForms" target="_blank">
|
||||
<img src="css/img/fill-forms-24.png" alt="Open in editor for filling in forms" title="Open in editor for filling in forms"/>
|
||||
</a>
|
||||
<% } %>
|
||||
</td>
|
||||
|
||||
<td class="contentCells contentCells-icon">
|
||||
<a href="EditorServlet?fileName=<%= URLEncoder.encode(files[i].getName(), "UTF-8") %>&type=desktop&mode=view" target="_blank">
|
||||
<img src="css/img/desktop-24.png" alt="Open in viewer for full size screens" title="Open in viewer for full size screens"/>
|
||||
</a>
|
||||
</td>
|
||||
<td class="contentCells contentCells-icon">
|
||||
<a href="EditorServlet?fileName=<%= URLEncoder.encode(files[i].getName(), "UTF-8") %>&type=mobile&mode=view" target="_blank">
|
||||
<img src="css/img/mobile-24.png" alt="Open in viewer for mobile devices" title="Open in viewer for mobile devices"/>
|
||||
</a>
|
||||
</td>
|
||||
<td class="contentCells contentCells-icon">
|
||||
<a href="EditorServlet?fileName=<%= URLEncoder.encode(files[i].getName(), "UTF-8") %>&type=embedded&mode=embedded" target="_blank">
|
||||
<img src="css/img/embeded-24.png" alt="Open in embedded mode" title="Open in embedded mode"/>
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
<% } %>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<% } %>
|
||||
|
||||
<br />
|
||||
<br />
|
||||
|
||||
@ -230,6 +230,21 @@ if (typeof jQuery !== "undefined") {
|
||||
}
|
||||
});
|
||||
|
||||
jq(document).on("click", ".delete-file", function () {
|
||||
var requestAddress = "IndexServlet"
|
||||
+ "?type=remove"
|
||||
+ "&filename=" + encodeURIComponent(jq(this).attr("data-filename"));
|
||||
|
||||
jq.ajax({
|
||||
async: true,
|
||||
contentType: "text/xml",
|
||||
url: requestAddress,
|
||||
complete: function (data) {
|
||||
document.location.reload();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
jq.dropdownToggle({
|
||||
switcherSelector: ".question",
|
||||
dropdownID: "hint"
|
||||
|
||||