-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
146 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
function BudgetViewModel(o, period) { | ||
var self = this; | ||
if (!o) o = {}; | ||
|
||
self.overallTotal = ko.observable(0.0); | ||
|
||
var headerArr = []; | ||
for (i = 0; i < period.length; i++) { | ||
headerArr.push({"data": period[i]}); | ||
} | ||
self.headers = ko.observableArray(headerArr); | ||
|
||
var row = []; | ||
o.rows ? row = o.rows : row.push(ko.mapping.toJS(new BudgetRowViewModel({}, period))); | ||
self.rows = ko.observableArray($.map(row, function (obj, i) { | ||
// Headers don't match with previously stored headers, adjust rows accordingly. | ||
if (o.headers && period && o.headers.length != period.length) { | ||
var updatedRow = []; | ||
for (i = 0; i < period.length; i++) { | ||
var index = -1; | ||
|
||
for (j = 0; j < o.headers.length; j++) { | ||
if (period[i] == o.headers[j].data) { | ||
index = j; | ||
break; | ||
} | ||
} | ||
updatedRow.push(index != -1 ? obj.costs[index] : 0.0) | ||
index = -1; | ||
} | ||
obj.costs = updatedRow; | ||
} | ||
|
||
return new BudgetRowViewModel(obj, period); | ||
})); | ||
|
||
self.overallTotal = ko.computed(function () { | ||
var total = 0.0; | ||
ko.utils.arrayForEach(this.rows(), function (row) { | ||
if (row.rowTotal()) { | ||
total += parseFloat(row.rowTotal()); | ||
} | ||
}); | ||
return total; | ||
}, this).extend({currency: {}}); | ||
|
||
var allBudgetTotal = []; | ||
for (i = 0; i < period.length; i++) { | ||
allBudgetTotal.push(new BudgetTotalViewModel(this.rows, i)); | ||
} | ||
self.columnTotal = ko.observableArray(allBudgetTotal); | ||
|
||
self.addRow = function () { | ||
self.rows.push(new BudgetRowViewModel({}, period)); | ||
} | ||
}; | ||
|
||
function BudgetTotalViewModel(rows, index) { | ||
var self = this; | ||
self.data = ko.computed(function () { | ||
var total = 0.0; | ||
ko.utils.arrayForEach(rows(), function (row) { | ||
if (row.costs()[index]) { | ||
total += parseFloat(row.costs()[index].dollar()); | ||
} | ||
}); | ||
return total; | ||
}, this).extend({currency: {}}); | ||
}; | ||
|
||
|
||
function BudgetRowViewModel(o, period) { | ||
var self = this; | ||
if (!o) o = {}; | ||
if (!o.activities || !_.isArray(o.activities)) o.activities = []; | ||
self.shortLabel = ko.observable(o.shortLabel); | ||
self.description = ko.observable(o.description); | ||
self.activities = ko.observableArray(o.activities); | ||
|
||
var arr = []; | ||
// Have at least one period to record, which will essentially be a project total. | ||
var minPeriods = _.max([1, period.length]); | ||
for (var i = 0; i < minPeriods; i++) { | ||
arr.push(ko.mapping.toJS(new FloatViewModel())); | ||
} | ||
|
||
if (o.costs && o.costs.length != arr.length) { | ||
o.costs = arr; | ||
} | ||
o.costs ? arr = o.costs : arr; | ||
self.costs = ko.observableArray($.map(arr, function (obj, i) { | ||
return new FloatViewModel(obj); | ||
})); | ||
|
||
self.rowTotal = ko.computed(function () { | ||
var total = 0.0; | ||
ko.utils.arrayForEach(this.costs(), function (cost) { | ||
if (cost.dollar()) | ||
total += parseFloat(cost.dollar()); | ||
}); | ||
return total; | ||
}, this).extend({currency: {}}); | ||
}; | ||
|
||
function FloatViewModel(o) { | ||
var self = this; | ||
if (!o) o = {}; | ||
self.dollar = ko.observable(o.dollar ? o.dollar : 0.0).extend({numericString: 2}).extend({currency: {}}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<!-- ko with:reportingTargetsAndFunding().funding --> | ||
<div class="funding"> | ||
|
||
<label><b>Funding</b><fc:iconHelp title="Project Budget">${budgetHelpText?:"Enter the budget as reviewed each year"}</fc:iconHelp></label> | ||
<g:if test="${explanation}"> | ||
<p>${explanation}</p> | ||
</g:if> | ||
<table class="table"> | ||
<thead> | ||
<tr> | ||
<!-- ko foreach: headers --> | ||
<th class="budget-amount"><div data-bind="text:data.label"></div>$</th> | ||
<!-- /ko --> | ||
|
||
</tr> | ||
</thead> | ||
<tbody data-bind="foreach : rows"> | ||
<tr> | ||
<!-- ko foreach: costs --> | ||
<td class="budget-amount"> | ||
<input type="number" class="form-control form-control-sm" data-bind="value: dollar, numeric: $root.number, disable: $root.isProjectDetailsLocked()" data-validation-engine="validate[custom[number]]"/> | ||
</td> | ||
<!-- /ko --> | ||
</tr> | ||
</tbody> | ||
</table> | ||
|
||
</div> | ||
<!-- /ko --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters