use of web.HTMLWriter in project common by zenlunatics.
the class FileColumn method writeLink.
// --------------------------------------------------------------------------
public static void writeLink(String text, String url, String print_url, String id, Request request) throws IOException {
HTMLWriter writer = request.writer;
if (Util.fileIsViewable(url)) {
StringBuilder on_click = new StringBuilder("new Dialog({url:'");
on_click.append(HTMLWriter.escapeJSString(url));
on_click.append("',title:'");
on_click.append(HTMLWriter.escapeJSString(text));
if (print_url != null) {
on_click.append(" <button onclick="window.open(context+\\\'");
on_click.append(print_url);
on_click.append(id);
on_click.append("\\\',\\\'\\\',\\\'\\\');return false;" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-print" style="padding-bottom:2px"></span></button>");
}
on_click.append("'})");
writer.aOnClick(text, on_click.toString());
} else {
String img;
String lc = url.toLowerCase();
if (lc.endsWith(".gif") || lc.endsWith(".jpg") || lc.endsWith(".jpeg") || lc.endsWith(".png")) {
img = "document-image.png";
writer.setAttribute("target", "_blank");
} else if (lc.endsWith(".pdf")) {
img = "document-pdf.png";
writer.setAttribute("target", "_blank");
} else {
if (lc.endsWith("doc") || lc.endsWith(".docx") || lc.endsWith(".dot"))
img = "document-word.png";
else if (lc.endsWith(".ods"))
img = "document-table.png";
else if (lc.endsWith(".odt") || lc.endsWith(".pages"))
img = "document-text-image.png";
else if (lc.endsWith(".odp") || lc.endsWith(".ppt") || lc.endsWith(".pptx"))
img = "document-powerpoint.png";
else if (lc.endsWith(".xls") || lc.endsWith(".xlsx"))
img = "document-excel.png";
else
img = "document.png";
writer.setAttribute("title", "download");
}
writer.a(text + " <img src=\"" + request.getContext() + "/images/" + img + "\" style=\"vertical-align:baseline;\" />", url);
}
}
use of web.HTMLWriter in project common by zenlunatics.
the class FileColumn method writeActionSelect.
// --------------------------------------------------------------------------
private void writeActionSelect(ViewDef view_def, Mode mode, String dir, Request request) throws IOException {
List<String> actions = new ArrayList<String>();
HTMLWriter writer = request.writer;
if (m_allow_editing)
actions.add("create a new file");
actions.add("upload a file");
if (m_allow_choosing || request.userIsAdministrator())
actions.add("select a file on the server");
new web.Select("db_actions", actions).setOnChange("this.fcs.change()").write(request);
writer.scriptOpen();
writer.write("var e=$('db_actions');e.fcs=new FileColumnSelect(e,'");
writer.write(view_def.getName());
writer.write("','");
writer.write(m_name);
writer.write("',{");
boolean has_options = false;
if (view_def.useDialogFor(mode)) {
writer.write("in_dialog:true");
has_options = true;
}
if (dir != null) {
if (has_options)
writer.write(',');
writer.write("dir_column:'");
writer.write(m_dir_column);
writer.write("',dir:'");
writer.write(dir);
writer.write('\'');
}
writer.write("});e.fcs.change();");
writer.scriptClose();
}
use of web.HTMLWriter in project common by zenlunatics.
the class FileColumn method checkFilesInDatabase.
// --------------------------------------------------------------------------
@AdminTask({ "table", "column", "show only problems" })
public static void checkFilesInDatabase(String table, String column, boolean show_only_problems, Request request) {
HTMLWriter writer = request.writer;
try {
FileColumn file_column = (FileColumn) request.site.getViewDef(table, request.db).getColumn(column);
String dir_column = file_column.getDirColumn();
StringBuilder sql = new StringBuilder("SELECT ").append(column);
if (dir_column != null)
sql.append(',').append(dir_column);
sql.append(" FROM ").append(table).append(" ORDER BY ");
if (dir_column != null)
sql.append(dir_column).append(',');
sql.append(column);
ResultSet rs = request.db.select(sql.toString());
writer.write("<table class=\"table table-condensed table-bordered\" style=\"width:auto;\"><tr><th>filename</th>");
if (dir_column != null)
writer.write("<th>dir column</th>");
writer.write("<th>status</th></tr>");
while (rs.next()) {
String dir_column_value = null;
String filename = rs.getString(1);
String problem = null;
if (filename == null)
problem = column + " is null";
else {
if (dir_column != null)
dir_column_value = rs.getString(2);
FilePathStringBuilder file_path = file_column.getDirectory(dir_column_value, request.site);
file_path.append(filename);
if (!new File(file_path.toString()).exists())
problem = "missing";
}
if (problem != null || !show_only_problems) {
writer.write("<tr><td>");
if (filename != null)
writer.write(filename);
if (dir_column != null) {
writer.write("</td><td>");
if (dir_column_value != null)
writer.write(dir_column_value);
}
writer.write("</td><td>").write(problem == null ? "ok" : problem).write("</td></tr>");
}
}
writer.write("</table>");
rs.getStatement().close();
} catch (SQLException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of web.HTMLWriter in project common by zenlunatics.
the class FileColumn method writeInput.
// --------------------------------------------------------------------------
@Override
public void writeInput(String default_value, boolean printer_friendly, View view, Form form, Request request) throws IOException {
View.Mode mode = view.getMode();
String dir_column_value = getDirColumnValue(view, mode);
HTMLWriter writer = request.writer;
writer.write("<span>");
String filename = null;
if (mode != View.Mode.ADD_FORM)
filename = view.data().getString(m_name);
if (mode == View.Mode.ADD_FORM || filename.length() == 0)
if (m_allow_choosing || m_allow_editing) {
writer.write("action: ");
writeActionSelect(view.getViewDef(), mode, dir_column_value, request);
writer.write("<div style=\"height:5px;\"></div>");
} else {
if (m_is_required) {
writer.setAttribute("required", "yes");
writer.setAttribute("title", getDisplayName(false));
}
writer.fileInput(m_name);
}
else if (mode == View.Mode.EDIT_FORM && Util.fileIsViewable(filename)) {
writer.hiddenInput(m_name, filename);
if (m_dir_column != null)
writer.hiddenInput(m_dir_column, dir_column_value);
writer.setAttribute("id", "db_" + m_name + "_text");
writer.textAreaOpen("db_" + m_name + "_text", "5", "80");
List<String> a = Util.readFile(getDirectory(dir_column_value, request.site).toString() + "/" + filename);
for (int i = 0; i < a.size(); i++) {
if (i > 0)
writer.write('\n');
writer.write(WriterBase.encode(a.get(i)));
}
writer.tagClose();
writer.js("rich_text('db_" + m_name + "_text');");
} else if (view.getMode() == View.Mode.EDIT_FORM) {
view.writeColumnHTML(m_name);
writeReplaceLink(view, this, mode, writer);
if (m_dir_column != null && mode == View.Mode.EDIT_FORM)
writer.hiddenInput(m_dir_column, dir_column_value);
}
if (m_post_text != null) {
writer.space();
writer.write(m_post_text);
}
writer.write("</span>");
}
use of web.HTMLWriter in project common by zenlunatics.
the class TextAreaColumn method writeInput.
// --------------------------------------------------------------------------
@Override
protected void writeInput(Mode mode, String default_value, View view, Form form, Request request) throws IOException {
String value;
HTMLWriter writer = request.writer;
value = getValue(request.db.getTable(view.getViewDef().getFrom()).getColumn(m_name), default_value, view, request);
if (m_encryption_column != null && mode == View.Mode.EDIT_FORM)
value = Util.scramble(value, view.data().getInt(m_encryption_column));
if (m_rows == 1)
writer.textInput(m_name, Integer.toString(m_cols), getValue(request.db.getTable(view.getViewDef().getFrom()).getColumn(m_name), default_value, view, request));
else if (m_is_expanding)
writer.textAreaExpanding(m_name, m_style, value);
else {
writeTextArea(m_name, value, m_cols, m_rows, view, writer);
if (m_is_rich_text)
writer.js("rich_text('" + m_name + "');");
}
}
Aggregations