Commits

singli committed cd9fc51

update sales and sales_nologin project to handle Template.rendered only firing once

Comments (0)

Files changed (4)

sales/client/sales.html

           </div>
           <div class="span5">
             <div style="float: right">
-              {{loginButtons align="right"}}
+              {{>loginButtons align="right"}}
             </div>
           </div>
     </div>
       {{/if}}
   	</div>
   	<div id="chart">
+      
   	</div>
   </div>
   
 </body>
 
+
+
 <template name="salesdata">
   <div class="salesdata">
     {{#each dataset}}

sales/client/sales.js

     }
   };
 
-Template.salesdata.rendered = function()
-{
- 
-  $('.editable').editable(function(value, settings) { 
-     console.log(this);
-     console.log(value);
-     console.log(settings);
-     Sales2013.update(Session.get("selected_datapoint"), {$set: {total: parseInt(value)}});
-     return(value);
-  }, { 
-     type    : 'text',
-     style : 'inherit',
-     width : 100,
-     submit  : 'OK',
+function setDeps ()  {
+ Deps.autorun(function()  {
+ plotit(Sales2013.find({}));
  });
+}
+
 
-     var cur = Sales2013.find();
-     if (cur.count() === 0)  // do not render pie if no data
+function plotit(cur)  {
+ if (cur.count() === 0)  // do not render pie if no data
        return;
      var data = [];
      cur.forEach( function(sale) {
        data.push( [sale.region, sale.total]);
      });
-
-  var plot1 = $.jqplot ('chart', [data], 
+  plot1 = $.jqplot ('chart', [data], 
     { 
       seriesDefaults: {
         // Make this a pie chart.
         }
       }, 
       legend: { show:true, location: 'e' }
-    });   
-};
+    }
+  );   
+
+}
+
+Template.salesdata.rendered = function()
+{
+ 
+  $('.editable').editable(function(value, settings) { 
+     console.log(this);
+     console.log(value);
+     console.log(settings);
+     Sales2013.update(Session.get("selected_datapoint"), {$set: {total: parseInt(value)}});
+     return(value);
+  }, { 
+     type    : 'text',
+     style : 'inherit',
+     width : 100,
+     submit  : 'OK',
+ });
+ 
+ plotit(Sales2013.find({}));
+
+ 
+setDeps();
+
+
+}
 

sales_nologin/sales.html

     	{{> salesdata}}
   	</div>
   	<div id="chart">
-  	</div>
+    </div>
+
+    
   </div>
   
 </body>
 
+
 <template name="salesdata">
   <div class="salesdata">
     {{#each dataset}}

sales_nologin/sales.js

     return Sales2013.find({});
   };
 
+
   Template.datapoint.selected = function () {
     return Session.equals("selected_datapoint", this._id) ? "selected" : '';
   };
     }
   };
 
-Template.salesdata.rendered = function()
-{
- 
-  $('.editable').editable(function(value, settings) { 
-     console.log(this);
-     console.log(value);
-     console.log(settings);
-     Sales2013.update(Session.get("selected_datapoint"), {$set: {total: parseInt(value)}});
-     return(value);
-  }, { 
-     type    : 'text',
-     style : 'inherit',
-     width : 100,
-     submit  : 'OK',
+function setDeps ()  {
+ Deps.autorun(function()  {
+ plotit(Sales2013.find({}));
  });
+}
+
 
-     var cur = Sales2013.find();
-     if (cur.count() === 0)  // do not render pie if no data
+function plotit(cur)  {
+ if (cur.count() === 0)  // do not render pie if no data
        return;
      var data = [];
      cur.forEach( function(sale) {
        data.push( [sale.region, sale.total]);
      });
-  
-  var plot1 = $.jqplot ('chart', [data], 
+  plot1 = $.jqplot ('chart', [data], 
     { 
       seriesDefaults: {
         // Make this a pie chart.
       legend: { show:true, location: 'e' }
     }
   );   
+
 }
 
+Template.salesdata.rendered = function()
+{
+ 
+  $('.editable').editable(function(value, settings) { 
+     console.log(this);
+     console.log(value);
+     console.log(settings);
+     Sales2013.update(Session.get("selected_datapoint"), {$set: {total: parseInt(value)}});
+     return(value);
+  }, { 
+     type    : 'text',
+     style : 'inherit',
+     width : 100,
+     submit  : 'OK',
+ });
+ 
+ plotit(Sales2013.find({}));
+
+ 
+setDeps();
+
+
 }
 
+}  // if client
+
 if (Meteor.isServer) {
   Meteor.startup(function () {
       Sales2013.remove({});