2013-01-10 7 views
5

मैं openerp के वेब देव के लिए नया हूं, मैं कुछ मदद की सराहना करता हूं। मैं गिनती टाइमर विजेट बनाना चाहता हूं, उदाहरण के लिए textbox में, स्टार्ट और स्टॉप बटन (मेरे नए कस्टम फ़ील्ड या अलग में शामिल) के साथ।ओपनरप वेब क्लाइंट फ़ील्ड को कस्टमाइज़ करने के लिए कैसे करें (मूल फ़ील्ड विजेट का विस्तार करें)

मैंने समय गिनने के लिए एक छोटा javascript फ़ंक्शन बनाया।

क्या मुझे मूल FieldChar का विस्तार करके एक नया विजेट बनाना चाहिए? एक नया प्रकार का क्षेत्र बनाएं?

मैं अपना काउंटर कोड कहां रखूं, और char फ़ील्ड (या नए प्रकार के फ़ील्ड) पर इसे कैसे प्रदर्शित करूं?

मैं कैसे कुछ के साथ 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); 
    } 
    }); 
} 

मैं कुछ मार्गदर्शन की जरूरत भी कैसे इंटरफ़ेस काम करता है के बारे में openerp's डॉक के साथ एक साथ यह सब डाल करने के लिए।

अग्रिम धन्यवाद है

यहाँ जहां मैं हूं: मॉड्यूल: 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> 

मेरी त्वरित गिनती अप टाइमर परीक्षण:

<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

आप सही रास्ते पर हैं। यहां प्रलेखन पर एक नज़र डालें: http: //doc.openerp।कॉम/ट्रंक/डेवलपर्स/वेब/मॉड्यूल/अंत में वे टाइमर विजेट का उदाहरण लेते हैं! : डी मैंने इसका परीक्षण किया, लेकिन काफी व्याख्यात्मक लगता है। – TimoSolo

+0

उत्तर तीमुथियुस के लिए धन्यवाद। मैं web_example की कोशिश कर रहा हूं जिसने मुझे बताया है। कुछ मुद्दों के बाद (मेन्यूटेम टैग पार्स त्रुटि) मैं काउंटर प्रदर्शित करने का प्रबंधन करता हूं (यह एक शुरुआत है !!!) लेकिन बटन फ़ंक्शंस कॉल नहीं कर रहे हैं ... क्या यह 6.1 पर काम कर रहा है? (मुझे आश्चर्य है कि जिस दस्तावेज़ से आपने मुझे लिंक किया है वह ट्रंक स्थित है) मैं कोड (एक बटन और अलर्ट) को सरल बनाने की कोशिश कर रहा हूं लेकिन काम नहीं कर रहा हूं। लगता है कि "घटनाएं" काम नहीं करती हैं या नहीं सुनाई जाती हैं ... कोई विचार? अग्रिम धन्यवाद, मैं अभी भी आगे बढ़ रहा हूं ताकि यह अच्छा हो –

उत्तर

2

मैं परीक्षण के लिए एक OpenERP कार्रवाई के रूप में मेरी घड़ी करना करने में कामयाब रहे, टाइमर अप में गिना जाता है, प्रदर्शन आदि अद्यतन किया जाता है ...

अब मैं इस जो मैं रूपों में इस्तेमाल कर सकते हैं एक OpenERP क्षेत्र बनना चाहते हैं :

मैं इसके करीब हूं, लेकिन बटन अब और काम नहीं कर रहे हैं।

मॉड्यूल का नाम 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/सीएसएस/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: मैं < को दूर के रूप में मैं (जल्दी से) नहीं था एचटीएमएल कोड सही तरीके से

प्रदर्शित करने के लिए एक रास्ता खोजने
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> 
संबंधित मुद्दे