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( ...@@ -50,74 +50,9 @@ var app = angular.module(
sessionTimeout: 'auth-session-timeout', sessionTimeout: 'auth-session-timeout',
notAuthenticated: 'auth-not-authenticated', notAuthenticated: 'auth-not-authenticated',
notAuthorized: 'auth-not-authorized' 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 // test the code with strict di mode to see if it works when minified
//angular.bootstrap(document, ['ulakbus'], { //angular.bootstrap(document, ['ulakbus'], {
......
...@@ -26,11 +26,10 @@ crud.controller('CRUDAddEditCtrl', function ($scope, $rootScope, $location, $htt ...@@ -26,11 +26,10 @@ crud.controller('CRUDAddEditCtrl', function ($scope, $rootScope, $location, $htt
else { else {
$scope.form_params['cmd'] = 'add'; $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 // get form with generator
Generator.get_form($scope); Generator.get_form($scope);
debugger;
$scope.onSubmit = function (form) { $scope.onSubmit = function (form) {
$scope.$broadcast('schemaFormValidate'); $scope.$broadcast('schemaFormValidate');
...@@ -56,7 +55,6 @@ crud.controller('CRUDListCtrl', function ($scope, $rootScope, Generator, $routeP ...@@ -56,7 +55,6 @@ crud.controller('CRUDListCtrl', function ($scope, $rootScope, Generator, $routeP
// call generator's get_list func // call generator's get_list func
Generator.get_list($scope) Generator.get_list($scope)
.then(function (res) { .then(function (res) {
debugger;
var data = res.data.objects; var data = res.data.objects;
for (var item in data){ for (var item in data){
delete data[item].data['deleted']; delete data[item].data['deleted'];
...@@ -76,5 +74,6 @@ crud.controller('CRUDShowCtrl', function ($scope, $rootScope, Generator, $routeP ...@@ -76,5 +74,6 @@ crud.controller('CRUDShowCtrl', function ($scope, $rootScope, Generator, $routeP
// call generator's get_single_itemfunc // call generator's get_single_itemfunc
Generator.get_single_item($scope).then(function (res) { Generator.get_single_item($scope).then(function (res) {
$scope.object = res.data.object; $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> <div class="starter-template">
\ No newline at end of file <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 @@ ...@@ -5,23 +5,43 @@
* (GPLv3). See LICENSE.txt for details. * (GPLv3). See LICENSE.txt for details.
*/ */
app.directive('headerNotification',function(){ /**
* logout directive
*/
app.directive('logout', function ($http, $location) {
return { return {
templateUrl:'shared/templates/directives/header-notification.html', 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',
restrict: 'E', restrict: 'E',
replace: true, replace: true,
} }
}); });
app.directive('sidebar',['$location',function() { app.directive('sidebar', ['$location', function () {
return { return {
templateUrl:'shared/templates/directives/sidebar.html', templateUrl: 'shared/templates/directives/sidebar.html',
restrict: 'E', restrict: 'E',
replace: true, replace: true,
scope: { scope: {},
}, controller: function ($scope, $http, RESTURL) {
controller:function($scope, $http, RESTURL){ $http.post(RESTURL.url + 'crud/').success(function (data) {
$http.post(RESTURL.url+'crud/').success(function(data){
//debugger; //debugger;
$scope.menuItems = data.models; $scope.menuItems = data.models;
}); });
...@@ -32,17 +52,17 @@ app.directive('sidebar',['$location',function() { ...@@ -32,17 +52,17 @@ app.directive('sidebar',['$location',function() {
$scope.collapseVar = 0; $scope.collapseVar = 0;
$scope.multiCollapseVar = 0; $scope.multiCollapseVar = 0;
$scope.check = function(x){ $scope.check = function (x) {
if(x==$scope.collapseVar) if (x == $scope.collapseVar)
$scope.collapseVar = 0; $scope.collapseVar = 0;
else else
$scope.collapseVar = x; $scope.collapseVar = x;
}; };
$scope.multiCheck = function(y){ $scope.multiCheck = function (y) {
if(y==$scope.multiCollapseVar) if (y == $scope.multiCollapseVar)
$scope.multiCollapseVar = 0; $scope.multiCollapseVar = 0;
else else
$scope.multiCollapseVar = y; $scope.multiCollapseVar = y;
...@@ -51,57 +71,56 @@ app.directive('sidebar',['$location',function() { ...@@ -51,57 +71,56 @@ app.directive('sidebar',['$location',function() {
} }
}]); }]);
app.directive('stats',function() { app.directive('stats', function () {
return { return {
templateUrl:'shared/templates/directives/stats.html', templateUrl: 'shared/templates/directives/stats.html',
restrict:'E', restrict: 'E',
replace:true, replace: true,
scope: { scope: {
'model': '=', 'model': '=',
'comments': '@', 'comments': '@',
'number': '@', 'number': '@',
'name': '@', 'name': '@',
'colour': '@', 'colour': '@',
'details':'@', 'details': '@',
'type':'@', 'type': '@',
'goto':'@' 'goto': '@'
} }
} }
}); });
app.directive('notifications',function(){ app.directive('notifications', function () {
return { return {
templateUrl:'shared/templates/directives/notifications.html', templateUrl: 'shared/templates/directives/notifications.html',
restrict: 'E', restrict: 'E',
replace: true, replace: true,
} }
}); });
app.directive('sidebarSearch',function() { app.directive('sidebarSearch', function () {
return { return {
templateUrl:'shared/templates/directives/sidebar-search.html', templateUrl: 'shared/templates/directives/sidebar-search.html',
restrict: 'E', restrict: 'E',
replace: true, replace: true,
scope: { scope: {},
}, controller: function ($scope) {
controller:function($scope){
$scope.selectedMenu = 'home'; $scope.selectedMenu = 'home';
} }
} }
}); });
app.directive('timeline',function() { app.directive('timeline', function () {
return { return {
templateUrl:'shared/templates/directives/timeline.html', templateUrl: 'shared/templates/directives/timeline.html',
restrict: 'E', restrict: 'E',
replace: true, replace: true,
} }
}); });
app.directive('chat',function(){ app.directive('chat', function () {
return { return {
templateUrl:'shared/templates/directives/chat.html', templateUrl: 'shared/templates/directives/chat.html',
restrict: 'E', restrict: 'E',
replace: true, replace: true,
} }
......
...@@ -11,12 +11,16 @@ ...@@ -11,12 +11,16 @@
sf-changed="form" sf-changed="form"
class="form-control {{form.fieldHtmlClass}}" class="form-control {{form.fieldHtmlClass}}"
schema-validate="form" 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]}}"> name="{{form.key.slice(-1)[0]}}">
</select> </select>
<div class="help-block" sf-message="form.description"></div> <div class="help-block" sf-message="form.description"></div>
</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> </div>
\ No newline at end of file
...@@ -29,12 +29,16 @@ form_generator.factory('Generator', function ($http, $q, $log, $modal, $timeout, ...@@ -29,12 +29,16 @@ form_generator.factory('Generator', function ($http, $q, $log, $modal, $timeout,
angular.forEach(scope.schema.properties, function(k, v){ angular.forEach(scope.schema.properties, function(k, v){
// check if type is date and if type date found change it to string // check if type is date and if type date found change it to string
// and give it 'format':'date' property // and give it 'format':'date' property
if (k.type == 'date') {k.type='string'; k.format='date'} 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 // if type is model use foreignKey.html template to show them
// TODO: treat models as foreign keys
if (k.type == 'model') { if (k.type == 'model') {
var formitem = scope.form[scope.form.indexOf(v)]; var formitem = scope.form[scope.form.indexOf(v)];
formitem = { formitem = {
"type": "template", "type": "template",
"templateUrl": "shared/templates/foreignKey.html", "templateUrl": "shared/templates/foreignKey.html",
...@@ -42,14 +46,12 @@ form_generator.factory('Generator', function ($http, $q, $log, $modal, $timeout, ...@@ -42,14 +46,12 @@ form_generator.factory('Generator', function ($http, $q, $log, $modal, $timeout,
}; };
k.title = k.model_name; k.title = k.model_name;
var modelscope = scope; var modelscope = {"url": scope.url, "form_params": {model: k.model_name}};
modelscope.form_params = {model: k.model_name};
// get model objects from db and add to select list // get model objects from db and add to select list
generator.get_list(modelscope).then(function(res){ generator.get_list(modelscope).then(function(res){
formitem.titleMap = []; formitem.titleMap = [];
angular.forEach(res.data.objects, function(item){ angular.forEach(res.data.objects, function(item){
console.log(item);
formitem.titleMap.push({ formitem.titleMap.push({
"value": item.key, "value": item.key,
"name": item.data.name ? item.data.name : item.data.username "name": item.data.name ? item.data.name : item.data.username
...@@ -59,8 +61,6 @@ form_generator.factory('Generator', function ($http, $q, $log, $modal, $timeout, ...@@ -59,8 +61,6 @@ form_generator.factory('Generator', function ($http, $q, $log, $modal, $timeout,
}); });
scope.form[scope.form.indexOf(v)] = formitem; scope.form[scope.form.indexOf(v)] = formitem;
debugger;
} }
}); });
...@@ -186,6 +186,7 @@ form_generator.factory('Generator', function ($http, $q, $log, $modal, $timeout, ...@@ -186,6 +186,7 @@ form_generator.factory('Generator', function ($http, $q, $log, $modal, $timeout,
} }
}; };
generator.submit = function ($scope) { generator.submit = function ($scope) {
debugger;
data = { data = {
"form": $scope.model, "form": $scope.model,
"cmd": $scope.form_params.cmd, "cmd": $scope.form_params.cmd,
...@@ -200,13 +201,7 @@ form_generator.factory('Generator', function ($http, $q, $log, $modal, $timeout, ...@@ -200,13 +201,7 @@ form_generator.factory('Generator', function ($http, $q, $log, $modal, $timeout,
"form": get_diff "form": get_diff
}; };
} }
return $http return $http.post(generator.makeUrl($scope.url), data);
.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 generator; return generator;
}); });
...@@ -230,6 +225,19 @@ form_generator.controller('ListNodeModalCtrl', function ($scope, $modalInstance, ...@@ -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 // todo: generic modal directive for all forms
//form_generator.directive('openmodal', ['Generator', function (Generator, $modal) { //form_generator.directive('openmodal', ['Generator', function (Generator, $modal) {
// return { // return {
...@@ -254,3 +262,46 @@ form_generator.controller('ListNodeModalCtrl', function ($scope, $modalInstance, ...@@ -254,3 +262,46 @@ form_generator.controller('ListNodeModalCtrl', function ($scope, $modalInstance,
// } // }
// } // }
//}]); //}]);
/**
* 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