Search in sources :

Example 6 with HtmlWriter

use of cn.cerc.jpage.core.HtmlWriter in project summer-mis by cn-cerc.

the class AbstractJspPage method getScriptHtml.

// 返回所有的脚本,供jsp中使用 ${jspPage.script}调用
public final HtmlWriter getScriptHtml() {
    HtmlWriter html = new HtmlWriter();
    // 加入脚本文件
    for (String file : getScriptFiles()) {
        html.println("<script src=\"%s?v=%s\"></script>", file, browserCacheVersion);
    }
    // 加入脚本代码
    List<HtmlContent> scriptCode1 = getScriptCodes();
    if (scriptFunctions.size() > 0 || scriptCode1.size() > 0) {
        html.println("<script>");
        // 输出自定义的函数
        for (HtmlContent func : scriptFunctions) {
            func.output(html);
        }
        // 输出立即执行的代码
        if (scriptCode1.size() > 0) {
            html.println("$(function(){");
            for (HtmlContent func : scriptCodes) {
                func.output(html);
            }
            html.println("});");
        }
        html.println("</script>");
    }
    return html;
}
Also used : HtmlContent(cn.cerc.jpage.core.HtmlContent) HtmlWriter(cn.cerc.jpage.core.HtmlWriter)

Example 7 with HtmlWriter

use of cn.cerc.jpage.core.HtmlWriter in project summer-mis by cn-cerc.

the class UIComponent method toString.

@Override
public final String toString() {
    HtmlWriter html = new HtmlWriter();
    output(html);
    return html.toString();
}
Also used : HtmlWriter(cn.cerc.jpage.core.HtmlWriter)

Example 8 with HtmlWriter

use of cn.cerc.jpage.core.HtmlWriter in project summer-mis by cn-cerc.

the class StringField method format.

@Override
public String format(Object value) {
    if (!(value instanceof Record))
        return value.toString();
    Record ds = (Record) value;
    String data = getDefaultText(ds);
    if (this.isReadonly()) {
        if (buildUrl != null) {
            HtmlWriter html = new HtmlWriter();
            UrlRecord url = new UrlRecord();
            buildUrl.buildUrl(ds, url);
            if (!"".equals(url.getUrl())) {
                html.print("<a href=\"%s\"", url.getUrl());
                if (url.getTitle() != null) {
                    html.print(" title=\"%s\"", url.getTitle());
                }
                if (url.getTarget() != null) {
                    html.print(" target=\"%s\"", url.getTarget());
                }
                html.println(">%s</a>", data);
            } else
                html.println(data);
            return html.toString();
        } else
            return data;
    }
    if (!(this.getOwner() instanceof AbstractGridLine))
        return data;
    return getEditor().format(ds);
}
Also used : HtmlWriter(cn.cerc.jpage.core.HtmlWriter) Record(cn.cerc.jdb.core.Record) UrlRecord(cn.cerc.jpage.core.UrlRecord) UrlRecord(cn.cerc.jpage.core.UrlRecord) AbstractGridLine(cn.cerc.jpage.grid.lines.AbstractGridLine)

Example 9 with HtmlWriter

use of cn.cerc.jpage.core.HtmlWriter in project summer-mis by cn-cerc.

the class ColumnEditor method format.

public String format(Record ds) {
    String data = ds.getString(owner.getField());
    if (owner.getBuildText() != null) {
        HtmlWriter html = new HtmlWriter();
        owner.getBuildText().outputText(ds, html);
        data = html.toString();
    } else if (ds.getField(owner.getField()) instanceof Double) {
        DecimalFormat df = new DecimalFormat("0.####");
        data = df.format(ds.getDouble(owner.getField()));
    }
    if (!this.init) {
        dataSet = gridLine.getDataSet();
        columns = new ArrayList<>();
        for (IField field : gridLine.getFields()) {
            if (field instanceof IColumn) {
                if (((AbstractField) field).isReadonly())
                    continue;
                if (field.getWidth() == 0)
                    continue;
                columns.add(field);
            }
        }
        if (gridLine.getOwner() instanceof DataGrid) {
            DataGrid grid = (DataGrid) gridLine.getOwner();
            if (columns.size() > 0 && grid.getPrimaryKey() == null)
                throw new RuntimeException("BaseGrid.primaryKey is null");
        }
        this.init = true;
    }
    HtmlWriter html = new HtmlWriter();
    String inputStyle = "";
    html.print("<input");
    if (gridLine instanceof MasterGridLine)
        html.print(" id='%s'", this.getDataId());
    else {
        if (owner.getId() != null)
            html.print(" id='%s'", owner.getId());
        inputStyle = "width:80%;";
    }
    inputStyle += "border: 1px solid #dcdcdc;";
    html.print(" type='text'");
    html.print(" name='%s'", owner.getField());
    html.print(" value='%s'", data);
    html.print(" autocomplete='off'");
    html.print(" data-%s='[%s]'", owner.getField(), data);
    if (gridLine instanceof MasterGridLine) {
        html.print(" data-focus='[%s]'", this.getDataFocus());
        if (owner.getAlign() != null)
            inputStyle += String.format("text-align:%s;", owner.getAlign());
        if (owner.getOnclick() != null) {
            html.print(" onclick=\"%s\"", owner.getOnclick());
        } else
            html.print(" onclick='this.select()'");
    }
    if (!"".equals(inputStyle))
        html.print(" style='%s'", inputStyle);
    html.print(" onkeydown='return tableDirection(event,this)'");
    if (dataField.size() > 0) {
        for (String field : dataField) {
            html.print(" data-%s='%s'", field, ds.getString(field));
        }
    }
    if (onUpdate != null)
        html.print(" oninput=\"tableOnChanged(this,'%s')\"", onUpdate);
    else
        html.print(" oninput='tableOnChanged(this)'");
    html.println("/>");
    return html.toString();
}
Also used : AbstractField(cn.cerc.jpage.fields.AbstractField) MasterGridLine(cn.cerc.jpage.grid.lines.MasterGridLine) IColumn(cn.cerc.jpage.core.IColumn) HtmlWriter(cn.cerc.jpage.core.HtmlWriter) DecimalFormat(java.text.DecimalFormat) DataGrid(cn.cerc.jpage.grid.DataGrid) IField(cn.cerc.jpage.core.IField)

Example 10 with HtmlWriter

use of cn.cerc.jpage.core.HtmlWriter in project summer-mis by cn-cerc.

the class AbstractField method getDefaultText.

/**
 * @param rs
 *            当前记录集
 * @return 返回输出文本
 */
protected String getDefaultText(Record rs) {
    if (rs == null)
        return null;
    if (buildText != null) {
        HtmlWriter html = new HtmlWriter();
        buildText.outputText(rs, html);
        return html.toString();
    }
    return rs.getString(getField());
}
Also used : HtmlWriter(cn.cerc.jpage.core.HtmlWriter)

Aggregations

HtmlWriter (cn.cerc.jpage.core.HtmlWriter)18 Record (cn.cerc.jdb.core.Record)2 UrlRecord (cn.cerc.jpage.core.UrlRecord)2 AbstractGridLine (cn.cerc.jpage.grid.lines.AbstractGridLine)2 DecimalFormat (java.text.DecimalFormat)2 HtmlContent (cn.cerc.jpage.core.HtmlContent)1 IColumn (cn.cerc.jpage.core.IColumn)1 IField (cn.cerc.jpage.core.IField)1 AbstractField (cn.cerc.jpage.fields.AbstractField)1 DataGrid (cn.cerc.jpage.grid.DataGrid)1 MasterGridLine (cn.cerc.jpage.grid.lines.MasterGridLine)1