/**
* Created by robin on 11/3/15.
*/
angular.module('luticateUtils')
.directive('luEditTable', ['dialogs', 'luticateDialogErrorHelper',
function(dialogs, luticateDialogErrorHelper) {
return {
restrict: 'E',
scope: {
options: '&'
},
templateUrl: "/luticate/lutable.html",
link: function ($scope, element, attrs) {
$scope.tableOptions = $scope.options();
if ($scope.tableOptions.onItemDeleted == null) {
$scope.tableOptions.onItemDeleted = function(item)
{
}
}
if ($scope.tableOptions.onItemEdited == null) {
$scope.tableOptions.onItemEdited = function(item)
{
}
}
if ($scope.tableOptions.onItemAdded == null) {
$scope.tableOptions.onItemAdded = function(item)
{
}
}
var onItemClicked = $scope.tableOptions.onItemClicked;
$scope.tableOptions.onItemClicked = function (item) {
if (onItemClicked != null) {
onItemClicked(item);
}
var ctrl = $scope.tableOptions.getEditController();
dialogs.create('views/modals/' + ctrl.toLowerCase() + '.html', ctrl + 'Controller', item)
.result.then(function (data) {
$scope.tableOptions.luBasicTableScope.loadPage($scope.tableOptions.page);
$scope.tableOptions.onItemEdited(data);
});
};
$scope.tableOptions.canCheck = $scope.tableOptions.canDelete;
$scope.tableOptions.canClick = $scope.tableOptions.canEdit;
$scope.deleteItems = function () {
if ($scope.tableOptions.checkedItems.length == 0) {
$scope.tableOptions.luBasicTableScope.loadPage($scope.tableOptions.page);
return;
}
var promiseDelItems = {
id: "promiseDelItems",
loaderGroups: [$scope.tableOptions.luBusy.group]
};
var item = $scope.tableOptions.checkedItems[0];
$scope.tableOptions.getDelPromise(item, promiseDelItems)
.then(function (data) {
$scope.tableOptions.onItemDeleted(item, $scope);
$scope.tableOptions.checkedItems.splice(0, 1);
$scope.deleteItems();
}, function (error) {
luticateDialogErrorHelper.errorDialog(error)
.result.then(function (data) {
$scope.tableOptions.luBasicTableScope.loadPage($scope.tableOptions.page);
}, function (error) {
});
});
};
$scope.addItem = function () {
var ctrl = $scope.tableOptions.getEditController();
dialogs.create('views/modals/' + ctrl.toLowerCase() + '.html', ctrl + 'Controller', null)
.result.then(function (data) {
$scope.tableOptions.luBasicTableScope.loadPage($scope.tableOptions.page);
$scope.tableOptions.onItemAdded(data);
});
};
}
};
}
]);
angular.module('luticateUtils').run(['$templateCache', function($templateCache)
{
$templateCache.put('/luticate/lutable.html',
'