adding angular-permission
This commit is contained in:
parent
c0ab6df74d
commit
e185f59bb1
|
@ -23,11 +23,6 @@ var FormSchema = new Schema({
|
|||
type: Date,
|
||||
default: Date.now
|
||||
},
|
||||
// type: {
|
||||
// type: String,
|
||||
// default: 'template',
|
||||
// enum: ['submission', 'template']
|
||||
// },
|
||||
title: {
|
||||
type: String,
|
||||
default: '',
|
||||
|
@ -39,7 +34,7 @@ var FormSchema = new Schema({
|
|||
type: String,
|
||||
default: '',
|
||||
},
|
||||
form_fields: [Schema.Types.Mixed],
|
||||
form_fields: [FieldSchema],
|
||||
|
||||
submissions: [{
|
||||
type: Schema.Types.ObjectId,
|
||||
|
@ -57,6 +52,10 @@ var FormSchema = new Schema({
|
|||
pdfFieldMap: {
|
||||
type: Schema.Types.Mixed
|
||||
},
|
||||
hideFooter: {
|
||||
type: Boolean,
|
||||
default: true,
|
||||
},
|
||||
isGenerated: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
|
@ -113,7 +112,7 @@ FormSchema.pre('save', function (next) {
|
|||
|
||||
//Autogenerate FORM from PDF if 'isGenerated' flag is 'true'
|
||||
FormSchema.pre('save', function (next) {
|
||||
var field;
|
||||
var field, _form_fields;
|
||||
|
||||
if(this.isGenerated && this.pdf){
|
||||
|
||||
|
@ -137,13 +136,22 @@ FormSchema.pre('save', function (next) {
|
|||
field.fieldType = _typeConvMap[ field.fieldType+'' ];
|
||||
}
|
||||
|
||||
field.created = Date.now();
|
||||
// field.created = Date.now();
|
||||
field.fieldValue = '';
|
||||
field.required = true;
|
||||
field.disabled = false;
|
||||
// field.required = true;
|
||||
//field.disabled = false;
|
||||
|
||||
// field = new Field(field);
|
||||
// field.save()
|
||||
// field.save(function(err) {
|
||||
// if (err) {
|
||||
// console.error(err.message);
|
||||
// throw new Error(err.message);
|
||||
// });
|
||||
// } else {
|
||||
// _form_fields[i] = this;
|
||||
// }
|
||||
// });
|
||||
_form_fields[i] = field;
|
||||
}
|
||||
|
||||
console.log('NEW FORM_FIELDS: ');
|
||||
|
|
|
@ -49,7 +49,7 @@ var FormFieldSchema = new Schema({
|
|||
},
|
||||
required: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
default: true,
|
||||
},
|
||||
disabled: {
|
||||
type: Boolean,
|
||||
|
|
|
@ -11,7 +11,8 @@
|
|||
"angular-bootstrap": "~0.12.0",
|
||||
"angular-ui-utils": "~0.1.1",
|
||||
"angular-ui-router": "~0.2.11",
|
||||
"angular-strap": "~2.2.1"
|
||||
"angular-strap": "~2.2.1",
|
||||
"angular-permission": "~0.3.0"
|
||||
},
|
||||
"resolutions": {
|
||||
"angular": "^1.2.21",
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
var ApplicationConfiguration = (function() {
|
||||
// Init module configuration options
|
||||
var applicationModuleName = 'medform';
|
||||
var applicationModuleVendorDependencies = ['ngResource', 'ngAnimate', 'ui.router', 'ui.bootstrap', 'ui.utils'];
|
||||
var applicationModuleVendorDependencies = ['ngResource', 'ngAnimate', 'ui.router', 'ui.bootstrap', 'ui.utils', 'permission'];
|
||||
|
||||
// Add a new vertical module
|
||||
var registerModule = function(moduleName, dependencies) {
|
||||
|
|
|
@ -11,16 +11,12 @@ angular.module('core').config(['$stateProvider', '$urlRouterProvider',
|
|||
state('home', {
|
||||
url: '/',
|
||||
templateUrl: 'modules/core/views/home.client.view.html'
|
||||
}).
|
||||
state('restricted', {
|
||||
'abstract': true,
|
||||
resolve: {
|
||||
authorize: ['Authorization',
|
||||
function(Authorization) {
|
||||
return Authorization.authorize();
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
|
||||
$urlRouterProvider.otherwise( function($injector) {
|
||||
var $state = $injector.get("$state");
|
||||
$state.go('home');
|
||||
});
|
||||
|
||||
}
|
||||
]);
|
|
@ -190,12 +190,14 @@
|
|||
|
||||
<br><br>
|
||||
<div class="row">
|
||||
<div class="col-sm-offset-4 col-sm-2">
|
||||
<div class="col-sm-offset-3 col-sm-2">
|
||||
<button class="btn btn-primary btn-large" type="button" ng-click="createOrUpdate()"><i class="icon-arrow-left icon-white"></i> Save Changes</button>
|
||||
</div>
|
||||
<div class="col-sm-2">
|
||||
<button class="btn btn-primary" type="button" ng-click="previewOn()"><i class="icon-eye-open icon-white"></i> Preview Form</button>
|
||||
<!-- <button class="btn btn-danger right" type="button" ng-click="reset()"><i class="icon-refresh icon-white"></i> Reset</button> -->
|
||||
<div class="col-sm-1">
|
||||
<button class="btn btn-primary" type="button" ng-data-href="#!/forms/{{form._id}}/admin"><i class="icon-eye-open icon-white"></i> Cancel</button>
|
||||
</div>
|
||||
<div class="col-sm-1 col-sm-offset-1">
|
||||
<button class="btn btn-secondary" type="button" ng-click="previewOn()"><i class="icon-eye-open icon-white"></i> Preview Form</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -1,13 +1,15 @@
|
|||
<section data-ng-controller="ViewFormController" data-ng-init="findAll()">
|
||||
<div class="page-header">
|
||||
<h1>Forms</h1>
|
||||
<section data-ng-controller="ViewFormController" data-ng-init="findAll()" class="container">
|
||||
<div class="row">
|
||||
<div class="page-header col-xs-10 col-xs-offset-1">
|
||||
<h1>My MedForms</h1>
|
||||
</div>
|
||||
</div>
|
||||
<div class=" container">
|
||||
<a data-ng-href="#!/forms/create" class="col-md-2 col-md-offset-1 form-item row create-new">
|
||||
<div class="title-row col-md-12">
|
||||
<div class="row container">
|
||||
<a data-ng-href="#!/forms/create" class="col-xs-2 col-xs-offset-1 form-item row container create-new">
|
||||
<div class="title-row col-xs-12">
|
||||
<h4 class=" fa fa-plus fa-6"></h4>
|
||||
</div>
|
||||
<div class="col-md-12 details-row">
|
||||
<div class="col-xs-12 details-row">
|
||||
|
||||
<small class="list-group-item-text">
|
||||
Create a new form
|
||||
|
@ -16,11 +18,11 @@
|
|||
</div>
|
||||
|
||||
</a>
|
||||
<a data-ng-repeat="form in forms" data-ng-href="#!/forms/{{form._id}}/admin" class="col-md-2 col-md-offset-1 form-item row">
|
||||
<div class="title-row col-md-12">
|
||||
<a data-ng-repeat="form in forms" data-ng-href="#!/forms/{{form._id}}/admin" class="col-xs-2 col-xs-offset-1 form-item row">
|
||||
<div class="title-row col-xs-12">
|
||||
<h4 class="list-group-item-heading" data-ng-bind="form.title"></h4>
|
||||
</div>
|
||||
<div class="col-md-12 details-row">
|
||||
<div class="col-xs-12 details-row">
|
||||
|
||||
<small class="list-group-item-text">
|
||||
Created on
|
||||
|
@ -33,7 +35,7 @@
|
|||
|
||||
</a>
|
||||
</div>
|
||||
<div class="alert alert-warning text-center" data-ng-if="forms.$resolved && !forms.length">
|
||||
<!-- <div class="alert alert-warning text-center" data-ng-if="forms.$resolved && !forms.length">
|
||||
No forms yet, why don't you <a href="/#!/forms/create">create one</a>?
|
||||
</div>
|
||||
</div> -->
|
||||
</section>
|
|
@ -4,30 +4,30 @@
|
|||
<form-directive form="form"></form-directive><hr>
|
||||
|
||||
|
||||
<section class="navbar navbar-fixed-bottom" style="background-color:rgba(242,242,242,0.5); padding-top:15px;">
|
||||
<div class="container" >
|
||||
<nav role="navigation">
|
||||
<ul class="nav navbar-nav navbar-left" >
|
||||
<li class="">
|
||||
<!-- <p class="lead">{{form | formValidity}} out of {{form.form_fields.length}} answered</p> -->
|
||||
</li>
|
||||
</ul>
|
||||
<ul class="nav navbar-nav navbar-right">
|
||||
<li style="padding-right:20px" >
|
||||
<a href="/forms/create" class="btn btn-default" ng-hide="authentication.user">create a Medform</a>
|
||||
</li>
|
||||
<li style="padding-right:20px" ng-show="authentication.user">
|
||||
<a href="/forms/{{form._id}}/edit" class="btn btn-default">edit this Medform</a>
|
||||
</li>
|
||||
<li style="padding-left:5px">
|
||||
<div class="btn btn-info" id="focusDownButton">\/</div>
|
||||
</li>
|
||||
<li style="padding-left:5px">
|
||||
<div class="btn btn-info" id="focusUpButton">/\</div>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
</section>
|
||||
<section ng-if="!form.hideFooter" class="navbar navbar-fixed-bottom" style="background-color:rgba(242,242,242,0.5); padding-top:15px;">
|
||||
<div class="container" >
|
||||
<nav role="navigation">
|
||||
<ul class="nav navbar-nav navbar-left" >
|
||||
<li class="">
|
||||
<!-- <p class="lead">{{form | formValidity}} out of {{form.form_fields.length}} answered</p> -->
|
||||
</li>
|
||||
</ul>
|
||||
<ul class="nav navbar-nav navbar-right">
|
||||
<li style="padding-right:20px" >
|
||||
<a href="/forms/create" class="btn btn-default" ng-hide="authentication.user">create a Medform</a>
|
||||
</li>
|
||||
<li style="padding-right:20px" ng-show="authentication.user">
|
||||
<a href="/forms/{{form._id}}/edit" class="btn btn-default">edit this Medform</a>
|
||||
</li>
|
||||
<li style="padding-left:5px">
|
||||
<div class="btn btn-info" id="focusDownButton">\/</div>
|
||||
</li>
|
||||
<li style="padding-left:5px">
|
||||
<div class="btn btn-info" id="focusUpButton">/\</div>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
|
|
|
@ -1,30 +1,53 @@
|
|||
// 'use strict';
|
||||
|
||||
// // Config HTTP Error Handling
|
||||
// angular.module('users').config(['$httpProvider',
|
||||
// function($httpProvider) {
|
||||
// // Set the httpProvider "not authorized" interceptor
|
||||
// $httpProvider.interceptors.push(['$q', '$location', 'Principal',
|
||||
// function($q, $location, Principal) {
|
||||
// return {
|
||||
// responseError: function(rejection) {
|
||||
// switch (rejection.status) {
|
||||
// case 401:
|
||||
// // Deauthenticate the global user
|
||||
// Principal.authenticate(null);
|
||||
// Config HTTP Error Handling
|
||||
angular.module('users').config(['$httpProvider','$q', '$location', 'Principal',
|
||||
function($httpProvider, $q, $location, Principal) {
|
||||
// Set the httpProvider "not authorized" interceptor
|
||||
$httpProvider.interceptors.push(['$q', '$location', 'Principal',
|
||||
function($q, $location, Principal) {
|
||||
return {
|
||||
responseError: function(rejection) {
|
||||
switch (rejection.status) {
|
||||
case 401:
|
||||
// Deauthenticate the global user
|
||||
|
||||
|
||||
// // Redirect to signin page
|
||||
// $location.path('signin');
|
||||
// break;
|
||||
// case 403:
|
||||
// // Add unauthorized behaviour
|
||||
// break;
|
||||
// }
|
||||
// Redirect to signin page
|
||||
$location.path('signin');
|
||||
break;
|
||||
case 403:
|
||||
// Add unauthorized behaviour
|
||||
break;
|
||||
}
|
||||
|
||||
// return $q.reject(rejection);
|
||||
// }
|
||||
// };
|
||||
// }
|
||||
// ]);
|
||||
// }
|
||||
// ]);
|
||||
return $q.reject(rejection);
|
||||
}
|
||||
};
|
||||
}
|
||||
]);
|
||||
}
|
||||
]).config(['Permission', 'Principal',
|
||||
function($Permission, Principal) {
|
||||
var User = Principal.identity();
|
||||
Permission.defineRole('anonymous', function (stateParams) {
|
||||
// If the returned value is *truthy* then the user has the role, otherwise they don't
|
||||
if ( !User || !Principal.isInAnyRole() ) {
|
||||
return true; // Is anonymous
|
||||
}
|
||||
return false;
|
||||
}).defineRole('admin', function (stateParams) {
|
||||
// If the returned value is *truthy* then the user has the role, otherwise they don't
|
||||
if (Principal.isInRole('admin')) {
|
||||
return true; // Is anonymous
|
||||
}
|
||||
return false;
|
||||
}).defineRole('admin', function (stateParams) {
|
||||
// If the returned value is *truthy* then the user has the role, otherwise they don't
|
||||
if (Principal.isInRole('user') && !Principal.isInRole('admin') ) {
|
||||
return true; // Is anonymous
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
]);
|
Loading…
Reference in a new issue