<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="th">
	<id>http://158.108.32.49/wiki/index.php?action=history&amp;feed=atom&amp;title=Openerp%2Fhistest2</id>
	<title>Openerp/histest2 - ประวัติรุ่นแก้ไข</title>
	<link rel="self" type="application/atom+xml" href="http://158.108.32.49/wiki/index.php?action=history&amp;feed=atom&amp;title=Openerp%2Fhistest2"/>
	<link rel="alternate" type="text/html" href="http://158.108.32.49/wiki/index.php?title=Openerp/histest2&amp;action=history"/>
	<updated>2026-05-02T22:53:10Z</updated>
	<subtitle>ประวัติรุ่นแก้ไขของหน้านี้ในวิกิ</subtitle>
	<generator>MediaWiki 1.33.1</generator>
	<entry>
		<id>http://158.108.32.49/wiki/index.php?title=Openerp/histest2&amp;diff=42709&amp;oldid=prev</id>
		<title>Chaiporn: หน้าที่ถูกสร้างด้วย &#039;== การแยกโค้ด javascript เป็นส่วน ==  &#039;&#039;&#039;ก่อนเริ่ม:&#039;&#039;&#039; ดาวน์โหล...&#039;</title>
		<link rel="alternate" type="text/html" href="http://158.108.32.49/wiki/index.php?title=Openerp/histest2&amp;diff=42709&amp;oldid=prev"/>
		<updated>2014-04-17T08:27:23Z</updated>

		<summary type="html">&lt;p&gt;หน้าที่ถูกสร้างด้วย &amp;#039;== การแยกโค้ด javascript เป็นส่วน ==  &amp;#039;&amp;#039;&amp;#039;ก่อนเริ่ม:&amp;#039;&amp;#039;&amp;#039; ดาวน์โหล...&amp;#039;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;หน้าใหม่&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== การแยกโค้ด javascript เป็นส่วน ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;ก่อนเริ่ม:&amp;#039;&amp;#039;&amp;#039; ดาวน์โหลดโค้ด [http://theory.cpe.ku.ac.th/~jittat/openerp/histest.zip histest.zip] จากครั้งก่อน&lt;br /&gt;
&lt;br /&gt;
=== histest.js ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
openerp.histest = function(instance) {&lt;br /&gt;
&lt;br /&gt;
    openerp.histest.message(instance);&lt;br /&gt;
    openerp.histest.patient(instance);&lt;br /&gt;
    &lt;br /&gt;
    instance.web.client_actions.add(&amp;#039;histest.indexAction&amp;#039;,&lt;br /&gt;
                                    &amp;#039;instance.histest.patient.indexAction&amp;#039;);&lt;br /&gt;
&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== histest_message.js ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
openerp.histest.message = function(instance) {&lt;br /&gt;
&lt;br /&gt;
    instance.histest.message = {};&lt;br /&gt;
    instance.histest.message.popupInterval = null;&lt;br /&gt;
    instance.histest.message.MsgManagerWidget = instance.web.Widget.extend({&lt;br /&gt;
&lt;br /&gt;
        start: function() {&lt;br /&gt;
            var self = this;&lt;br /&gt;
            console.log(&amp;quot;MsgMan started...&amp;quot;);&lt;br /&gt;
            if(instance.histest.message.popupInterval) {&lt;br /&gt;
                clearInterval(instance.histest.message.popupInterval);&lt;br /&gt;
            }&lt;br /&gt;
            instance.histest.message.popupInterval = setInterval(function() {&lt;br /&gt;
                self.popup();&lt;br /&gt;
            },5000);&lt;br /&gt;
            this.shownMsgId = 0;&lt;br /&gt;
            this.fetchNewMessage(this.shownMsgId, function(msgId) {&lt;br /&gt;
                self.shownMsgId = msgId;&lt;br /&gt;
            });&lt;br /&gt;
        },&lt;br /&gt;
&lt;br /&gt;
        fetchNewMessage: function(recentId, callback) {&lt;br /&gt;
            var model = new instance.web.Model(&amp;#039;histest.message&amp;#039;);&lt;br /&gt;
            model.query().filter([[&amp;#039;id&amp;#039;,&amp;#039;&amp;gt;&amp;#039;,recentId]]).all().done(function(results){&lt;br /&gt;
                if (results.length &amp;gt; 0) {&lt;br /&gt;
                    msgId = results[results.length-1].id;&lt;br /&gt;
                    callback(msgId);&lt;br /&gt;
                }&lt;br /&gt;
            });&lt;br /&gt;
        },&lt;br /&gt;
        &lt;br /&gt;
        popup: function() {&lt;br /&gt;
            var self = this;&lt;br /&gt;
            this.fetchNewMessage(this.shownMsgId, function(msgId) {&lt;br /&gt;
                self.do_action({&lt;br /&gt;
                    type: &amp;#039;ir.actions.act_window&amp;#039;,&lt;br /&gt;
                    res_model: &amp;quot;histest.message&amp;quot;,&lt;br /&gt;
                    res_id: msgId,&lt;br /&gt;
                    views: [[false, &amp;#039;form&amp;#039;]],&lt;br /&gt;
                    target: &amp;#039;new&amp;#039;,&lt;br /&gt;
                    context: {},&lt;br /&gt;
                });&lt;br /&gt;
                self.shownMsgId = msgId;&lt;br /&gt;
            });&lt;br /&gt;
        }&lt;br /&gt;
    });&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== histest_patient.js ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
openerp.histest.patient = function(instance) {&lt;br /&gt;
    &lt;br /&gt;
    instance.histest.patient = {};&lt;br /&gt;
    instance.histest.patient.indexAction = instance.web.Widget.extend({&lt;br /&gt;
        template: &amp;#039;histest.index&amp;#039;,&lt;br /&gt;
        events: {&lt;br /&gt;
            &amp;#039;click .oe_histest_patient_new_link&amp;#039;: &amp;#039;linkClick&amp;#039;,&lt;br /&gt;
            &amp;#039;click .oe_histest_patient_query_link&amp;#039;: &amp;#039;patientQuery&amp;#039;,&lt;br /&gt;
        },&lt;br /&gt;
&lt;br /&gt;
        start: function() {&lt;br /&gt;
            var msgManager = new instance.histest.message.MsgManagerWidget(this);&lt;br /&gt;
            msgManager.appendTo(&amp;#039;.oe_application&amp;#039;);&lt;br /&gt;
        },&lt;br /&gt;
&lt;br /&gt;
        patientQuery: function() {&lt;br /&gt;
            var model = new instance.web.Model(&amp;#039;histest.patient&amp;#039;);&lt;br /&gt;
            var self = this;&lt;br /&gt;
            self.$(&amp;quot;.oe_histest_patient_results&amp;quot;).html(&amp;quot;&amp;quot;);&lt;br /&gt;
            model.query().all().done(function(results) {&lt;br /&gt;
                for(var i=0; i &amp;lt; results.length; i++) {&lt;br /&gt;
                    self.$(&amp;quot;.oe_histest_patient_results&amp;quot;)&lt;br /&gt;
                        .append(&amp;#039;&amp;lt;li&amp;gt;&amp;#039; + results[i].first_name + &amp;#039;&amp;lt;/li&amp;gt;&amp;#039;);&lt;br /&gt;
                }&lt;br /&gt;
            });&lt;br /&gt;
        },&lt;br /&gt;
&lt;br /&gt;
        linkClick: function() {&lt;br /&gt;
            this.do_action({&lt;br /&gt;
                type: &amp;#039;ir.actions.act_window&amp;#039;,&lt;br /&gt;
                res_model: &amp;#039;histest.patient&amp;#039;,&lt;br /&gt;
                views: [[false,&amp;#039;form&amp;#039;]],&lt;br /&gt;
                target: &amp;#039;current&amp;#039;,&lt;br /&gt;
                context: {},&lt;br /&gt;
            });&lt;br /&gt;
        }&lt;br /&gt;
    });&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Responsive CSS ==&lt;br /&gt;
&lt;br /&gt;
=== addons/web/static/src/xml/base.xml ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;diff&amp;quot;&amp;gt;&lt;br /&gt;
453c453&lt;br /&gt;
&amp;lt;             &amp;lt;td colspan=&amp;quot;2&amp;quot; class=&amp;quot;oe_topbar&amp;quot;&amp;gt;&lt;br /&gt;
---&lt;br /&gt;
&amp;gt;             &amp;lt;td colspan=&amp;quot;1&amp;quot; class=&amp;quot;oe_topbar&amp;quot;&amp;gt;&lt;br /&gt;
460c460,461&lt;br /&gt;
&amp;lt;             &amp;lt;td class=&amp;quot;oe_leftbar&amp;quot; valign=&amp;quot;top&amp;quot;&amp;gt;&lt;br /&gt;
---&lt;br /&gt;
&amp;gt;           &amp;lt;td&amp;gt;&lt;br /&gt;
&amp;gt;             &amp;lt;div class=&amp;quot;oe_leftbar&amp;quot; style=&amp;quot;float: left;&amp;quot; valign=&amp;quot;top&amp;quot;&amp;gt;&lt;br /&gt;
470,472c471,474&lt;br /&gt;
&amp;lt;             &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;             &amp;lt;td class=&amp;quot;oe_application&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;             &amp;lt;/td&amp;gt;&lt;br /&gt;
---&lt;br /&gt;
&amp;gt;             &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;gt;             &amp;lt;div class=&amp;quot;oe_application&amp;quot; style=&amp;quot;float: left&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt;             &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;gt;           &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== addons/web/controllers/main.py ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;diff&amp;quot;&amp;gt;&lt;br /&gt;
546a547&lt;br /&gt;
&amp;gt;         &amp;lt;meta name=&amp;quot;viewport&amp;quot; content=&amp;quot;width=device-width, minimum-scale=1.0, maximum-scale=1.0&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== histest/static/src/css/histest.css ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;css&amp;quot;&amp;gt;&lt;br /&gt;
.openerp .oe_histest_index {&lt;br /&gt;
    padding: 10px;&lt;br /&gt;
    background: black;&lt;br /&gt;
    color: white;&lt;br /&gt;
}&lt;br /&gt;
.openerp .oe_histest_index h1 {&lt;br /&gt;
    font-size: 40px;&lt;br /&gt;
}&lt;br /&gt;
.openerp .oe_application {&lt;br /&gt;
    width: calc(100% - 221px);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
@media screen and (max-width: 800px) {&lt;br /&gt;
    .openerp .oe_leftbar {&lt;br /&gt;
        width: 100%;&lt;br /&gt;
    }&lt;br /&gt;
    .openerp .oe_application {&lt;br /&gt;
        width: 100%;&lt;br /&gt;
    }&lt;br /&gt;
    .openerp a.oe_logo {&lt;br /&gt;
        display: none;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Asynchronous request ==&lt;br /&gt;
&lt;br /&gt;
=== เพิ่มปุ่ม Search ในฟอร์มให้เรียกค้นกลับไปยังเซิร์ฟเวอร์ของ OpenERP === &lt;br /&gt;
&lt;br /&gt;
==== ไฟล์ &amp;lt;code&amp;gt;histest_view.xml&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
แก้ไข view &amp;lt;code&amp;gt;histest.patient.form&amp;lt;/code&amp;gt; โดยระบุชนิด widget ที่สร้างขึ้นมาให้กับฟิลด์ &amp;lt;code&amp;gt;first_name&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;last_name&amp;lt;/code&amp;gt; และ &amp;lt;code&amp;gt;id_number&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;record model=&amp;quot;ir.ui.view&amp;quot; id=&amp;quot;view_histest_patient_form&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;field name=&amp;quot;name&amp;quot;&amp;gt;histest.patient.form&amp;lt;/field&amp;gt;&lt;br /&gt;
  &amp;lt;field name=&amp;quot;model&amp;quot;&amp;gt;histest.patient&amp;lt;/field&amp;gt;&lt;br /&gt;
  &amp;lt;field name=&amp;quot;arch&amp;quot; type=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;form string=&amp;quot;Patient&amp;quot; version=&amp;quot;7.0&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;group cols=&amp;quot;2&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;group colspan=&amp;quot;1&amp;quot;&amp;gt;&lt;br /&gt;
          &amp;lt;field name=&amp;quot;title&amp;quot;/&amp;gt;&lt;br /&gt;
          &amp;lt;field name=&amp;quot;first_name&amp;quot; widget=&amp;quot;firstname&amp;quot; /&amp;gt;&lt;br /&gt;
          &amp;lt;field name=&amp;quot;last_name&amp;quot; widget=&amp;quot;lastname&amp;quot; /&amp;gt;&lt;br /&gt;
        &amp;lt;/group&amp;gt;&lt;br /&gt;
        &amp;lt;group colspan=&amp;quot;1&amp;quot;&amp;gt;&lt;br /&gt;
          &amp;lt;field name=&amp;quot;sex&amp;quot;/&amp;gt;&lt;br /&gt;
          &amp;lt;field name=&amp;quot;id_number&amp;quot; widget=&amp;quot;person_id&amp;quot; /&amp;gt;&lt;br /&gt;
        &amp;lt;/group&amp;gt;&lt;br /&gt;
      &amp;lt;/group&amp;gt;&lt;br /&gt;
    &amp;lt;/form&amp;gt;&lt;br /&gt;
  &amp;lt;/field&amp;gt;&lt;br /&gt;
&amp;lt;/record&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== ไฟล์ &amp;lt;code&amp;gt;static/src/xml/histest.xml&amp;lt;/code&amp;gt; ====&lt;br /&gt;
เพิ่มเทมเพลทเพื่อใข้กับ widget สำหรับฟิลด์ &amp;lt;code&amp;gt;first_name&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;last_name&amp;lt;/code&amp;gt; และ &amp;lt;code&amp;gt;id_number&amp;lt;/code&amp;gt; ในฟอร์มเพิ่มข้อมูลผู้ป่วย&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;templates&amp;gt;&lt;br /&gt;
  :&lt;br /&gt;
  &amp;lt;t t-name=&amp;quot;histest.FieldPID&amp;quot; t-extend=&amp;quot;FieldChar&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;t t-jquery=&amp;quot;input&amp;quot;&amp;gt;&lt;br /&gt;
      this.parent().append(&amp;#039;&amp;lt;button class=&amp;quot;oe_histest_pid_search&amp;quot;&amp;gt;Search&amp;lt;/button&amp;gt;&amp;#039;);&lt;br /&gt;
    &amp;lt;/t&amp;gt;&lt;br /&gt;
  &amp;lt;/t&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;t t-name=&amp;quot;histest.FieldFirstName&amp;quot; t-extend=&amp;quot;FieldChar&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;t t-jquery=&amp;quot;input&amp;quot;&amp;gt;&lt;br /&gt;
      this.addClass(&amp;quot;oe_histest_firstname&amp;quot;);&lt;br /&gt;
    &amp;lt;/t&amp;gt;&lt;br /&gt;
  &amp;lt;/t&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;t t-name=&amp;quot;histest.FieldLastName&amp;quot; t-extend=&amp;quot;FieldChar&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;t t-jquery=&amp;quot;input&amp;quot;&amp;gt;&lt;br /&gt;
      this.addClass(&amp;quot;oe_histest_lastname&amp;quot;);&lt;br /&gt;
    &amp;lt;/t&amp;gt;&lt;br /&gt;
  &amp;lt;/t&amp;gt;&lt;br /&gt;
  :&lt;br /&gt;
&amp;lt;/templates&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== ไฟล์ &amp;lt;code&amp;gt;static/src/js/histest_regis.js&amp;lt;/code&amp;gt; ====&lt;br /&gt;
เป็นไฟล์ใหม่ที่สร้างขึ้นมาเพื่อผูก widget ใหม่เข้ากับเทมเพลท รวมถึงบรรจุโค้ดที่ดำเนินการส่งคำร้องการค้นหาตามรหัสผู้ป่วยแบบ asynchronous กลับมายัง OpenERP Server เมื่อผู้ใช้คลิ้กปุ่ม Search ซึ่งเมื่อได้รับคำตอบแล้วจะนำไปอัพเดตในฟิลด์ &amp;lt;code&amp;gt;first_name&amp;lt;/code&amp;gt; และ &amp;lt;code&amp;gt;last_name&amp;lt;/code&amp;gt; ที่อยู่ในฟอร์มอีกที&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
openerp.histest.regis = function(instance) {&lt;br /&gt;
    instance.histest.regis = {}&lt;br /&gt;
&lt;br /&gt;
    instance.histest.regis.FieldPID = instance.web.form.FieldChar.extend({&lt;br /&gt;
&lt;br /&gt;
        template: &amp;#039;histest.FieldPID&amp;#039;,&lt;br /&gt;
&lt;br /&gt;
        events: {&lt;br /&gt;
          &amp;#039;click .oe_histest_pid_search&amp;#039;: function(e) {&lt;br /&gt;
            var url = &amp;quot;/histest/ajax?pid=&amp;quot;+$(&amp;quot;.oe_histest_pid_search&amp;quot;).parent().find(&amp;quot;input&amp;quot;).val();&lt;br /&gt;
            $.getJSON(url, function(data) {&lt;br /&gt;
              $(&amp;quot;.oe_histest_firstname&amp;quot;).val(data.firstname);&lt;br /&gt;
              $(&amp;quot;.oe_histest_lastname&amp;quot;).val(data.lastname);&lt;br /&gt;
            });&lt;br /&gt;
          },&lt;br /&gt;
        },&lt;br /&gt;
&lt;br /&gt;
    });&lt;br /&gt;
&lt;br /&gt;
    instance.histest.regis.FieldFirstName = instance.web.form.FieldChar.extend({&lt;br /&gt;
        template: &amp;#039;histest.FieldFirstName&amp;#039;,&lt;br /&gt;
    });&lt;br /&gt;
&lt;br /&gt;
    instance.histest.regis.FieldLastName = instance.web.form.FieldChar.extend({&lt;br /&gt;
        template: &amp;#039;histest.FieldLastName&amp;#039;,&lt;br /&gt;
    });&lt;br /&gt;
&lt;br /&gt;
    instance.web.form.widgets.add(&amp;#039;person_id&amp;#039;, &amp;#039;instance.histest.regis.FieldPID&amp;#039;);&lt;br /&gt;
    instance.web.form.widgets.add(&amp;#039;firstname&amp;#039;, &amp;#039;instance.histest.regis.FieldFirstName&amp;#039;);&lt;br /&gt;
    instance.web.form.widgets.add(&amp;#039;lastname&amp;#039;, &amp;#039;instance.histest.regis.FieldLastName&amp;#039;);&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== ไฟล์ &amp;lt;code&amp;gt;__openerp__.py&amp;lt;/code&amp;gt; ====&lt;br /&gt;
ระบุให้โค้ดจาวาสคริปต์ &amp;lt;code&amp;gt;static/src/js/histest_regis.js&amp;lt;/code&amp;gt; ถูกโหลดพร้อมกับมอดูล&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
    :&lt;br /&gt;
    &amp;#039;js&amp;#039;: [&lt;br /&gt;
        &amp;#039;static/src/js/histest.js&amp;#039;,&lt;br /&gt;
        &amp;#039;static/src/js/histest_message.js&amp;#039;,&lt;br /&gt;
        &amp;#039;static/src/js/histest_patient.js&amp;#039;,&lt;br /&gt;
        &amp;#039;static/src/js/histest_regis.js&amp;#039;,&lt;br /&gt;
    ],&lt;br /&gt;
    :&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== สร้าง web controller เพื่อรับคำร้องการค้นหา ===&lt;br /&gt;
web controller ที่สร้างขึ้นมีขั้นตอนการทำงานดังนี้&lt;br /&gt;
&lt;br /&gt;
# รับคำร้องในรูป AJAX request เมื่อผู้ใช้กดปุ่มค้นหาในฟอร์มวิว โดยส่งมาในรูปของ URL &amp;lt;code&amp;gt;localhost:8069/histest/ajax/?pid=&amp;lt;รหัสผู้ป่วย&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
# ส่งเลขประจำตัวผู้ป่วยไปยังเซิร์ฟเวอร์ให้บริการข้อมูล (อาทิเช่นเซิร์ฟเวอร์ทะเบียนราษฎร์) เพื่อขอรายละเอียดผู้ป่วย ในการอบรมนี้สมมติว่าเซิร์ฟเวอร์รอรับคำร้องขออยู่ที่ URL http://theory.cpe.ku.ac.th:8080&lt;br /&gt;
# คืนผลลัพธ์กลับไปที่ฟอร์มในรูปของ JSON&lt;br /&gt;
&lt;br /&gt;
==== ไฟล์ &amp;lt;code&amp;gt;controllers/__init__.py&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import my_controller&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== ไฟล์ &amp;lt;code&amp;gt;controllers/my_controller.py&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import openerp.addons.web.http as http&lt;br /&gt;
import simplejson as json&lt;br /&gt;
import urllib2&lt;br /&gt;
&lt;br /&gt;
class MyController(http.Controller):&lt;br /&gt;
    _cp_path = &amp;#039;/histest/ajax&amp;#039;&lt;br /&gt;
&lt;br /&gt;
    @http.httprequest&lt;br /&gt;
    def index(self, req, s_action=None, **kwargs):&lt;br /&gt;
        pid = req.params[&amp;#039;pid&amp;#039;]&lt;br /&gt;
        request_url = &amp;quot;http://theory.cpe.ku.ac.th:8080/%s&amp;quot; % pid&lt;br /&gt;
        contents = urllib2.urlopen(request_url)&lt;br /&gt;
        return contents.read()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== ไฟล์ &amp;lt;code&amp;gt;__init__.py&amp;lt;/code&amp;gt; ====&lt;br /&gt;
เพิ่มคำสั่ง import แพคเกจ controllers&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import histest&lt;br /&gt;
import controllers&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== เอกสารครั้งก่อน ๆ ==&lt;br /&gt;
* [[Openerp/histest1|โค้ดสำหรับการทดสอบครั้งที่ 1 วันที่ 27 มี.ค. 2557]] - เกี่ยวกับ web module และการเรียก message&lt;/div&gt;</summary>
		<author><name>Chaiporn</name></author>
		
	</entry>
</feed>