Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You should use the <em>new</em> keyword when initailizing the object if you want to use <em>this</em>:</p> <pre><code>$.pcw.outstandingInvoices = function(){ var context = this;//replace every instance of "this" in your class with the context var context.init= function () { console.log('Initializing outstandingInvoices class.'); context.loadData(); } //the rest of functions defined below } var invoices = new $.pcw.outstandingInvoices(); invoices.init(); </code></pre> <p>Edit: to fix the remaining errors try using context instead of self, and declare outstandingInvoicesObject on the context:</p> <pre><code>$.pcw.outstandingInvoices = function () { var context = this; context.outstandingInvoicesObject = []; context.init = function () { console.log('Initializing outstandingInvoices class.'); context.loadData(); }; context.loadData = function () { console.log('Loading outstanding invoices from server.'); jQuery.getJSON('/ajax/outgoing-invoices/find-outstanding.json', function (data) { jQuery.each(data, function (key, entry) { context.outstandingInvoicesObject[key] = entry; }); //now that we have data, call add the invoices to the table context.removeLoader(); context.addOutstandingInvoicesToTable(); }).error(function () { console.error('Error while loading outstanding invoices.'); }); }; context.removeLoader = function () { jQuery('table#invoices-outstanding tr.ajax-loader').fadeOut(); }; context.addOutstandingInvoicesToTable = function() { if (context.outstandingInvoicesObject.length == 0) { console.log('No outstanding invoices found'); } jQuery.each(context.outstandingInvoicesObject, function (key, entry) { // This is a new outstanding invoice var rowClass = 'info'; switch(entry.status) { case 'Created': case 'Sent': case 'Paid': // The invoices with Paid statuses aren't show here, because we only show the oustanding invoices on this page. rowClass = 'success'; break; case 'First reminder': case 'Second reminder': case 'Partially paid': rowClass = 'warning'; break; case 'Third reminder': case 'Collection agency': case 'Judicial proceedings': rowClass = 'error'; break; } jQuery('table#invoices-outstanding tbody').append( outstandingInvoice = jQuery('&lt;tr/&gt;', { id: 'outgoing-invoice-' + key, class: rowClass }).append( jQuery('&lt;td/&gt;', { class: 'id', text: key }) ).append( jQuery('&lt;td/&gt;', { class: 'debtor-name', text: entry.debtor_name }) ).append( jQuery('&lt;td/&gt;', { class: 'amount', text: entry.amount }) ).append( jQuery('&lt;td/&gt;', { class: 'date', text: entry.created_timestamp }) ).append( jQuery('&lt;td/&gt;', { class: 'status', text: entry.status }) ).append( jQuery('&lt;td/&gt;', { class: 'creator', text: entry.creator }) ) ); }); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload