29 เมษายน 2555

jquery plugin สำหรับใช้ barcode scaner กับ web application HTML form input

วันนี้เจอปัญหาของ web application ตัวนึงซึ่งมี form รับ input เป็น Serial Barcode

ปกติอุปกรณ์ barcode scanner ทั่วไปจะแสกน serial เหมือน keyboard แล้วตามด้วยการกด "Enter" key stroke

ปัญหา 

ใน HTML web form

ถ้าพิมพ์อะไรในช่อง input  นี้แล้วกด Enter จะเป็นการ submit form นั้นทันที ถ้าในฟอร์มเราต้องกรอก input ข้อมูลอื่นด้วยหลายช่อง ทันทีที่แสกนบาร์โค้ดเสร็จจะเหมือนกด submit ทันทีทั้งที่ยังกรอกข้อมูลช่องอื่นไม่ครบ

Solved

แก้ด้วยการเขียน jquery plugin ป้องกัน form submit เวลาที่ยิงสแกน barcode

(function($){
    $.fn.acceptBarcode = function(barcodeClass){
        var canSubmit = false;

        this.submit(function(e){
            //e.preventDefault();
            return canSubmit;
        });

        this.find('input.' + barcodeClass).each(function(){
            console.log('accept barcode for ' + $(this).attr('name'))

            $(this).bind('keyup', function(e){
                var code = (e.keyCode? e.keyCode : e.which);
                if(code == 13){ // Enter key pressed.
                    canSubmit = false;
                    console.log('serial enter detected - disable form.submit()');
                }
            })

            $(this).bind('focus', function(){
                canSubmit = false;
                console.log('serial input focus - disable form.submit()');
            })

            $(this).bind('blur', function(){
                canSubmit = true;
                console.log('serial input blur - enable form.submit()');
            });
        });
    };
})(jQuery);



วิธีใช้งาน..
<input class="barcode" type="text" 
$(document).ready(function(){
    $('form').acceptBarcode('barcode');
});

11 เมษายน 2555

เขียน Python webapp ด้วย Django+Google App Engine+Cloud SQL - part2 deploy

series content :


django settings.py  ติดต่อฐานข้อมูล Cloud SQL


DATABASES = {
   'default': {
       'ENGINE': 'google.appengine.ext.django.backends.rdbms',
       'INSTANCE': 'project-id:instance1',
       'NAME': 'my_database_name',
   }
}

ตั้งค่า INSTANCE และชื่อฐานข้อมูลตามที่สร้างไว้ใน https://code.google.com/apis/console


ตอนนี้เราอยากทดลองติดต่อฐานข้อมูล Cloud ให้ได้ก่อน โดยยังไม่ต้องเขียน models เอง วิธีง่ายสุดเปิดใช้ django.contrib.admin กับ auth (ระบบ login) ที่มากับ django นี่ล่ะ

10 เมษายน 2555

เขียน Python webapp ด้วย Django+Google App Engine+Cloud SQL -part0 สมัครใช้ API

series content :

Update June, 2012

ตอนนี้ Google ประกาศเก็บเงินค่าใช้บริการ Cloud SQL แล้ว
Dear Cloud SQL previewer
As was previously announced, from June 12th 2012 use of the Google Cloud SQL service will be charged.
To continue using your Cloud SQL instances after June 12th 2012, you will need to enable billing for your projects before then by signing in to the Google APIs console and clicking the Billing tab. Once billing is enabled you can choose (or change) the billing plan for your instances from the Cloud SQL tab. Your instances will not be available after June 12th 2012 if you do not enable billing beforehand.
ตั้งแต่วันที่ 12 มิย. 55 ถ้าอยากจะใช้งาน Cloud SQL ต้องเปิด Billing Service มี  Pricing Package คิดตามการใช้งานจริง ถ้าทดลองใช้งานแบบ Per Use Billing Plan จะถูกกว่า

วิธีการสมัครใช้งาน Google Cloud SQL Limited Preview

ตอนนี้ Google เปิดให้ใช้งาน  Cloud SQL  สำหรับ developer ที่สนใจทดสอบเท่านั้น ยังไม่ได้เปิดใช้ 100% ขั้นตอนการสมัครใช้เวลาพอสมควร อธิบายวิธีการสมัครไว้หน่อย

เข้าไปที่หน้า https://code.google.com/apis/console ถ้ายังไม่เคยใช้งานก็ใช้ Gmail Account login

เปิดไปที่แทป Services มองหา Google Cloud SQL



กด Request access.. link ไปที่หน้าฟอร์มสมัครใช้งาน .. (Google Cloud SQL Limited Preview Signup)

9 เมษายน 2555

เขียน Python webapp ด้วย Django+Google App Engine+Cloud SQL - part1 การติดตั้ง SDK

series content :


ก่อนหน้านี้เคยใช้ django non-rel deploy ใน Google App Engine ตอนนั้นยังไม่รองรับ relational database มีแต่ datastore เป็น nosql 

ปัจจุบัน appengine SDK มี builtins: - django_wsgi มาให้พร้อมใช้งาน เลยอยากลองทำ prove concept  Google Cloud SQL ดูซะหน่อย

การติดตั้ง Google App Engine SDK + Django ใน Development Server



Prerequisition : สมัครใช้งาน Google Cloud SQL - Sign up for Limited Preview (estimate time: 7-10 days)

Download / Runtime version ที่ GAE รองรับ (updated 04/2012)