webglade

JavaScript library to dynamically create XUL GUI from Glade XML files
git clone https://logand.com/git/webglade.git/
Log | Files | Refs | README | LICENSE

mab.js (14752B)


      1 var LOADED = 0;
      2 
      3 WHANDLER['on_allinfo_loaded'] =
      4 function () {
      5   ++LOADED;
      6   if (2 < LOADED) {
      7     main();
      8   };
      9 };
     10 
     11 WHANDLER['on_comment_loaded'] =
     12 function () {
     13   ++LOADED;
     14   if (2 < LOADED) {
     15     main();
     16   };
     17 };
     18 
     19 function main2() {
     20   if (LOADED == 0) {
     21     ++LOADED;
     22     wremove(wget('loading'));
     23     if (window.name) {
     24       switch (window.name) {
     25         case 'Settings':
     26            loadXml
     27            ('mab.glade',
     28             function (glade) {
     29               {
     30                 var widgets = parseGlade(glade);
     31                 wbuild
     32                 (document.documentElement, [ widgets['settings'] ]);
     33               };
     34               initSettings();
     35             });
     36            break;
     37         case 'About':
     38            loadXml
     39            ('mab.glade',
     40             function (glade) {
     41               var widgets = parseGlade(glade);
     42               wbuild
     43               (document.documentElement, [ widgets['about'] ]);
     44             });
     45            break;
     46         case 'Help':
     47            loadXml
     48            ('mab.glade',
     49             function (glade) {
     50               var widgets = parseGlade(glade);
     51               wbuild
     52               (document.documentElement, [ widgets['helpWin'] ]);
     53             });
     54       };
     55     } else {
     56       loadXml
     57       ('mab.glade',
     58        function (glade) {
     59          {
     60            var widgets = parseGlade(glade);
     61            wbuild
     62            (document.documentElement, [ widgets['amazWindow'] ]);
     63          };
     64          init();
     65        });
     66     };
     67   };
     68 };
     69 
     70 function settingsDialog() {
     71   window.open
     72   ('mab.xul', 'Settings', 'chrome,centerscreen,modal,width=440,height=300');
     73 };
     74 
     75 function aboutDialog() {
     76   window.open
     77   ('mab.xul', 'About', 'chrome,centerscreen,modal,width=450,height=350');
     78 };
     79 
     80 function helpDialog() {
     81   window.open
     82   ('mab.xul', 'Help', 'chrome,centerscreen,resizable,width=640,height=500');
     83 };
     84 
     85 function init() {
     86   {
     87     var w = wget('amazWindow');
     88     var cs = wmake(w, 'xul:commandset', { id : 'mabCommand' });
     89     var ks = wmake(w, 'xul:keyset');
     90     var ms = wmake(cs, 'xul:commandset', { id : 'menubarCommand' });
     91     wmake
     92     (w, 'xul:broadcaster',
     93      { id : 'isSearchRunning', 
     94        disabled : 'true' });
     95     wmake
     96     (w, 'xul:broadcaster',
     97      { id : 'isMabRemote', 
     98        disabled : 'false' });
     99     wmake
    100     (w, 'xul:spacer',
    101      { id : 'settings-spacer', 
    102        hidden : 'true', 
    103        search : 'lite', 
    104        nrResult : 20, 
    105        persist : 'search nrResult' });
    106     {
    107       var tmpArr1 =
    108           [ [ 'newSearchCmd', 'newSearch()' ], [ 'nextCmd', 'nextRecord()' ],
    109             [ 'clearCmd', 'clearAll()' ], [ 'commentCmd', 'getComment()' ],
    110             [ 'goAmazonCmd', 'goAmazon()' ], [ 'addCartCmd', 'addCart()' ],
    111             [ 'goGoogleCmd', 'goGoogle()' ], [ 'deleteCmd', 'deleteRow()' ] ];
    112       if (tmpArr1) {
    113         for (var tmpI2 = 0; tmpI2 < tmpArr1.length; tmpI2 = tmpI2 + 1) {
    114           var obj = tmpArr1[tmpI2];
    115           wmake
    116           (cs, 'xul:command',
    117            { id : obj[0], 
    118              oncommand : obj[1] });
    119         };
    120       };
    121     };
    122     {
    123       var tmpArr3 =
    124           [ [ 'newCmd', 'newDoc()' ],
    125             [ 'openCmd', 'openDoc(\'open\')', 'isMabRemote' ],
    126             [ 'closeCmd', 'closeDoc()' ],
    127             [ 'mergeCmd', 'openDoc(\'merge\')', 'isMabRemote' ],
    128             [ 'saveCmd', 'saveDoc()', 'isMabRemote' ],
    129             [ 'saveAsCmd', 'saveAsDoc()', 'isMabRemote' ],
    130             [ 'exportXMLCmd', 'exportXMLDoc()' ],
    131             [ 'exportHTMLCmd', 'exportHTMLDoc()' ],
    132             [ 'exportTXTCmd', 'exportTXTDoc()' ],
    133             [ 'makeCoverCmd', 'openCoverWin()' ],
    134             [ 'exitCmd', 'window.close()' ],
    135             [ 'simProductCmd', 'getSimilarProducts()' ],
    136             [ 'reloadExpiredCmd', 'reloadExpired()' ],
    137             [ 'reloadCmd', 'reload()' ], [ 'abortCmd', 'abort()' ],
    138             [ 'bookmarkCmd', 'addBookmark()' ],
    139             [ 'settingsCmd', 'settingsDialog()' ],
    140             [ 'topicsCmd', 'helpDialog()' ],
    141             [ 'feedbackCmd', 'window.open(MAB_FEEDBACK_PAGE)' ],
    142             [ 'aboutCmd', 'aboutDialog()' ] ];
    143       if (tmpArr3) {
    144         for (var tmpI4 = 0; tmpI4 < tmpArr3.length; tmpI4 = tmpI4 + 1) {
    145           var obj = tmpArr3[tmpI4];
    146           wmake
    147           (ms, 'xul:command',
    148            { id : obj[0], 
    149              oncommand : obj[1], 
    150              observes : 2 < obj.length ? obj[2] : undefined });
    151         };
    152       };
    153     };
    154     {
    155       var tmpArr5 =
    156           [ [ 'search-key', 'VK_RETURN', 'newSearchCmd' ],
    157             [ 'search-key', 'VK_ENTER', 'newSearchCmd' ],
    158             [ 'deleteKey', 'VK_DELETE', 'deleteCmd' ] ];
    159       if (tmpArr5) {
    160         for (var tmpI6 = 0; tmpI6 < tmpArr5.length; tmpI6 = tmpI6 + 1) {
    161           var obj = tmpArr5[tmpI6];
    162           wmake
    163           (ks, 'xul:key',
    164            { id : obj[0], 
    165              keycode : obj[1], 
    166              command : obj[2] });
    167         };
    168       };
    169     };
    170     var tmpArr7 =
    171         [ [ 'new-key', 'accel', 'n', 'newCmd' ],
    172           [ 'close-key', 'accel', 'w', 'closeCmd' ],
    173           [ 'save-key', 'accel', 's', 'saveCmd' ],
    174           [ 'review-key', 'accel', 'r', 'commentCmd' ] ];
    175     if (tmpArr7) {
    176       for (var tmpI8 = 0; tmpI8 < tmpArr7.length; tmpI8 = tmpI8 + 1) {
    177         var obj = tmpArr7[tmpI8];
    178         wmake
    179         (ks, 'xul:key',
    180          { id : obj[0], 
    181            modifiers : obj[1], 
    182            key : obj[2], 
    183            command : obj[3] });
    184       };
    185     };
    186   };
    187   {
    188     var tmpArr9 =
    189         [ [ 'new-icon', 'newCmd', 'new-key' ],
    190           [ 'save-icon', 'saveCmd', 'save-key' ],
    191           [ 'comment-button', 'commentCmd', 'review-key' ],
    192           [ 'delete-btn', 'deleteCmd', 'delete-key' ],
    193           [ 'open-icon', 'openCmd' ], [ 'reload-btn', 'reloadCmd' ],
    194           [ 'clear-btn', 'clearCmd' ], [ 'new1', 'newCmd', 'new-key' ],
    195           [ 'open1', 'openCmd' ], [ 'merge1', 'mergeCmd' ],
    196           [ 'close2', 'closeCmd', 'close-key' ],
    197           [ 'save1', 'saveCmd', 'save-key' ], [ 'save_as1', 'saveAsCmd' ],
    198           [ 'export_html1', 'exportHTMLCmd' ],
    199           [ 'export_xml1', 'exportXMLCmd' ], [ 'quit1', 'exitCmd' ],
    200           [ 'mabAddBookmark', 'bookmarkCmd' ], [ 'reload1', 'reloadCmd' ],
    201           [ 'load_reviews1', 'commentCmd', 'review-key' ],
    202           [ 'load_similar_products1', 'simProductCmd' ],
    203           [ 'delete_rows1', 'deleteCmd' ],
    204           [ 'text_summary1', 'exportTXTCmd' ],
    205           [ 'make_cd_cover1', 'makeCoverCmd' ],
    206           [ 'reload_expired1', 'reloadExpiredCmd' ],
    207           [ 'trash_all1', 'clearCmd' ], [ 'settings1', 'settingsCmd' ],
    208           [ 'content1', 'topicsCmd' ], [ 'feedback1', 'feedbackCmd' ],
    209           [ 'about1', 'aboutCmd' ], [ 'search-btn', 'newSearchCmd' ] ];
    210     if (tmpArr9) {
    211       for (var tmpI10 = 0; tmpI10 < tmpArr9.length; tmpI10 = tmpI10 + 1) {
    212         var obj = tmpArr9[tmpI10];
    213         var w = wget(obj[0]);
    214         wsetp(w, 'command', obj[1]);
    215         if (2 < obj.length) {
    216           wsetp(w, 'key', obj[2]);
    217         };
    218       };
    219     };
    220   };
    221   {
    222     var tmpArr11 =
    223         [ [ 'goAmazon-icon', 'goAmazonCmd', 'a' ],
    224           [ 'addCart-icon', 'addCartCmd', 'd' ],
    225           [ 'goGoogle-icon', 'goGoogleCmd', 'g' ],
    226           [ 'goAmazon-button', 'goAmazonCmd', 'a' ],
    227           [ 'addCart-button', 'addCartCmd', 'd' ],
    228           [ 'next-btn', 'nextCmd', 'm' ] ];
    229     if (tmpArr11) {
    230       for (var tmpI12 = 0; tmpI12 < tmpArr11.length; tmpI12 = tmpI12 + 1) {
    231         var obj = tmpArr11[tmpI12];
    232         var w = wget(obj[0]);
    233         wsetp(w, 'command', obj[1]);
    234         wsetp(w, 'accesskey', obj[2]);
    235       };
    236     };
    237   };
    238   {
    239     var tmpArr13 =
    240         [ [ 'none1', 'setLabel(\'none\')' ],
    241           [ 'orange1', 'setLabel(\'Orange\')' ],
    242           [ 'blue1', 'setLabel(\'Blue\')' ],
    243           [ 'green1', 'setLabel(\'Green\')' ],
    244           [ 'maroon1', 'setLabel(\'Maroon\')' ],
    245           [ 'olive1', 'setLabel(\'Olive\')' ],
    246           [ 'teal1', 'setLabel(\'Teal\')' ],
    247           [ 'purple1', 'setLabel(\'Purple\')' ],
    248           [ 'locale-popup', null, 'value' ], [ 'mode-popup', null, 'value' ],
    249           [ 'search-popup', null, 'value' ], [ 'sort-popup', null, 'value' ] ];
    250     if (tmpArr13) {
    251       for (var tmpI14 = 0; tmpI14 < tmpArr13.length; tmpI14 = tmpI14 + 1) {
    252         var obj = tmpArr13[tmpI14];
    253         var w = wget(obj[0]);
    254         if (obj[1]) {
    255           wsetp(w, 'oncommand', obj[1]);
    256         };
    257         if (obj[2]) {
    258           wsetp(w, 'persist', obj[2]);
    259         };
    260       };
    261     };
    262   };
    263   {
    264     var tmpArr15 =
    265         [ 'ProductName', 'Author', 'Manufacturer', 'ReleaseDate', 'ListPrice',
    266           'OurPrice', 'UsedPrice' ];
    267     if (tmpArr15) {
    268       for (var tmpI16 = 0; tmpI16 < tmpArr15.length; tmpI16 = tmpI16 + 1) {
    269         var obj = tmpArr15[tmpI16];
    270         wsetp(wget(obj), 'class', 'detail');
    271       };
    272     };
    273   };
    274   {
    275     var w = wget('abort-icon');
    276     wsetp(w, 'keycode', 'VK_ESCAPE');
    277     wsetp(w, 'observes', 'isSearchRunning');
    278   };
    279   {
    280     var w = wget('meter');
    281     wsetp(w, 'value', 0);
    282     wsetp(w, 'mode', 'determined');
    283   };
    284   {
    285     var tmpArr17 = [ 'isMabRemote', 'search-btn' ];
    286     if (tmpArr17) {
    287       for (var tmpI18 = 0; tmpI18 < tmpArr17.length; tmpI18 = tmpI18 + 1) {
    288         var n = tmpArr17[tmpI18];
    289         wsetp(wget(n), 'disabled', 'false');
    290       };
    291     };
    292   };
    293   {
    294     var tmpArr19 =
    295         [ 'locale-popup', 'mode-popup', 'search-popup', 'sort-popup' ];
    296     if (tmpArr19) {
    297       for (var tmpI20 = 0; tmpI20 < tmpArr19.length; tmpI20 = tmpI20 + 1) {
    298         var n = tmpArr19[tmpI20];
    299         var w = wget(n);
    300         var tmpArr21 = w.childNodes[0].childNodes;
    301         if (tmpArr21) {
    302           for (var tmpI22 = 0; tmpI22 < tmpArr21.length;
    303                tmpI22 = tmpI22 + 1) {
    304             var w2 = tmpArr21[tmpI22];
    305             wsetp(w2, 'disabled', 'false');
    306           };
    307         };
    308       };
    309     };
    310   };
    311   wempty(wget('windows-menu_menu'));
    312   var w = wget('result-tree');
    313   var h = wmake(w, 'xul:treecols');
    314   wsetp(w, 'enableColumnDrag', 'true');
    315   wsetp(w, 'onselect', 'showDetails()');
    316   {
    317     var tmpArr23 =
    318         [ { id : 'expired-col', 
    319             src : '../skin/images/expired.png', 
    320             label : 'Expired', 
    321             fixed : 'true', 
    322             hidden : 'true', 
    323             persist : 'ordinal hidden', 
    324             class : 'numeric treecol-image', 
    325             sortDirection : 'normal', 
    326             tooltiptext : 'Click to sort by expired products information', 
    327             onclick : 'sortResult(this,\'MABTSLastUpdate\')' },
    328           { id : 'status-col', 
    329             src : '../skin/images/status_unread.png', 
    330             label : 'Status', 
    331             fixed : 'true', 
    332             persist : 'ordinal hidden', 
    333             class : 'string treecol-image', 
    334             sortDirection : 'normal', 
    335             tooltiptext : 'Click to sort by read', 
    336             onclick : 'sortResult(this,\'MABStatus\')' },
    337           { id : 'name-col', 
    338             label : 'Product Name', 
    339             flex : '2', 
    340             persist : 'width ordinal', 
    341             class : 'string', 
    342             sortDirection : 'normal', 
    343             tooltiptext : 'Click to sort by product name', 
    344             onclick : 'sortResult(this,\'ProductName\')' },
    345           { id : 'catalog-col', 
    346             label : 'Catalog', 
    347             flex : '1', 
    348             persist : 'width ordinal hidden', 
    349             class : 'string', 
    350             sortDirection : 'normal', 
    351             tooltiptext : 'Click to sort by catalog', 
    352             onclick : 'sortResult(this,\'Catalog\')' },
    353           { id : 'locale-col', 
    354             label : 'Country', 
    355             flex : '1', 
    356             hidden : 'true', 
    357             persist : 'width ordinal hidden', 
    358             class : 'string', 
    359             sortDirection : 'normal', 
    360             tooltiptext : 'Click to sort by country', 
    361             onclick : 'sortResult(this,\'MABLocale\')' },
    362           { id : 'price-col', 
    363             label : 'Our Price', 
    364             flex : '1', 
    365             persist : 'width ordinal hidden', 
    366             class : 'numeric', 
    367             sortDirection : 'normal', 
    368             tooltiptext : 'Click to sort by our Price', 
    369             onclick : 'sortResult(this,\'OurPrice\')' },
    370           { id : 'used-price-col', 
    371             label : 'Used Price', 
    372             flex : '1', 
    373             persist : 'width ordinal hidden', 
    374             class : 'numeric', 
    375             sortDirection : 'normal', 
    376             tooltiptext : 'Click to sort by used Price', 
    377             onclick : 'sortResult(this,\'UsedPrice\')' },
    378           { id : 'rating-col', 
    379             label : 'Rating', 
    380             flex : '1', 
    381             hidden : 'true', 
    382             persist : 'width ordinal hidden', 
    383             class : 'numeric', 
    384             sortDirection : 'normal', 
    385             tooltiptext : 'Click to sort by customers rating', 
    386             onclick : 'sortResult(this,\'AvgCustomerRating\')' },
    387           { id : 'rank-col', 
    388             label : 'Rank', 
    389             flex : '1', 
    390             hidden : 'true', 
    391             persist : 'width ordinal hidden', 
    392             class : 'numeric', 
    393             sortDirection : 'normal', 
    394             tooltiptext : 'Click to sort by sales rank', 
    395             onclick : 'sortResult(this,\'SalesRank\')' },
    396           { id : 'released-col', 
    397             label : 'Released', 
    398             flex : '1', 
    399             hidden : 'true', 
    400             persist : 'width ordinal hidden', 
    401             class : 'date', 
    402             sortDirection : 'normal', 
    403             tooltiptext : 'Click to sort by released year', 
    404             onclick : 'sortResult(this,\'ReleaseDate\')' },
    405           { id : 'label-col', 
    406             src : '../skin/images/label.png', 
    407             label : 'Label', 
    408             flex : '1', 
    409             hidden : 'true', 
    410             persist : 'width ordinal hidden', 
    411             class : 'string treecol-image', 
    412             sortDirection : 'normal', 
    413             tooltiptext : 'Click to sort by your labels', 
    414             onclick : 'sortResult(this,\'MABLabel\')' } ];
    415     if (tmpArr23) {
    416       for (var tmpI24 = 0; tmpI24 < tmpArr23.length; tmpI24 = tmpI24 + 1) {
    417         var x = tmpArr23[tmpI24];
    418         wmake(h, 'xul:treecol', x);
    419         wmake(h, 'xul:splitter', { class : 'tree-splitter' });
    420       };
    421     };
    422   };
    423   wmake
    424   (w, 'xul:treechildren',
    425    { id : 'list-tree', 
    426      flex : 1, 
    427      contextmenu : 'relatedcontext' });
    428 };
    429 
    430 function initSettings() {
    431   ;
    432 };
    433 
    434 WHANDLER['on_domain_changed'] =
    435 function () {
    436   myProductLineController.update();
    437 };
    438 
    439 WHANDLER['on_catalog_changed'] =
    440 function () {
    441   myProductLineController.update();
    442 };
    443 
    444 WHANDLER['on_abort'] =
    445 function () {
    446   ;
    447 };
    448 
    449 WHANDLER['on_change_help_page'] =
    450 function () {
    451   var wframe = wget('help-iframe');
    452   var wlist = wget('help-list');
    453   wsetp(wframe, 'src', wgetp(wlist.selectedItem, 'value'));
    454 };
    455