2013-01-10 20 views
5

Tôi mới đến trang web của openerp, tôi sẽ đánh giá cao một số trợ giúp. Tôi muốn tạo tiện ích đếm thời gian đếm ngược, ví dụ: trong textbox, với nút bắt đầu và nút dừng (bao gồm trong trường tùy chỉnh mới của tôi hoặc riêng biệt).trình duyệt web của openerp cách tùy chỉnh trường (mở rộng tiện ích trường cơ bản)

Tôi đã thực hiện một chức năng nhỏ javascript để đếm thời gian.

Tôi có nên tạo tiện ích con mới bằng cách mở rộng cơ bản FieldChar không? Tạo một loại trường mới?

Tôi nên đặt mã truy cập của mình ở đâu và cách hiển thị mã trên trường char (hoặc loại trường mới)?

Tôi tìm thấy một số doc về cách mở rộng với một cái gì đó giống như openerp.web.form.FieldChar:

openerp.web_mymodule = function(openerp) { 
    openerp.web.form.Field.include({ 
    init: function(view, node) { 
     console.log('mine'); 
     this._super(view, node); 
    } 
    }); 
} 

Tôi cần một số hướng dẫn để đặt tất cả này lại với nhau ngay cả với openerp's doc về giao diện làm việc như thế nào.

Cảm ơn trước

Đây là nơi tôi: Module: web_uptimer

web_uptimer.js:

openerp.web_uptimer = function (openerp) 
{ 
    openerp.web.form.widgets.add('uptimer', 'openerp.web_uptimer.CountUp'); 
    openerp.web_uptimer.CountUp = openerp.web.form.FieldChar.extend(
     { 
     template : "uptimer.template", 
     init: function (view, code) { 
      this._super(view, code); 
      console.log('counting...'); 
      alert('counting...'); 
     } 
    }); 
} 

web_uptimer.xml:

<?xml version="1.0" encoding="UTF-8"?> 
<templates id="template" xml:space="preserve"> 
<t t-name="uptimer.template"> 
      <html> 
      </html> 
</t> 
</templates> 

đếm nhanh chóng của tôi kiểm tra hẹn giờ lên:

<html> 
    <head> 
     <title></title> 
     <script type="text/javascript"> 
      var counter = 0; 
      var minutes = 0; 
      var hours = 0; 
      var timer; 
      var todisplay; 
      var h2disp; 
      var m2disp; 
      var s2disp; 

      function countUP() 
      { 
       counter = counter + 1;//increment the counter by 1 
       if(counter == 60) 
       { 
        counter = 0; 
        minutes = minutes + 1; 
        if(minutes == 60) 
        { 
         minutes = 0; 
         hours = hours + 1 
        } 
       } 
       if(counter < 10) 
       { 
        s2disp = "0" + counter; 
       } 
       else 
       { 
        s2disp = counter; 
       } 
       if(minutes < 10) 
       { 
        m2disp = "0" + minutes; 
       } 
       else 
       { 
        m2disp = minutes; 
       } 
       if(hours < 10) 
       { 
        h2disp = "0" + hours; 
       } 
       else 
       { 
        h2disp = hours; 
       } 
       todisplay = h2disp + ":" + m2disp + ":" + s2disp; 
       document.getElementById("timer_container").innerHTML = todisplay; 
      } 
     </script> 
    </head> 
    <body onload='timer=setInterval("countUP()", 1000);'> 
     <div id="timer_container">00:00:00</div> 
     <div> 
      <button onclick='clearInterval(timer);'>Stop Timer</button> 
      <button onclick='timer=setInterval("countUP()", 1000);'>Continue Timer</button> 
     </div> 
    </body> 
</html> 
+0

bạn đang đi đúng hướng. Xem tài liệu tại đây: http: //doc.openerp.com/trunk/developers/web/module/ở cuối chúng xảy ra để có một ví dụ về một widget hẹn giờ! : D Tôi đã thử nghiệm nó, nhưng có vẻ khá giải thích. – TimoSolo

+0

Cảm ơn câu trả lời Timothy. Tôi đang thử web_example bạn đã chỉ cho tôi. Sau một số vấn đề (lỗi phân tích thẻ menuitem) Tôi quản lý để hiển thị bộ đếm (bắt đầu !!!) nhưng các nút không phải là chức năng gọi ... Nó có hoạt động trên 6.1 không? (Tôi tự hỏi là tài liệu bạn liên kết với tôi nằm ở thân cây) Tôi đang cố đơn giản hóa mã (nút và cảnh báo) nhưng không hoạt động. dường như “các sự kiện” không hoạt động hoặc không được lắng nghe… Bất kỳ ý tưởng nào? Cảm ơn trước, tôi vẫn đang tiến lên vì vậy điều đó tốt –

Trả lời

2

tôi quản lý để làm hẹn giờ của tôi như là một hành động OpenERP ra xét xử, timer đếm lên, hiển thị được cập nhật vv ...

Bây giờ tôi muốn điều này trở thành một lĩnh vực OpenERP mà tôi có thể sử dụng các hình thức :

Tôi gần gũi với nó, nhưng các nút không hoạt động nữa.

Đây là mã của tôi:

tên module là web_example:

src/js/first_module.js:

openerp.web_example = function (openerp) { 
     openerp.web.form.widgets.add('FieldUpTimer',  'openerp.web.form.FieldUpTimer'); 
     openerp.web.form.FieldUpTimer = openerp.web.form.FieldChar.extend({ 
     template: 'web_example.action', 
     init: function() { 
      this._super.apply(this, arguments); 
      this._start = null; 
      this._watch = null; 

     }, 

    start: function() { 
     this.$element.find('button#bstart').click(_.bind(this.mystart, this)); 
     this.$element.find('button#bstart').click(this.mystart); 
     this._start = null; 
    }, 

    countUP: function (counter,minutes,hours,timer,todisplay,h2disp,m2disp,s2disp) 
      { 
     var h, m, s; 
     // Subtracting javascript dates returns the difference in milliseconds 
     var diff = new Date() - this._start; 
     s = diff/1000; 
     m = Math.floor(s/60); 
     s -= 60*m; 
     h = Math.floor(m/60); 
     m -= 60*h; 
       todisplay = _.str.sprintf("%02d:%02d:%02d", h, m, s); 
       document.getElementById("extimer").innerHTML = todisplay; 
      }, 

    mystart: function() { 
      alert('pffff ça marche'); 
      this.$element.addClass('oe_web_example_started') 
          .removeClass('oe_web_example_stopped'); 
      //timer=setInterval(this.countUP(counter,minutes,hours,timer,todisplay,h2disp,m2disp,s2disp), 1000); 
      this._start = new Date(); 
        this._watch = setInterval(this.proxy('countUP'),33); 
    }, 



      destroy: function() { 
     if (this._watch) { 
      clearInterval(this._watch); 
     } 
     this._super(); 
    } 
}); 

};

src/css/web_example.css:

.openerp .oe_web_example { 
    color: black; 
    background-color: white; 
    height: 100%; 
} 
.openerp .oe_web_example h4 { 
    margin: 0; 
    font-size: 100%; 
} 
.openerp .oe_web_example.oe_web_example_started .oe_web_example_start button, 
.openerp .oe_web_example.oe_web_example_stopped .oe_web_example_stop button { display: none }, 

src/xml/web_example.xml: tôi loại bỏ < như tôi không (nhanh chóng) tìm thấy một cách để hiển thị mã html đúng

templates> 
    div t-name="web_example.action" class="oe_web_example"> 
    p> 
     button type="button" id="bstart">start</button> 

     h4 class="oe_web_example_timer" id="extimer">00:00:00</h4> 
    /p> 
    button type="button" id="bstop">Stop</button> 
/div> 
/templates> 

/web_example.xml

<?xml version="1.0" encoding="utf-8"?> 
<openerp> 
<data> 
    <record model="ir.actions.act_window" id="action_web_example_form"> 
     <field name="name">web_example_class</field> 
     <field name="res_model">web_example_class</field> 
    </record> 

    <record model="ir.ui.view" id="action_web_example_form_view"> 
     <field name="name">web_example.form</field> 
     <field name="model">web_example_class</field> 
     <field name="type">form</field> 
     <field name="arch" type="xml"> 
      <form string="Web Example View"> 
       <field name="test2" widget="FieldUpTimer"/> 
      </form> 
     </field> 
    </record> 

<menuitem name="WEB EXAMPLE" action="action_web_example_form" id="web_example_menu"/> 
</data> 
</openerp>