Added categories suggestions on editing. Closes #3.

This commit is contained in:
Alexis Lahouze 2013-01-25 00:13:03 +01:00
parent 4dfa6ec279
commit c7245581e3
2 changed files with 36 additions and 2 deletions

View File

@ -157,7 +157,7 @@
<td><input type="text" class="input-mini" data-bind="value: value"/></td> <td><input type="text" class="input-mini" data-bind="value: value"/></td>
<td></td> <td></td>
<td></td> <td></td>
<td><input type="text" class="input-small" data-bind="value: category"/></td> <td><input type="text" class="input-small" data-bind="value: category, typeahead: {source: $root.categories }"/></td>
<td class="buttons"> <td class="buttons">
<a class="btn btn-mini btn-success" data-bind="click: $root.save" href="#" title="save"><i class="icon-plus"></i></a> <a class="btn btn-mini btn-success" data-bind="click: $root.save" href="#" title="save"><i class="icon-plus"></i></a>
<a class="btn btn-mini" data-bind="click: $root.cancel" href="#" title="cancel"><i class="icon-remove"></i></a> <a class="btn btn-mini" data-bind="click: $root.cancel" href="#" title="cancel"><i class="icon-remove"></i></a>
@ -174,7 +174,7 @@
<td><input type="text" class="input-mini" data-bind="value: value"/></td> <td><input type="text" class="input-mini" data-bind="value: value"/></td>
<td data-bind="text: sold"></td> <td data-bind="text: sold"></td>
<td data-bind="text: pointedsold"></td> <td data-bind="text: pointedsold"></td>
<td><input type="text" class="input-small" data-bind="value: category"/></td> <td><input type="text" class="input-small" data-bind="value: category, typeahead: {source: $root.categories }" /></td>
<td class="buttons"> <td class="buttons">
<a class="btn btn-mini btn-success" data-bind="click: $root.save" href="#" title="save"><i class="icon-ok"></i></a> <a class="btn btn-mini btn-success" data-bind="click: $root.save" href="#" title="save"><i class="icon-ok"></i></a>
<a class="btn btn-mini" data-bind="click: $root.cancel" href="#" title="cancel"><i class="icon-ban-circle"></i></a> <a class="btn btn-mini" data-bind="click: $root.cancel" href="#" title="cancel"><i class="icon-ban-circle"></i></a>

View File

@ -151,6 +151,22 @@ var ListViewModel = function() {
}); });
}; };
self.categories = ko.computed(function() {
var unwrap = ko.utils.unwrapObservable;
var entries=unwrap(self.entries);
var categories = ko.observableArray([]);
$.each(entries, function(index, entry) {
if(entry.category() && entry.category() != '' && categories.indexOf(entry.category()) == -1) {
categories.push(entry.category());
}
});
return categories();
});
// Returns the data for the categories by summing values with same category // Returns the data for the categories by summing values with same category
self.expenseCategoriesChart = ko.computed(function() { self.expenseCategoriesChart = ko.computed(function() {
var unwrap = ko.utils.unwrapObservable; var unwrap = ko.utils.unwrapObservable;
@ -620,6 +636,24 @@ $(document).ajaxError(function(event, xhr, settings) {
message("error", xhr.statusText, xhr.responseText); message("error", xhr.statusText, xhr.responseText);
}); });
// Bootstrap.Typeahead binding.
// Use like so: data-bind="typeahead: { source: namespaces }"
ko.bindingHandlers.typeahead = {
init: function(element, valueAccessor, allBindingsAccessor, viewModel) {
$(element).typeahead({
source: function() { return ko.utils.unwrapObservable(valueAccessor().source); },
onselect: function(value) { allBindingsAccessor().value(value); }
});
},
update: function(element, valueAccessor, allBindingsAccessor, viewModel) {
$(element).typeahead({
source: function() { ko.utils.unwrapObservable(valueAccessor().source); },
onselect: function(value) { allBindingsAccessor().value(value); }
});
}
};
// Resize callback. // Resize callback.
$(window).resize(function() { $(window).resize(function() {
if(window.chart) { if(window.chart) {