basic.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * JavaScript file
  3. */
  4. function init(){
  5. NOKIA_PATH_JAVASCRIPT = 'lib/';
  6. NOKIA_PATH_STYLE_ROOT = 'themes/nokia/base/';
  7. URL_PRODUCTLIST = 'http://www.izinin.fn-sandbox.net/mobile_getproductlist.php';
  8. AUTHDIGEST = '';
  9. window.buyButtonArr = [];
  10. // IAP API related literals below
  11. KUserAndDevice = "UserAndDeviceId";
  12. KProductData = "ProductData";
  13. KPurchaseProduct = "PurchaseProduct";
  14. // ~~~~
  15. KIAPCmd = "command";
  16. KProductID = "productId";
  17. //Necessary if you are working on 3rd Ed devices
  18. if (window.widget) {
  19. widget.setNavigationEnabled(false);
  20. }
  21. Nokia.use('template-default', 'busy', 'customizablelist', 'button',
  22. function(){
  23. //setup
  24. inapprogress = new Nokia.Busy({
  25. element: document.body,
  26. autoOpen: false
  27. });
  28. Nokia.dom.append(document.body, Nokia.dom.parseHTML('<div id="productlist"></div>'));
  29. productListCtrl = new Nokia.CustomizableList({element: '#productlist'});
  30. // utility functions
  31. function appendProduct(product, index, array){
  32. var item_placeholder = Nokia.dom.parseHTML(
  33. '<div id="product_' + index + '" class="ui-helper-clearfix">' +
  34. '<span id="buy_' + index + '" ></span>' +
  35. '<span id="productinfo_' + index + '" > Please wait product <' +
  36. product + '> data is loading...</span></div>');
  37. productListCtrl.addItem(item_placeholder);
  38. window.buyButtonArr[index] = new Nokia.Button({
  39. element: '#buy_' + index,
  40. disabled: true,
  41. label: 'Wait...',
  42. click: function(){
  43. APIBridge.Internal._sendRequest(
  44. "/nokia/iapplugin?" + KIAPCmd + "=" + KPurchaseProduct + "&" + KProductID + "=" + product,
  45. null,
  46. function(req){
  47. alert("Purchasing result: <" + req.responseText + ">");
  48. },
  49. null);
  50. }
  51. });
  52. APIBridge.Internal._sendRequest(
  53. "/nokia/iapplugin?" + KIAPCmd + "=" + KProductData + "&" + KProductID + "=" + product,
  54. null,
  55. function(req){
  56. var expr = '#productinfo_' + index;
  57. $(expr).html(req.responseText);
  58. $(expr).css("color", "darkgreen");
  59. var expr = '#buy_' + index;
  60. window.buyButtonArr[index].enable();
  61. window.buyButtonArr[index].setLabel("Buy");
  62. },
  63. null);
  64. }
  65. //start execution
  66. inapprogress.hide();
  67. APIBridge.Internal._sendRequest(
  68. "/nokia/iapplugin?" + KIAPCmd + "=" + KUserAndDevice,
  69. null,
  70. function(req){
  71. AUTHDIGEST = req.responseText;
  72. inapprogress.show();
  73. window.jQuery.getJSON(URL_PRODUCTLIST + "?callback=?", null, function(productList, result, xdr){
  74. productList.forEach(appendProduct);
  75. productListCtrl.show();
  76. inapprogress.hide();
  77. });
  78. },
  79. null);
  80. });
  81. }