Skip to content

Commit

Permalink
Добавление операции
Browse files Browse the repository at this point in the history
  • Loading branch information
PomanoB committed Feb 6, 2016
1 parent a3f0ae9 commit b262c03
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 2 deletions.
26 changes: 26 additions & 0 deletions server/controllers/baseoperations.js
Expand Up @@ -20,12 +20,14 @@ module.exports = {
model: null,
path: '',
searchColumns: null,
autoCompleteField: '',
registerRoutes: function(router)
{
assert(this.model);
assert(this.path);
router.get(this.path, makeQueryFunc(this.getList, this));
router.get(this.path + '/datatable', makeQueryFunc(this.dataTable, this));
router.get(this.path + '/autocomplete', makeQueryFunc(this.autocomplete, this));
router.get(this.path + '/:id', makeQueryFunc(this.getOne, this));
router.del(this.path + '/:id', makeQueryFunc(this.deleteOne, this));
router.post(this.path, koaBody, koaValidate, csrf.middleware, makeQueryFunc(this.add, this));
Expand Down Expand Up @@ -236,5 +238,29 @@ module.exports = {
};
return columnQuery;
}.bind(this));
},
autocomplete: function * ()
{
var query = this.req.query || {};
var term = query.term || '';
if (!term || !this.autoCompleteField)
{
this.req.body = [];
return;
}

var dbQuery = {
where: {},
limit: 10
};
dbQuery.where[this.autoCompleteField] = {
'$iLike': '%' + term.replace(/[%_]/g, '') + '%'
};
var rows = yield this.model.findAll(dbQuery);
this.req.body = rows.map((row) => this.autoCompleteResult(row));
},
autoCompleteResult: function(row)
{
return row.toJSON();
}
};
9 changes: 9 additions & 0 deletions server/controllers/subjects.js
Expand Up @@ -28,6 +28,15 @@ accounts.extractAddData = function(body)
type: body['type']
};
};
accounts.autoCompleteField = 'name';
accounts.autoCompleteResult = function(subject)
{
return {
id: subject.id,
label: subject.name,
value: subject.name
};
};
accounts.registerRoutes(router);

//router.get('/subjects', baseTable.display({
Expand Down
12 changes: 10 additions & 2 deletions web/src/jade/modules/main-menu.jade
Expand Up @@ -2,14 +2,22 @@ div(class='main__menu-header')
div(class='main__menu-header__collapse' title='Главное меню' data-bind-click='collapseMainMenu')
div(class='main__menu-header__title') Главное меню
ul(class='main__menu-list')
li(
data-bind-click='openNewTab',
data-tab-name='operation-add',
data-tab-label='Добавление операции',
data-template='operations-add',
data-post-init='initOperationsAdd'
)
span Добавить операцию
li(
data-bind-click='openNewTab',
data-tab-name='subjects',
data-tab-label='Субъекты',
data-template='subjects-list',
data-post-init='initDataTables bindClickView'
)

)
span Субъекты
li(
data-bind-click='openNewTab',
Expand Down
1 change: 1 addition & 0 deletions web/src/jade/modules/templates.jade
Expand Up @@ -2,3 +2,4 @@ include ../templates/subjects-list
include ../templates/subject-view
include ../templates/operations-list
include ../templates/operations-view
include ../templates/operations-add
16 changes: 16 additions & 0 deletions web/src/js/app.js
Expand Up @@ -59,6 +59,22 @@ window.Handlers = {
window.Handlers[binding.event][binding.func].apply(this, args);
});
});
},
initOperationsAdd: function(tabId)
{
var $tab = window.fin.$tabs.find('[id="' + tabId + '"]');
var autoCompleteFields = $tab.find('.autocomplete');
autoCompleteFields.each(function(index, field){
var url = $(field).data('autocompleteUrl');
$(field).autocomplete({
source: url,
minLength: 1,
select: function(event, ui){
var id = ui.item ? ui.item.id : -1;
$(this).data('autocompleteId', id);
}
});
});
}
},
click: {
Expand Down

0 comments on commit b262c03

Please sign in to comment.