Commit 7fb39794 authored by Evren Kutar's avatar Evren Kutar

quick add widget for listnodes

rfix #5269
parent 287e49d0
/**
* Copyright (C) 2015 ZetaOps Inc.
*
* This file is licensed under the GNU General Public License v3
* (GPLv3). See LICENSE.txt for details.
*
* @author Evren Kutar
*/
angular.module('ulakbus.crud')
.directive('quickAdd', function (Generator) {
return {
templateUrl: 'components/crud/templates/quick_add.html',
restrict: 'E',
replace: true,
scope: {
node: '='
},
controller: function ($scope) {
$scope.kw = '';
$scope.getTitleMap = function () {
return $scope.generateTitleMap($scope.kw);
};
$scope.generateTitleMap = function (kw) {
var searchData = {
form_params: {
model: $scope.node.quick_add_model,
wf: 'crud',
query: kw,
cmd: 'object_search'
}
};
if (angular.isDefined($scope.$parent.form_params.param)){
searchData.form_params['id'] = $scope.$parent.form_params.id;
}
return Generator.get_list(searchData).then(function (res) {
var titleMap = [];
angular.forEach(res.objects, function (item) {
titleMap.push({
"value": item[0],
"name": item[1]
});
});
return titleMap;
});
};
$scope.onSelect = function (item) {
// add to listnode here
// field default is node schema properties first index
var get_first_key = function () {
return Object.keys($scope.node.schema.properties)[0];
};
var field = $scope.node.quick_add_field || get_first_key();
var f = { key: item.value};
f[field] = item.name;
// loop item keys and if a key not found in f add it with no value
angular.forEach($scope.node.items[0], function (value, key) {
if (!angular.isDefined(f[key])) {
f[key] = undefined;
}
});
try {
angular.forEach($scope.node.items, function (value, key) {
if (value['key'] === item.value) {
throw Error();
}
});
$scope.node.model.push(f);
$scope.node.items.push(f);
} catch (e) {
alert('bu öğe listede zaten mevcut!!');
}
}
}}
});
\ No newline at end of file
...@@ -20,11 +20,12 @@ ...@@ -20,11 +20,12 @@
</div> </div>
<div ng-repeat="node in ListNode"> <div ng-repeat="node in ListNode">
<h3>{{ node.title }} <h3>{{ node.title }}
<span ng-if="meta.allow_add_listnode !== false"> <span ng-if="meta.allow_add_listnode !== false" ng-hide="node.quick_add === true">
<a modal-for-nodes="{{node.schema.model_name}},ListNode,add"> <a modal-for-nodes="{{node.schema.model_name}},ListNode,add">
<i class="fa fa-plus-circle fa-fw"></i> <i class="fa fa-plus-circle fa-fw"></i>
</a> </a>
</span> </span>
<quick-add node="node" ng-if="node.quick_add === true"></quick-add>
</h3> </h3>
<div class="list-node-table" ng-if="!meta.translate_widget"> <div class="list-node-table" ng-if="!meta.translate_widget">
......
...@@ -66,7 +66,8 @@ ...@@ -66,7 +66,8 @@
</td> </td>
<td ng-if="meta.allow_actions!==false"> <td ng-if="meta.allow_actions!==false">
<div ng-hide="meta.object_actions.length > 0"> <div ng-hide="meta.object_actions.length > 0">
<span modal-for-nodes="{{node.schema.model_name}},{{node.schema.formType}},edit,{{$index}}"> <span modal-for-nodes="{{node.schema.model_name}},{{node.schema.formType}},edit,{{$index}}"
ng-hide="node.quick_add === true">
<i class="fa fa-pencil-square-o fa-fw"></i> <i class="fa fa-pencil-square-o fa-fw"></i>
</span> </span>
<span ng-click="remove(node, 'ListNode', $index)"><i class="fa fa-times fa-fw"></i></span> <span ng-click="remove(node, 'ListNode', $index)"><i class="fa fa-times fa-fw"></i></span>
......
<div>
<input class="form-control"
type="text"
placeholder="eklemek istediğiniz nesneyi yazınız..."
ng-model="kw"
uib-typeahead="item as item.name for item in getTitleMap($viewValue)"
typeahead-on-select="onSelect($item)"
typeahead-loading="loadingTitleMap" typeahead-no-results="noResults"
typeahead-wait-ms="500"/>
<div ng-show="loadingTitleMap" class="loader"></div>
<div ng-show="noResults">
<i class="fa fa-close"></i> bulunamadı.
</div>
</div>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment