แสดงบทความที่มีป้ายกำกับ dojo แสดงบทความทั้งหมด
แสดงบทความที่มีป้ายกำกับ dojo แสดงบทความทั้งหมด

วันพฤหัสบดีที่ 19 สิงหาคม พ.ศ. 2553

การสร้าง List โดยใช้ Dojo

ในการสร้างฟอร์มเพื่อช่วยคัดกรองรายงานในโมดูล report ของ imas จะมีขั้นตอนดังบทความ การเพิ่ม filter ในการแสดงรายงานโดยใช้ dojo และ การทำ lookup ให้กับการเลือกดูฟอร์ม โดยใช้ dojo ดังนั้น ในบทความนี้จะแสดงเฉพาะในส่วนของการสร้าง List โดยใช้ Dojo มีขั้นตอนดังนี้

1. ใน form ทำการสร้าง drop down list ดังนี้

<select id="ProductTypeInventory" name="ProductTypeInventory" dojoType="dijit.form.ComboBox" autocomplete="false" >
                        <option value="">${uiLabelMap.CommonSelect}</option>
                            <#list productTypeList as productTypeListMap>
                                <option value="${productTypeListMap.productTypeId}">${productTypeListMap.description}</option>
                             </#list>
</select>

2. สร้าง screen ดังนี้

<screen name="ProductSummaryDialog">
        <section>
            <actions>
                <property-map resource="iMAS-ReportUiLabels" map-name="uiLabelMap" global="true"/>
                <property-map resource="iMAS-AccountingUiLabels" map-name="uiLabelMap" global="true"/>
                <property-map resource="CommonUiLabels" map-name="uiLabelMap" global="true"/>
                <property-map resource="iMAS-InventoryUiLabels" map-name="uiLabelMap" global="true"/>
                <set field="headerItem" value="ProductSummaryDialog"/>
                <entity-condition list="productTypeList" entity-name="ProductType">
                </entity-condition>
            </actions>
            <widgets>
                    <platform-specific>
                        <html>
                            <html-template location="component://imas-report/webapp/imas-report/report/inventory/page/ProductSummaryDialog.ftl"/>
                        </html>
                    </platform-specific>
            </widgets>
        </section>
    </screen>

อธิบายโค้ด
กำหนดว่าจะดึงข้อมูลจาก entity ไหน โดยใช้คำสั่ง
<entity-condition list="productTypeList" entity-name="ProductType"></entity-condition>
จากตัวอย่าง จะเป็นการเลือกข้อมูลจาก entity ชื่อ ProductType

จะได้ฟอร์มที่สามารถเลือกข้อมูลจาก drop down list ของ ProductType ได้ดังนี้


การทำ lookup ให้กับการเลือกดูฟอร์ม โดยใช้ dojo

จากบทความ การเพิ่ม filter ในการแสดงรายงานโดยใช้ dojo ก่อนหน้านี้ ได้พูดถึงการอำนวยความสะดวกให้แก่ผู้ใช้งานโปรแกรม โดยการใช้ calendar ของ dojo ในการเลือกวันที่ ส่วนในบทความนี้จะพูดถึงการใช้ dojo ดึงเอา Lookup ของ OFBiz มาแสดงเป็น popup แบบ ajax ที่มีลักษณะดังรูป


มีขั้นตอนดังนี้

1. เพิ่มฟิลด์ที่ลงในไฟล์ ARAccruedInvoiceDialog.ftl ดังนี้

<input name="partyIdFrom" size="25" id="findCommEvents_partyIdFrom" type="text">
            <a href="javascript:call_fieldlookup2(document.ARCardForm.partyIdFrom,'LookupPartyName');">
                <img src="/images/fieldlookup.gif" alt="Lookup" border="0" height="14" width="15">
            </a>

อธิบายโค้ด
สร้าง input ชนิด textbox เพิ่มเข้าไปในฟอร์ม และสร้าง link โดยเรียกใช้ function ของ java script ชื่อ call_fieldlookup2 ซึ่งต้องส่ง parameter ดังนี้

call_fieldlookup2(target, viewName)

2. ทำการ include controller ของ module ที่มี lookup เข้าไปใน controller ของ component ที่ทำงานอยู่ เช่น จะเรียกใช้ lookup ที่มีการเรียก party id ใน component report ต้องทำการ include controller ของ party มา ดังนี้

<include location="component://imas-partymgr/webapp/partymgr/WEB-INF/controller.xml"/>

ผลที่ได้ จะสามารถใช้งาน lookup ได้

วันพุธที่ 18 สิงหาคม พ.ศ. 2553

การเพิ่ม filter ในการแสดงรายงานโดยใช้ dojo

โดยปกติการเรียกดู report ของ OFBiz จะมีข้อมูลที่จะต้องแสดงในปริมาณมาก จึงควรมีส่วนที่ให้ผู้ใช้งานสามารถสามารถเลือกดูได้ว่า จะดู report ของส่วนไหน และช่วงเวลาไหน

เพื่อให้ง่ายต่อการใช้งานของผู้ใช้ Imas จึงเลือกที่จะนำเอา Dojo มาสร้าง User Interface ซึ่งจะได้ form ในรูปแบบนี้


จาก form นี้ ผู้ใช้งานสามารถเลือกดู report ได้ว่า ต้องการช่วงไหนบ้าง

การนำเอา dojo มาช่วยใน user interface ในส่วนของ form มีขั้นตอนดังนี้

1. ค้นหารายงานที่ต้องการสร้าง dojo ui เช่น ในส่วนของ Payable - Recievable (เจ้าหนี้-ลูกหนี้) ต้องการสร้าง form แบบ calendar เพื่อให้ผู้ใช้สามารถเลือกช่วงเวลาที่ต้องการแสดงรายงานได้ โดย list ของรายงานเจ้าหนี้-ลูกหนี้ แสดงตาม url นี้
https://localhost:8443/imas-report/control/fourth

2. สร้าง form ของ calendar โดยการสร้างไฟล์ชื่อ ARAccruedInvoiceDialog.ftl ลงในโฟลเดอร์ ofbiz.9.04/hot-deploy/imas-report/webapp/imas-report/report/receivable/page ดังนี้

<form id="ARAccruedInvoiceForm" name="ARAccruedInvoiceForm" dojoType="dijit.form.Form" target="_blank" action="/imas-report/control/ARAccruedInvoice?externalLoginKey=${externalLoginKey}" method="POST">
    <table cellspacing="0">
      <tr>
        <td>${uiLabelMap.CommonFromDate}:</td>
        <td>
            <input id="ARAccruedInvoicefromDate" type="text" name="fromDate" dojoType="dijit.form.DateTextBox" constraints={datePattern:'dd-MM-yyyy'}
            onChange="dijit.byId('ARAccruedInvoicetoDate').constraints.min = arguments[0];"
            />
        </td>
        <td>${uiLabelMap.CommonThruDate}</td>
        <td>
            <input id="ARAccruedInvoicetoDate" type="text" name="toDate" dojoType="dijit.form.DateTextBox" constraints={datePattern:'dd-MM-yyyy'}
            onChange="dijit.byId('ARAccruedInvoicefromDate').constraints.max = arguments[0];"
            />
        </td>
      </tr>
      <tr>
      <td colspan="3">&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td colspan="3">
            <div align="center">
                <button id="ARAccruedInvoicesubmit" name="ARAccruedInvoicesubmitButton" dojoType="dijit.form.Button" type="submit" iconClass="dijitEditorIcon dijitEditorIconSave" onClick="dijit.byId('ARAccruedInvoiceDialog').hide();">${uiLabelMap.CommonSubmit}</button>
                <button id="ARAccruedInvoicecancel" name="cancelButton" dojoType="dijit.form.Button" type="button" iconClass="dijitEditorIcon dijitEditorIconCancel" onClick="javascript:dijit.byId('ARAccruedInvoiceDialog').hide();">${uiLabelMap.CommonCancelled}</button>
            </div>
        </td>
     </tr>
    </table>
</form>

อธิบายโค้ด
ไฟล์ ARAccruedInvoiceDialog.ftl นี้จะสร้างฟอร์มที่มี id = ARAccruedInvoiceForm และ name = ARAccruedInvoiceForm และมี action ไปที่ uri-map ชื่อ ARAccruedInvoice

ทำการสร้าง text field ที่มี id = ARAccruedInvoicefromDate โดยมี dojoType="dijit.form.DateTextBox" เพราะต้องการแสดงผลเป็น calendar ให้ผู้ใช้เลือกวันที่ได้ โดยกำหนด datePattern เป็น dd-MM-yyyy และส่งค่าที่เลือกนี้ไปกับ form

ทำการสร้าง text field ที่มี id = ARAccruedInvoicetoDate โดยมี dojoType="dijit.form.DateTextBox" เพราะต้องการแสดงผลเป็น calendar ให้ผู้ใช้เลือกวันที่ได้ โดยกำหนด datePattern เป็น dd-MM-yyyy และส่งค่าที่เลือกนี้ไปกับ form เช่นกัน

สร้างปุ่มที่มี id="ARAccruedInvoicesubmit" และ name="ARAccruedInvoicesubmitButton" เมื่อมีการกดปุ่มนี้ จะทำการซ่อน form ที่มี id = ARAccruedInvoiceDialog ในไฟล์ iMAS-ReportScreens.xml

สร้างปุ่มที่มี id="ARAccruedInvoicecancel" และ name="cancelButton" เมื่อมีการกดปุ่มนี้ จะทำการซ่อน form ที่มี id = ARAccruedInvoiceDialog ในไฟล์ iMAS-ReportScreens.xml

3. ที่ controller สร้าง request-map และ view-map ดังนี้
<request-map uri="ARAccruedInvoiceDialog"><security https="true" auth="true"/><response name="success" type="view" value="ARAccruedInvoiceDialog"/></request-map>
<view-map name="ARAccruedInvoiceDialog" type="screen" page="component://imas-report/widget/iMAS-ReportScreens.xml#ARAccruedInvoiceDialog"/>

อธิบายโค้ด
 สร้าง request-map ชื่อ ARAccruedInvoiceDialog ที่มีการเรียกใช้ view-map ชื่อ ARAccruedInvoiceDialog ที่มีการเรียกใช้ screen ชื่อ ARAccruedInvoiceDialog ในไฟล์ imas-report/widget/iMAS-ReportScreens.xml มาแสดงผล

4. ที่ imas-report/widget/iMAS-ReportScreens.xml สร้าง screen ชื่อ ARAccruedInvoiceDialog ดังนี้
<screen name="ARAccruedInvoiceDialog">
        <section>
            <actions>
                <property-map resource="iMAS-ReportUiLabels" map-name="uiLabelMap" global="true"/>
                <property-map resource="iMAS-PurchaseUiLabels" map-name="uiLabelMap" global="true"/>
                <property-map resource="CommonUiLabels" map-name="uiLabelMap" global="true"/>
                <set field="headerItem" value="ARAccruedInvoiceDialog"/>
            </actions>
            <widgets>
                    <platform-specific>
                        <html>
                            <html-template location="component://imas-report/webapp/imas-report/report/receivable/page/ARAccruedInvoiceDialog.ftl"/>
                        </html>
                    </platform-specific>
            </widgets>
        </section>
    </screen>
</screens>

อธิบายโค้ด
สร้าง screen ชื่อ ARAccruedInvoiceDialog ที่ทำการ include ไฟล์ ftl ชื่อ ARAccruedInvoiceDialog.ftl มาแสดงผล

5. แก้ไข link ที่ fourth.ftl เพื่อให้เรียกใช้ screen ชื่อ ARAccruedInvoiceForm ได้
<div class="browsecategorytext"><a href="#" id="ARAccruedInvoiceButton" onclick="javascript:dijit.byId('ARAccruedInvoiceDialog').show();">${uiLabelMap.ARAccruedInvoice} FF</button></div>
<div dojoType="dijit.Dialog" id="ARAccruedInvoiceDialog"  title="${uiLabelMap.ARAccruedInvoice}" href="/imas-report/control/ARAccruedInvoiceDialog?formTarget=ARAccruedInvoice&amp;dialogName=ARAccruedInvoiceDialog" ></div>

อธิบายโค้ด
เมื่อมีการกดลิ้ง จะมีการเรียก ARAccruedInvoiceDialog มาแสดงผล

ในบทความต่อไปจะพูดถึงเรื่องการทำ lookup ให้กับการเลือกดูฟอร์ม โดยใช้ dojo

วันอาทิตย์ที่ 4 กรกฎาคม พ.ศ. 2553

การเพิ่ม confirm dialog box ใน form ของ OFBiz 9.04

ใน OFBiz 10.04 การทำ Confirm Dialog Box สามารถใช้ confirmation-message ใน button ได้โดยตรง ดังนี้

<field name="searchButton" title="Search" widget-style="smallSubmit"><submit button-type="button" confirmation-message="Test"/></field>

แต่ใน OFBiz 9.04 ไม่สามารถใช้ confirmation-message ได้ จึงได้ทำการทดลองหาวิธีต่างๆ มาใช้ ดังนี้

ทดลองสร้าง javascript แล้วนำไปใช้กับ onClick ของปุ่มของฟอร์มใน OFBiz ดังนี้
<input type="submit" name="Submit" value="Submit" onClick="fncSubmit()" />

พบว่าไม่สามารถทำได้ เนื่องจาก OFBiz จะทำการ generate แท็ก onSubmit ให้โดยอัติโนมัติดังนี้

onSubmit="javascript:submitFormDisableSubmits(this)"

เมื่อเขียน javascript ที่ปุ่ม submit ของ form ทำให้เกิดการ submit ไปยัง target ของ form ถึงแม้ว่าจะเป็นการกดปุ่ม cancel

ได้รับคำแนะนำจากพี่แซนด์ให้ทำการสร้างปุ่มของฟอร์มในไฟล์ ftl แล้ว include เข้ามาใช้แทนปุ่มของ form โดยตรง จึงได้ทำการสร้างไฟล์ดังนี้

1. สร้างไฟล์ submitButton.ftl โดยมีรายละเอียดดังนี้ (ใช้ dojo มาช่วยในการเขียน javascript ศึกษาเพิ่มเติมได้จาก http://www.dojotoolkit.org/)

<button dojoType="dijit.form.Button" id="btn">Submit
    <script type="dojo/method" event="onClick">showDlg1("FindProject")</script>
</button>

2. ทำการ comment ปุ่มของ form เดิม เพื่อไม่ให้ปุ่มเดิมสามารถทำงานได้
3. เขียนฟังก์ชั่น javascript ในไฟล์ชื่อ testDialog.js ดังนี้

dojo.addOnLoad(function(){
 dojo.parser.parse();
});

function removeThis(){
 this.destroyRecursive()
}

function showDlg1(formIdName){
 var d = new dijit.Dialog({id:'dlg',title:'Dojo Dialogs',content: "<h2>Do you need to do this thing ?</h2>" +
        "<button dojoType='dijit.form.Button' type='submit' id='buttonalertyes' iconClass='mailIconOk' onClick='document." + formIdName + ".submit()'>Yes</button><button dojoType='dijit.form.Button' type='submit' id='buttonalertno' iconClass='mailIconCancel'>No</button>",onExecute:removeThis,onCancel:removeThis});
 d.show()
}

4. ที่ form ทำการ include ไฟล์ submitButton.ftl เข้าไปดังนี้
<platform-specific>
    <html><html-template location="component://imas-project/webapp/imas-project/project/submitButton.ftl"/></html>
</platform-specific>

5. ทำการเพิ่มไฟล์ testDialog.js ใน framework/common/widget/CommonScreens.xml เพื่อให้ทุกเพจสามารถเรียกใช้ไฟล์ javscript นี้ได้ ดังนี้
<set field="layoutSettings.javaScripts[+0]" value="/dojotoolkit/imas/testDialog.js" global="true"/>

6.เมื่อทดลองกดปุ่ม จะแสดง dialog box ดังนี้