Commit b9055e46 authored by Evren Kutar's avatar Evren Kutar

record linkedmodel data when clicked on plus icon

open modal and return to form with new objects
parent 50a15184
......@@ -50,74 +50,9 @@ var app = angular.module(
sessionTimeout: 'auth-session-timeout',
notAuthenticated: 'auth-not-authenticated',
notAuthorized: 'auth-not-authorized'
}).
/**
* Directive to highlight current menu item
*/
// todo: not working properly, get it done!
directive('activeLink', ['$location', function ($location) {
return {
restrict: 'A',
link: function ($scope, $element, $attrs) {
var clazz = $attrs.activeLink;
var path = $location.path();
path = path //hack because path does not
// return including hashbang
$scope.location = $location;
$scope.$watch('location.path()', function (newPath) {
if (path === newPath) {
$element.addClass(clazz);
} else {
$element.removeClass(clazz);
}
});
}
};
}]).
/**
* logout directive
*/
directive('logout', function ($http, $location) {
return {
link: function ($scope, $element, $rootScope) {
$element.on('click', function () {
$http.post('http://' + window.location.hostname + ':9001/logout', {}).then(function () {
$rootScope.loggedInUser = false;
console.log($rootScope.loggedInUser);
$location.path("/login");
$scope.$apply();
});
});
}
}
});
// buildbot mailnotifier change on master mail test comment (will be deleted)
/**
* listnode add directive
*/
//directive('addlistnode', function () {
// return {
// link: function ($scope, $modal, $element) {
// debugger;
//$element.on('click', function () {
// var nodename = $element[0].firstElementChild.innerHTML;
// var newitem = angular.copy($scope.listnodeform[nodename+'_1']);
// console.log($scope.form);
// $scope.form.splice(7, 0, newitem);
// console.log($scope.form);
// $scope.$broadcast('schemaFormRedraw');
// $scope.$apply();
//});
// }
// }
//});
// test the code with strict di mode to see if it works when minified
//angular.bootstrap(document, ['ulakbus'], {
......
......@@ -26,11 +26,10 @@ crud.controller('CRUDAddEditCtrl', function ($scope, $rootScope, $location, $htt
else {
$scope.form_params['cmd'] = 'add';
}
// to start in certain part of the workflow use clear_wf=1
//$scope.form_params['clear_wf'] = 1;
// get form with generator
Generator.get_form($scope);
debugger;
$scope.onSubmit = function (form) {
$scope.$broadcast('schemaFormValidate');
......@@ -56,7 +55,6 @@ crud.controller('CRUDListCtrl', function ($scope, $rootScope, Generator, $routeP
// call generator's get_list func
Generator.get_list($scope)
.then(function (res) {
debugger;
var data = res.data.objects;
for (var item in data){
delete data[item].data['deleted'];
......@@ -76,5 +74,6 @@ crud.controller('CRUDShowCtrl', function ($scope, $rootScope, Generator, $routeP
// call generator's get_single_itemfunc
Generator.get_single_item($scope).then(function (res) {
$scope.object = res.data.object;
$scope.model = $routeParams.model;
})
});
\ No newline at end of file
<p ng-repeat="(key, value) in object"><span class="col-md-3">{{ key }}:</span>{{value}}</p>
\ No newline at end of file
<div class="starter-template">
<h1>{{model}}</h1>
<p ng-repeat="(key, value) in object"><span class="col-md-3">{{ key }}:</span>{{value}}</p>
</div>
\ No newline at end of file
......@@ -5,23 +5,43 @@
* (GPLv3). See LICENSE.txt for details.
*/
app.directive('headerNotification',function(){
/**
* logout directive
*/
app.directive('logout', function ($http, $location) {
return {
link: function ($scope, $element, $rootScope) {
$element.on('click', function () {
$http.post('http://' + window.location.hostname + ':9001/logout', {}).then(function () {
$rootScope.loggedInUser = false;
console.log($rootScope.loggedInUser);
$location.path("/login");
$scope.$apply();
});
});
}
}
});
/**
* headerNotification directive for header
*/
app.directive('headerNotification', function () {
return {
templateUrl:'shared/templates/directives/header-notification.html',
templateUrl: 'shared/templates/directives/header-notification.html',
restrict: 'E',
replace: true,
}
});
app.directive('sidebar',['$location',function() {
app.directive('sidebar', ['$location', function () {
return {
templateUrl:'shared/templates/directives/sidebar.html',
templateUrl: 'shared/templates/directives/sidebar.html',
restrict: 'E',
replace: true,
scope: {
},
controller:function($scope, $http, RESTURL){
$http.post(RESTURL.url+'crud/').success(function(data){
scope: {},
controller: function ($scope, $http, RESTURL) {
$http.post(RESTURL.url + 'crud/').success(function (data) {
//debugger;
$scope.menuItems = data.models;
});
......@@ -32,17 +52,17 @@ app.directive('sidebar',['$location',function() {
$scope.collapseVar = 0;
$scope.multiCollapseVar = 0;
$scope.check = function(x){
$scope.check = function (x) {
if(x==$scope.collapseVar)
if (x == $scope.collapseVar)
$scope.collapseVar = 0;
else
$scope.collapseVar = x;
};
$scope.multiCheck = function(y){
$scope.multiCheck = function (y) {
if(y==$scope.multiCollapseVar)
if (y == $scope.multiCollapseVar)
$scope.multiCollapseVar = 0;
else
$scope.multiCollapseVar = y;
......@@ -51,57 +71,56 @@ app.directive('sidebar',['$location',function() {
}
}]);
app.directive('stats',function() {
app.directive('stats', function () {
return {
templateUrl:'shared/templates/directives/stats.html',
restrict:'E',
replace:true,
templateUrl: 'shared/templates/directives/stats.html',
restrict: 'E',
replace: true,
scope: {
'model': '=',
'comments': '@',
'number': '@',
'name': '@',
'colour': '@',
'details':'@',
'type':'@',
'goto':'@'
'details': '@',
'type': '@',
'goto': '@'
}
}
});
app.directive('notifications',function(){
app.directive('notifications', function () {
return {
templateUrl:'shared/templates/directives/notifications.html',
templateUrl: 'shared/templates/directives/notifications.html',
restrict: 'E',
replace: true,
}
});
app.directive('sidebarSearch',function() {
app.directive('sidebarSearch', function () {
return {
templateUrl:'shared/templates/directives/sidebar-search.html',
templateUrl: 'shared/templates/directives/sidebar-search.html',
restrict: 'E',
replace: true,
scope: {
},
controller:function($scope){
scope: {},
controller: function ($scope) {
$scope.selectedMenu = 'home';
}
}
});
app.directive('timeline',function() {
app.directive('timeline', function () {
return {
templateUrl:'shared/templates/directives/timeline.html',
templateUrl: 'shared/templates/directives/timeline.html',
restrict: 'E',
replace: true,
}
});
app.directive('chat',function(){
app.directive('chat', function () {
return {
templateUrl:'shared/templates/directives/chat.html',
templateUrl: 'shared/templates/directives/chat.html',
restrict: 'E',
replace: true,
}
......
......@@ -11,12 +11,16 @@
sf-changed="form"
class="form-control {{form.fieldHtmlClass}}"
schema-validate="form"
ng-options="item.value as item.name group by item.group for item in form.titleMap track by item[form.trackBy]"
ng-options="item.value as item.name group by item.group for item in form.titleMap"
name="{{form.key.slice(-1)[0]}}">
</select>
<div class="help-block" sf-message="form.description"></div>
</div>
<div class="col-md-4"><a href="javascript:void(0);" logout><i class="fa fa-plus-circle fa-fw"></i></a></div>
<div class="col-md-4">
<a href="javascript:void(0);" add-modal>
<i class="fa fa-plus-circle fa-fw"></i>
</a>
</div>
</div>
\ No newline at end of file
......@@ -29,12 +29,16 @@ form_generator.factory('Generator', function ($http, $q, $log, $modal, $timeout,
angular.forEach(scope.schema.properties, function(k, v){
// check if type is date and if type date found change it to string
// and give it 'format':'date' property
if (k.type == 'date') {k.type='string'; k.format='date'}
if (k.type == 'int') {k.type='number'}
// if type is model use foreignKey.html template to show them
// TODO: treat models as foreign keys
if (k.type == 'model') {
var formitem = scope.form[scope.form.indexOf(v)];
formitem = {
"type": "template",
"templateUrl": "shared/templates/foreignKey.html",
......@@ -42,14 +46,12 @@ form_generator.factory('Generator', function ($http, $q, $log, $modal, $timeout,
};
k.title = k.model_name;
var modelscope = scope;
modelscope.form_params = {model: k.model_name};
var modelscope = {"url": scope.url, "form_params": {model: k.model_name}};
// get model objects from db and add to select list
generator.get_list(modelscope).then(function(res){
formitem.titleMap = [];
angular.forEach(res.data.objects, function(item){
console.log(item);
formitem.titleMap.push({
"value": item.key,
"name": item.data.name ? item.data.name : item.data.username
......@@ -59,8 +61,6 @@ form_generator.factory('Generator', function ($http, $q, $log, $modal, $timeout,
});
scope.form[scope.form.indexOf(v)] = formitem;
debugger;
}
});
......@@ -186,6 +186,7 @@ form_generator.factory('Generator', function ($http, $q, $log, $modal, $timeout,
}
};
generator.submit = function ($scope) {
debugger;
data = {
"form": $scope.model,
"cmd": $scope.form_params.cmd,
......@@ -200,13 +201,7 @@ form_generator.factory('Generator', function ($http, $q, $log, $modal, $timeout,
"form": get_diff
};
}
return $http
.post(generator.makeUrl($scope.url), data);
//.then(function (res) {
// // todo: for now fake rest api returns 'ok' no data to
// // manipulate on ui. therefor used just a log
// $log.info(res);
//});
return $http.post(generator.makeUrl($scope.url), data);
};
return generator;
});
......@@ -230,6 +225,19 @@ form_generator.controller('ListNodeModalCtrl', function ($scope, $modalInstance,
};
});
form_generator.controller('LinkedModelModalCtrl', function ($scope, $modalInstance, items) {
angular.forEach(["model", "schema", "form"], function(key){
$scope[key] = items[key];
});
$scope.onSubmit = function(){
// send form to modalinstance result function
$modalInstance.close($scope);
};
$scope.cancel = function () {
$modalInstance.dismiss('cancel');
};
});
// todo: generic modal directive for all forms
//form_generator.directive('openmodal', ['Generator', function (Generator, $modal) {
// return {
......@@ -253,4 +261,47 @@ form_generator.controller('ListNodeModalCtrl', function ($scope, $modalInstance,
// });
// }
// }
//}]);
\ No newline at end of file
//}]);
/**
* modal directive for linked models
*/
form_generator.directive('addModal', function ($modal, Generator) {
return {
link: function (scope, element) {
element .on('click', function () {
var modalInstance = $modal.open({
animation: false,
templateUrl: 'shared/templates/linkedModelModalContent.html',
controller: 'LinkedModelModalCtrl',
size: 'lg',
resolve: {
items: function () {
debugger;
scope.url = 'crud';
scope.form_params = {'model': scope.form.title, "cmd": "add"};
return Generator.get_form(scope);
}
}
});
modalInstance.result.then(function (childmodel, key) {
debugger;
Generator.submit(scope);
//angular.forEach(childmodel, function(v, k){
// if ($scope.model[k]){
// $scope.model[k][v.idx] = v;
// } else {
// $scope.model[k] = {};
// $scope.model[k][v.idx] = v;
// }
//scope.$broadcast('schemaFormRedraw');
//});
});
//$scope.$broadcast('schemaFormRedraw');
//$scope.$apply();
});
}
}
});
\ 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