Search in sources :

Example 51 with HTMLWriter

use of web.HTMLWriter in project common by zenlunatics.

the class News method writeStatusForm.

// --------------------------------------------------------------------------
public void writeStatusForm(Request request) throws IOException {
    HTMLWriter writer = request.writer;
    writer.write("<div class=\"status\">");
    writer.setAttribute("placeholder", "What's on your mind?");
    writer.setAttribute("rows", "2");
    writer.textAreaExpanding("status", "width:100%", null, false);
    writer.scriptOpen();
    writer.jsFunction("post_status", null, "var t=$('status').value;" + "if(t)" + "XHR_post(context+'/NewsFeed/add','text='+encodeURIComponent(t),function(){" + "var s=$('status');" + "s.value='';" + "s.getPrevious().getFirst().set('text','');" + "fetch_new();" + "});");
    writer.scriptClose();
    writer.write("<div class=\"post\"><table style=\"background-color:inherit;width:100%;\"><tr><td>");
    for (NewsProvider provider : m_providers.values()) provider.writeAddButton(request);
    writer.write("</td><td style=\"text-align:right;\"><button class=\"btn btn-primary btn-sm\" onclick=\"post_status()\">Post</button></td></tr></table></div></div>");
}
Also used : HTMLWriter(web.HTMLWriter)

Example 52 with HTMLWriter

use of web.HTMLWriter in project common by zenlunatics.

the class News method writeItems.

// --------------------------------------------------------------------------
public void writeItems(String where, Request request) throws IOException {
    HTMLWriter writer = request.writer;
    // String sql = "SELECT DISTINCT provider FROM news";
    // if (where != null)
    // sql += " WHERE " + where;
    // List<String> providers = request.db.readValues(sql);
    // new Select("providers").setOptions(providers).write(request);
    // sql = "SELECT DISTINCT _owner_ FROM news";
    // if (where != null)
    // sql += " WHERE " + where;
    // ResultSet rs = request.db.select("SELECT id,first,last FROM people WHERE id IN(" + sql + ")");
    // try {
    // rs.getStatement().close();
    // } catch (SQLException e) {
    // throw new RuntimeException(e);
    // }
    writer.write("<div id=\"news_items\" class=\"news_items\">");
    if (where != null)
        request.setSessionAttribute("news where", where);
    ResultSet rs = request.db.select(new Select("*").from("news").where(where).orderBy("last_update DESC").limit(20));
    State state = (State) request.getSessionAttribute("news state");
    if (state == null) {
        state = new State();
        request.setSessionAttribute("news state", state);
    } else {
        state.earliest = null;
        state.latest = null;
    }
    writeItems(20, rs, request);
    writer.write("</div>");
    writer.scriptOpen();
    writer.write("var fetching=false;");
    writer.jsFunction("fetch_new", null, "fetching=true;" + "new Request.HTML({evalScripts:false,onSuccess:function(t,e,h,j){" + "var ni=$('news_items');" + "for(var i=t.length-1;i>=0;i--){" + "var item=$(t[i].id);" + "if(item)" + "item.destroy();" + "ni.grab(t[i],'top');" + "}" + "Browser.exec(j);" + "fetching=false;" + "},url:context+'/News/new'}).get();");
    writer.jsFunction("fetch_next", null, "fetching=true;" + "new Request.HTML({evalScripts:false,onSuccess:function(t,e,h,j){" + "var ni=$('news_items');" + "while(t.length>0)" + "ni.grab(t[0]);" + "Browser.exec(j);" + "fetching=false;" + "},url:context+'/News/next'}).get();");
    writer.jsFunction("item_popup", "e,id,ce,cd", "if(!e.firstChild){" + "d=new Dropdown(e);" + "if(ce)" + "d.add('Edit',function(){new Dialog({url:context+'/News/'+id+'/edit',title:'Edit Post',dialog_class:'news_item_dialog',e:e,cancel:'Cancel'});});" + "if(cd)" + "d.add('Delete',function(){" + "dialog_confirm('Delete this post?',function(){XHR_post(context+'/News/'+id+'/delete',null,function(){e.getParent('div.news_item').dispose();});});" + "});" + "d.show();" + "} else " + "e.getFirst().retrieve('object').show();");
    writer.jsFunction("replace_news_item", "id", "var ni=Dialog.top().options.e.getParent('div.news_item');" + "Dialog.top().close();" + "new Request.HTML({evalScripts:false,onSuccess:function(t,e,h,j){" + "t[0].replaces(ni);" + "Browser.exec(j);" + "},url:context+'/News/'+id}).get();");
    writer.write("window.addEvent('domready', function(){" + "document.addEvent('scroll',function(){" + "if(!fetching)" + "if(document.getScroll().y>document.getScrollSize().y-document.getSize().y-10)" + "fetch_next();" + "else if(document.getScroll().y<100)" + "fetch_new();" + "})});");
    Likes.writeJavascriptFunctions(writer);
    writer.scriptClose();
}
Also used : HTMLWriter(web.HTMLWriter) ResultSet(java.sql.ResultSet) Select(db.Select)

Example 53 with HTMLWriter

use of web.HTMLWriter in project common by zenlunatics.

the class AnswerTypeRenderer method writeInput.

// ----------------------------------------------------------------------
@Override
public boolean writeInput(View view, Form form, ColumnBase<?> column, View.Mode mode, String default_value, Request request) throws IOException {
    String answer_type = null;
    String[] parts = null;
    String type_data = null;
    HTMLWriter writer = request.writer;
    if (mode == View.Mode.EDIT_FORM) {
        answer_type = view.data().getString("answer_type");
        type_data = view.data().getString("type_data");
        if (answer_type.equals("Rating"))
            parts = type_data.split("\\|");
    }
    writer.scriptOpen();
    writer.write("append_input=function(e,label,name,size,value){" + "e.appendChild(document.createTextNode(' '+label+' '));" + "var i=document.createElement('input');" + "i.name=name;" + "i.size=size;" + "if(value)" + "i.value=value;" + "i.setAttribute('required','yes');" + "i.setAttribute('title',label);" + "e.appendChild(i);};");
    writer.write("append_radio=function(e,label,name,checked){" + "var i=document.createElement('input');" + "i.name=name;" + "i.value=label;" + "i.type='radio';" + "if(checked)" + "i.checked='checked';" + "e.appendChild(i);" + "e.appendChild(document.createTextNode(' '+label));};");
    writer.write("update_answer_type=function(){" + "var s=$('answer_type');" + "var e=s.nextSibling;" + "if(e)" + "e.parentNode.removeChild(e);" + "if(s.selectedIndex==0){" + "e=document.createElement('div');" + "var ta=new Element('textarea');" + "ta.name='type_data';" + "ta.set('rows',5);" + "ta.set('cols',40);");
    if ("Choices".equals(answer_type)) {
        writer.write("ta.set('html',");
        writer.jsString(type_data.charAt(0) == 'r' ? type_data.substring(5) : type_data.substring(6));
        writer.write(");");
    }
    writer.write("e.appendChild(ta);" + "e.appendChild(document.createElement('br'));" + "e.appendChild(document.createTextNode('type: '));" + "append_radio(e,'radio','type'");
    if (mode == View.Mode.ADD_FORM || "Choices".equals(answer_type) && type_data.charAt(0) == 'r')
        writer.write(",true");
    writer.write(");" + "append_radio(e,'select','type'");
    if ("Choices".equals(answer_type) && type_data.charAt(0) == 's')
        writer.write(",true");
    writer.write(");" + "s.parentNode.appendChild(e);" + "}else if(s.selectedIndex==5){" + "e=document.createElement('span');" + "append_input(e,'from','from',3");
    if ("Rating".equals(answer_type)) {
        writer.write(",'");
        writer.write(parts[0]);
        writer.write("'");
    }
    writer.write(");" + "append_input(e,'to','to',3");
    if ("Rating".equals(answer_type)) {
        writer.write(",'");
        writer.write(parts[1]);
        writer.write("'");
    }
    writer.write(");" + "append_input(e,'from label','from_label',15");
    if ("Rating".equals(answer_type)) {
        writer.write(",'");
        writer.write(parts[2]);
        writer.write("'");
    }
    writer.write(");" + "append_input(e,'to label','to_label',15");
    if ("Rating".equals(answer_type)) {
        writer.write(",'");
        writer.write(parts[3]);
        writer.write("'");
    }
    writer.write(");" + "s.parentNode.appendChild(e);" + "}else if(s.selectedIndex==6){" + "e=document.createElement('span');" + "append_input(e,'size','type_data',3");
    if ("String".equals(answer_type)) {
        writer.write(",'");
        writer.write(type_data);
        writer.write("'");
    }
    writer.write(");" + "s.parentNode.appendChild(e);" + "}" + "var i=s.selectedIndex;" + "$('pre_text_row').style.display=(i==1||i==2||i==4)?'none':'table-row';" + "$('post_text_row').style.display=(i==1||i==2||i==4)?'none':'table-row';" + "$('question_row').style.display=i==1||i==4?'none':'table-row';" + "$('required_row').style.display=(i==1||i==2||i==4)?'none':'table-row';};");
    writer.scriptClose();
    m_select_renderer.writeInput(view, form, column, mode, default_value, request);
    // request.writer.javascript("update_answer_type()");
    return true;
}
Also used : HTMLWriter(web.HTMLWriter)

Example 54 with HTMLWriter

use of web.HTMLWriter in project common by zenlunatics.

the class AnswerTypeRenderer method writeValue.

// ----------------------------------------------------------------------
@Override
public void writeValue(View view, ColumnBase<?> column, Request request) throws IOException {
    String type = view.data().getString("answer_type");
    HTMLWriter writer = request.writer;
    writer.write(type);
    if (type.equals("String")) {
        writer.write('(');
        writer.write(view.data().getString("type_data"));
        writer.write(')');
    }
}
Also used : HTMLWriter(web.HTMLWriter)

Example 55 with HTMLWriter

use of web.HTMLWriter in project common by zenlunatics.

the class Survey method writeQuestion.

// ----------------------------------------------------------------------
public boolean writeQuestion(int question_num, Request request) throws IOException {
    HTMLWriter writer = request.writer;
    try {
        if (m_questions.isBeforeFirst())
            if (!m_questions.next())
                return false;
        while (m_questions.getInt("_order_") < question_num) {
            if (m_number_questions) {
                String type = m_questions.getString("answer_type");
                if (!type.equals("Divider") && !type.equals("HTML") && !type.equals("Page Break"))
                    m_question_num++;
            }
            if (!m_questions.next())
                return false;
        }
        String type = m_questions.getString("answer_type");
        if (type.equals("Divider"))
            writer.hr();
        else if (type.equals("HTML")) {
            writer.write("<p>");
            writer.write(m_questions.getString("question"));
            writer.write("</p>");
        } else if (type.equals("Page Break"))
            return false;
        else {
            writer.setAttribute("id", "q" + question_num);
            writer.tagOpen("p");
            writer.setAttribute("class", "question");
            writer.tagOpen("span");
            if (m_number_questions) {
                writer.write(++m_question_num);
                writer.write(". ");
            }
            String question = m_questions.getString("question");
            if (question != null)
                writer.write(question);
            writer.tagClose();
            if (m_inputs_on_new_line || m_questions.getString("answer_type").equals("Text"))
                writer.br();
            else
                writer.space();
            writer.setAttribute("autocomplete", "off");
            m_form.writeColumnInput("a" + m_questions.getString("id"));
            writer.tagClose();
        }
        return true;
    } catch (SQLException e) {
        throw new RuntimeException(e);
    }
}
Also used : HTMLWriter(web.HTMLWriter) SQLException(java.sql.SQLException)

Aggregations

HTMLWriter (web.HTMLWriter)109 Select (db.Select)18 SQLException (java.sql.SQLException)16 ResultSet (java.sql.ResultSet)14 Table (web.Table)12 JDBCTable (db.JDBCTable)10 Person (app.Person)7 Calendar (java.util.Calendar)7 ArrayList (java.util.ArrayList)6 JDBCColumn (db.JDBCColumn)5 View (db.View)5 DBObject (db.DBObject)4 Form (db.Form)4 File (java.io.File)4 AdminTask (web.AdminTask)4 FilePathStringBuilder (web.FilePathStringBuilder)4 Select (web.Select)4 Mode (db.View.Mode)3 IOException (java.io.IOException)3 NumberFormat (java.text.NumberFormat)3