Example #1
0
def print_headers():
    print '''Content-Type: text/html\n\n'''
    print '''<html><head>
    <title>Open Produce Item Manager</title>

    <link rel="stylesheet" type="text/css" href="../../common/tools.css" />
    <script type="text/javascript" src="../../common/jquery-1.3.2.min.js"></script>
    <script type="text/javascript" src="../../common/sorttable.js"></script>
    <script type="text/javascript" src="../../common/fix_table_headers.js"></script>
<script type="text/javascript">
function uncheckAllMulti(){
    $('.multi').each(function (){
         this.checked = false;
    });
}

function multiAddDist(){
   var selectedDist = $('#multi_dist').val();
   $('.multi:checked').each(function (){
       var id = this.id;
       $.post('update_distributor_item.py', {action: 'add', item: id, distid : selectedDist},
           function(data){
              if(data.indexOf('Error:') == -1){   // update text
                $.post('update_distributor_item.py', { action: 'query', item: id},
                  function(data){ 
                     $('#'+id+'_dist').html(data + ' &nbsp; ');
                   }, 'text');
               }
              else { alert(data); }
          },'text');
    });
}

function multiRemoveDist(){
   var selectedDist = $('#multi_dist').val();
   $('.multi:checked').each(function (){
       var id = this.id;
       $.post('update_distributor_item.py', {action: 'remove', item: id, distid : selectedDist},
           function(data){
              if(data.indexOf('Error:') == -1){   // update text
                $.post('update_distributor_item.py', { action: 'query', item: id},
                  function(data){  
                    $('#'+id+'_dist').html(data + ' &nbsp; ');
                  }, 'text');
               }
              else { alert(data); }
          },'text');
    });

}

function multiAddCategory(){
   var selectedCat = $('#multi_category').val();
   $('.multi:checked').each(function (){
      var itemid = this.id;
      $.post('update_category_item.py', {action : 'add', item_id: itemid, cat_id : selectedCat},
           function(data){
              if(data.indexOf('Error:') == -1){  // update text
                 $.post('update_category_item.py', { action: 'query', item: itemid},
                   function(data){
                     if (data.indexOf('Error:') == -1){
                       $('#'+itemid+'_cat').html(data + ' &nbsp; ');
                     }
                     else{
                        alert(data);
                     }
                  }, 'text');
             }   // end if no error returned by update_category_item - add
            else{ alert(data);}
           }, 'text');
   });
}

function multiRemoveCategory(){
   var selectedCat = $('#multi_category').val();
   $('.multi:checked').each(function (){
      var itemid = this.id;
      $.post('update_category_item.py', {action : 'remove_item_cat', item: itemid, catid : selectedCat},
           function(data){
              if(data.indexOf('Error:') == -1){  // update text
                 $.post('update_category_item.py', { action: 'query', item: itemid},
                   function(data){
                     if (data.indexOf('Error:') == -1){
                       $('#'+itemid+'_cat').html(data + ' &nbsp; ');
                     }
                     else{
                        alert(data);
                     }
                  }, 'text');
             }   // end if no error returned by update_category_item - add
            else{ alert(data);}
           }, 'text');
   });
}

function multiSetTaxCategory(){
   var selectedTaxCat = $('#multi_tax_category').val();
   $('.multi:checked').each(function (){
      var itemid = this.id;
   $.post('update_tax_categories.py', {action: 'set-item', item_id: itemid, taxcatid: selectedTaxCat},
        function(data){
           if(data.indexOf('Error:') == -1) {   // set text
             $.post('update_tax_categories.py', {action: 'query-item', item_id: itemid},
               function(data){
                  $('#'+itemid+'_tax').html(data + ' &nbsp; ');
               }, 'text');
           }
           else{
               alert(data);
           }
        }, 'text');
   });
}

function updateDistributorItemInfo(itemid, d_id){
   cu = $('#'+itemid+'_'+d_id+'_caseUnits').val();
   cs = $('#'+itemid+'_'+d_id+'_caseSize').val();
   p = $('#'+itemid+'_'+d_id+'_price').val();
   di = $('#'+itemid+'_'+d_id+'_distItemId').val();
   
   $.post('update_distributor_item.py', { action: 'update', item: itemid, distid: d_id, distitemid: di, price: p, casesize: cs, caseunit: cu },
       function () {alert('Update succesful');}, 'text');

}

function updateTaxCategory(id) {
   var selectedTaxCat = $('#'+id+'_taxSelect').val();
   $.post('update_tax_categories.py', {action: 'set-item', item_id: id, taxcatid: selectedTaxCat},
        function(data){
           if(data.indexOf('Error:') == -1) {
               alert('Succesfully updated');
           }
           else{
               alert(data);
           }
        }, 'text');
}

function discontinueItem(ckbox){
   var itemid = parseInt(ckbox.id);
   $.post('update_item.py', { action: 'status', id: itemid, stocked: ckbox.checked},
       function(data){
       }, 'text');
}

$(document).ready(function() {
   $('.th').each(
      function(idx, th) {
        var width = $('#item-stats').children(':first').children().eq(idx).css('width');
        $(th).css('width',width);
      }
   );


   $('.itemname').keypress(function(e) {
       if (e.which == 13) {
            var itemid = parseInt(this.id);
            var newname = this.value;
            name_box = this;
            name_box.disabled = true;
            $(name_box).removeClass('default').removeClass('complete').addClass('submitting');

            $.post('update_item.py', {action:'name', id : itemid, name : newname},
               function(data){
                  name_box.disabled = false;
                  if(data.indexOf('Error:') == -1) {
                     $(name_box).removeClass('default').removeClass('submitting').addClass('complete');      
                  }
                  else { alert(data);}
               }, 'text');

       }
   });

   $('.itembarcode').keypress(function(e) {
       if (e.which == 13) {
            var ids = this.id.split("_");
            var itemid = parseInt(ids[0]);
            var oldbc = ids[1];
            var newbc = this.value;

            bc_box = this;
            bc_box.disabled = true;
            $(bc_box).removeClass('default').removeClass('complete').addClass('submitting');
            $.post('update_item.py', {action:'barcode', id : itemid, newbarcode : newbc, oldbarcode : oldbc},
               function(data){
                  bc_box.disabled = false;
                  if(data.indexOf('Error:') == -1) {
                      bc_box.id = itemid + "_" + newbc + "_" + "bc";                      
                      $(bc_box).removeClass('default').removeClass('submitting').addClass('complete');
                  }
                  else { alert(data);}
               }, 'text');

       }
   });

});
</script>
'''
    idf.print_javascript()
    print '''</head>'''
Example #2
0
def print_headers():
    print '''Content-Type: text/html\n\n'''
    print '''<html><head>
    <title>Open Produce Price Manager</title>

    <link rel="stylesheet" type="text/css" href="../../common/tools.css" />
    <script type="text/javascript" src="../../common/jquery-1.3.2.min.js"></script>\n
    <script type="text/javascript" src="../../common/sorttable.js"></script>\n
    <script type="text/javascript" src="../../common/fix_table_headers.js"></script>
<script type="text/javascript">'''
    # The following is just to remove whitespace and &nbsp's from stuff
    print '''
    function trim(str) {
       return str.replace(/^[\s]+/g,'').replace(/[\s]+$/g,'');
    }'''
    # The following array is needed so that the when an item is split it will have the dropdown to change sale units
    print '''units = new Array();'''
    for i,unit in enumerate(db.get_units()):
        print '''units[%d] = '%s';''' % (i, str(unit))

    print '''
    function handlePriceChange(e){
		if (e.which == 13) {
                     var p_id = parseInt(this.id);
                     price_box = this;
                     price_box.disabled = true;
                    $(price_box).removeClass('default').removeClass('complete').addClass('submitting');
                        $.post('update_prices.py', {action: 'price', price_id: p_id, price: this.value},
                           function(data){
                              price_box.disabled = false;
                              if(data.indexOf('Error:') != -1){
                                  alert(data);
                              }
                              else{
                                 updateMargins(p_id);
                                 $(price_box).removeClass('default').removeClass('submitting').addClass('complete');
                              }
                           }, 'text');
		}
        }

   function discontinueItem(ckbox){
      var itemid = parseInt(ckbox.id);
      $.post('update_item.py', { action: 'status', id: itemid, stocked: ckbox.checked},
         function(data){
         }, 'text');
   }
  
    function handleGroupChange(e){
                if (e.which == 13) {
                   var item = parseInt(this.id);
                   var newid = parseInt(this.value);
                   $.post('update_prices.py', {action : 'group', item_id : item, price_id : this.value},
                     function(data){
                       if(data.indexOf('Error:') == -1){
                       // data contains old_price_id, [1] is the number of items with a given price
                         data = data.split(',');    
                         updateRows(item,data,newid);
                       }
                       else{
                         alert(data);
                       }
                       $('#'+item+'_group').val('');
                     }, 'text');
                }

    }

    function handleAmtChange(e){
		if (e.which == 13) {
			var id = parseInt(this.name);
                        $('#'+id+'_in').attr('disabled', 'true');
                        $('#'+id+'_in').removeClass('default').removeClass('complete').addClass('submitting');
                        var delivery_amt = $(this).val();
      		        $('#'+id+'_in').val('');
			$.post('update_item.py', { action: 'delivery', id: id, amt: delivery_amt, dist: $('#'+id+'_dist_in').val() },
			       function(data) {
                                   $('#'+id+'_in').removeAttr('disabled');
                                   if (data.indexOf('Error:') != -1){alert(data);}
                                   else{
                                        $('#'+id+'_in').removeClass('default').removeClass('submitting').addClass('complete');
                                        if (data != ''){
					    $('#'+id+'_amt').html(data);
                                        }
                                        day14 = parseFloat($('#tr_'+id).attr('title'))
                                         
                                    }
				}, 'text');
                         
		}
    }

    function handleDItemChange(e){
        if (e.which == 13) {
           var ids = this.id.split('_');
           var item = parseInt(ids[0]);
           var dist = parseInt(ids[1]);
           var newvalue = this.value;
           ditem_box = this;
           ditem_box.disabled = true;
           $(ditem_box).removeClass('default').removeClass('complete').addClass('submitting');

           $.post('update_distributor_item.py', {action:'update', item : item, distid : dist, distitemid : newvalue},
             function(data){
                 ditem_box.disabled = false;
                 if(data.indexOf('Error:') == -1) {
                    $(ditem_box).removeClass('default').removeClass('submitting').addClass('complete');
                 }
                 else { alert(data);}
             }, 'text');
          }
    }

    function handleCaseSizeChange(e){
                if (e.which == 13) {
                   var ids = this.id.split('_');
                   var item = parseInt(ids[0]);
                   var dist = parseInt(ids[1]);
                   var price = parseInt(ids[2]);
                   var newvalue = parseFloat(this.value);
                   ditem_box = this;
                   ditem_box.disabled = true;
                   $(ditem_box).removeClass('default').removeClass('complete').addClass('submitting');

                   $.post('update_distributor_item.py', {action:'update', item : item, distid : dist, casesize : newvalue},
                      function(data){
                         ditem_box.disabled = false;
                         if(data.indexOf('Error:') == -1) {
                            $(ditem_box).removeClass('default').removeClass('submitting').addClass('complete');
                            updateMargins(price);
                         }
                         else { alert(data);}
                      }, 'text');
            } 
    }

    function handleCaseCostChange(e){
                if (e.which == 13) {
                   var ids = this.id.split('_');
                   var item = parseInt(ids[0]);
                   var dist = parseInt(ids[1]);
                   var price = parseFloat(ids[2]);
                   var newvalue = parseFloat(this.value);
                   ditem_box = this;
                   ditem_box.disabled = true;
                   $(ditem_box).removeClass('default').removeClass('complete').addClass('submitting');

                   $.post('update_distributor_item.py', {action:'update', item : item, distid : dist, price : newvalue},
                      function(data){
                         ditem_box.disabled = false;
                         if(data.indexOf('Error:') == -1) {
                             $(ditem_box).removeClass('default').removeClass('submitting').addClass('complete'); 
                             updateMargins(price);
                         }
                         else { alert(data);}
                      }, 'text');
            }
    }

    // This takes the data list returned from update_prices.py and the new price id
    function updateRows(item, data, newid) {
        if ($('#'+newid+'_table').length == 0){   // price_id row is not currently displayed so make it
           var newrow = '<tr id="'+newid+'_price"><td class="td">'+newid+'</td>';
           newrow += '<td class="td">$<input type="text" class="price" id="'+newid+'_price_input" size="3" value="'+trim(data[2])+'"></input></td>';
           newrow += '<td><select class="saleunit" id="'+newid+'_sale_unit" onChange="setPriceSaleUnit('+newid+')">';
           for (var i=0; i<units.length; i++){
             newrow += '<option value="'+units[i]+'"';
             if (units[i] == trim(data[4])){
                newrow += 'selected';
             }
             newrow+= '>' +units[i] +'</option>';
           }
           newrow += '</select></td>';

           newrow += '<td ''',
    print '''colspan="%d" class="td"> <table id="'+newid+'_table" cellspacing=0 cellpadding=0></table></td></tr>' ''' % (colspan)
    print '''
           $('#main').append(newrow);
           $('.price').keypress(handlePriceChange);
         }
         $('#'+newid+'_table').append($('.'+item+'_tr'));
                        
        updateMargins(newid);

        if (parseInt(data[1]) == 0){
            $('#'+data[0]+'_price').remove();
        }
    }

    function setPriceSaleUnit(priceid){
          var selected = $('#'+priceid+'_sale_unit :selected').text();
          $.post('update_prices.py', {action:'sale_unit', price_id:priceid, unit_name : selected},
            function(data){
               if(data.indexOf('Error:') == -1) {
               }
               else { alert(data);}
            }, 'text');
    }
 
    function updateMargins(price){
        $.post('update_prices.py', {action: 'query', price_id: price},
            function(data){                                 
               if(data.indexOf('Error:') != -1){
                   alert(data);
               }
               else{
                  var rows = data.split("\\n");
                  for(var i=0; i<rows.length; i++){
                      var cols = rows[i].split(',');
                      var tagPrefix = "#" + cols[0] + '_' + cols[1] +'_';
                      $(tagPrefix+'each').text('$'+cols[2]);
                      $(tagPrefix+'margin').text(cols[3]+'%');
                      var margin = parseInt(cols[3]);
                      if(margin <= 20){
                         $(tagPrefix+'margin').attr('class','bad');
                      } else if(margin <= 30) {
                         $(tagPrefix+'margin').attr('class','mid');
                      } else{
                         $(tagPrefix+'margin').attr('class','good');                 
                      }
                   }
               }
            }, 'text');

    }

    function split(item) {
        if (!confirm("Are you sure you want to split item "+item+" from its current price group?")) { return;}
        $.post('update_prices.py', {action : 'split', item_id: item},
          function(data){
            if(data.indexOf('Error:') == -1){
               // data contains old_price_id, [1] is the number of items with a given price
               data = data.split(',');    
               newid = parseInt(data[3]);
               updateRows(item, data, newid);
            }
            else{
              alert(data);
            }
           }, 'text');
    }


    $(document).ready(function() {
        $('.th').each(
          function(idx, th) {
            var width = 0;
            if (idx < 3) {
              width = $('#item-stats').children(':first').children().eq(idx).css('width');
            }
            else {
              // Since we have a table within the first table (at idx 3) we need to get a child from that table 
              width = $('.inner_table:first').children(':first').children().eq(idx-3).css('width');
            }
            $(th).css('width',width);
          }
        );

        $('.ditemid').keypress(handleDItemChange);
        $('.casesize').keypress(handleCaseSizeChange);
        $('.casecost').keypress(handleCaseCostChange);
        $('.group').keypress(handleGroupChange);
	$('.price').keypress(handlePriceChange);
	$('.amt').keypress(handleAmtChange);
 });


</script>
'''
    idf.print_javascript()
    print '''
Example #3
0
def print_headers():
    print '''Content-Type: text/html\n\n'''
    print '''<html><head>
    <title>Open Produce Catalog</title>

    <link rel="stylesheet" type="text/css" href="../../common/tools.css" />
    <script type="text/javascript" src="../../common/jquery-1.3.2.min.js"></script>\n
    <script type="text/javascript" src="../../common/sorttable.js"></script>\n
    <script type="text/javascript" src="../../common/fix_table_headers.js"></script>
<script type="text/javascript">
function discontinueItem(ckbox){
   var itemid = parseInt(ckbox.id);
   $.post('update_item.py', { action: 'status', id: itemid, stocked: ckbox.checked},
       function(data){
       }, 'text');
}

$(document).ready(function() {
	$('.count').keypress(function(e) {
		if (e.which == 13) {
 			var id = parseInt(this.id);
                        $('[id^='+id+'_count_]').removeClass('default').removeClass('complete').addClass('submitting');
                        $('[id^='+id+'_count_]').attr('disabled','true');

			$.post('update_item.py', { action: 'count', id: id, count: $(this).val(), exp_date: $('#exp_date').val() },
			       function(data) {
                                        if (data != ''){
                                            data = data.split(',');
					    $('[id^='+id+'_amt_]').html(data[1]);
                                            $('[id^='+id+'_spec_]').html(data[0]);
                                        }
					$('[id^='+id+'_count_]').val('');
                                        day14 = parseFloat($('#tr_'+id).attr('title'))  // using just one is fine here

					if (parseFloat(data[1]) < -10) {
						$('[id^=tr_'+id+'_]').attr('class','na');
					} else if (parseFloat(data[1]) < 0) {
						$('[id^=tr_'+id+'_]').attr('class','bad');
					} else if (parseFloat(data[1]) < 1) {
						$('[id^=tr_'+id+'_]').attr('class','out');
					} else if (parseFloat(data[1]) < day14){
						$('[id^=tr_'+id+'_]').attr('class','low');
					} else {
						$('[id^=tr_'+id+'_]').attr('class','');
                                        }

                                        $('[id^='+id+'_count_]').removeClass('default').removeClass('submitting').addClass('complete');
                                        $('[id^='+id+'_count_]').removeAttr('disabled');
				}, 'text');
		}
	});

        $('.th').each(
          function(idx, th) {
            var width = $('#item-stats').children(':first').children().eq(idx).css('width');
            $(th).css('width',width);
          }
        );
});

</script>
'''
    idf.print_javascript()
    print '''