-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(uibootstrap-modal): add basic modal service and template when us…
…ing uibootstrap Changes: (only if ui-bootstrap is selected) - add `client/components/modal` folder - modal folder contains service, markup template, and stylesheet - modal service is intended to be extended, comes with `Modal.confirm.delete()` method - admin and main page will both use `Modal.confirm.delete()` Todo: - review code for cleanliness and correctness - possibly extend the modal service to include a basic alert class? - write test for `Modal` service?
- Loading branch information
Showing
16 changed files
with
277 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
app/templates/client/app/admin(auth)/admin.controller(coffee).coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
'use strict' | ||
|
||
angular.module '<%= scriptAppName %>' | ||
.controller 'AdminCtrl', ($scope, $http, Auth, User) -> | ||
.controller 'AdminCtrl', ($scope, $http, Auth, User<% if(filters.uibootstrap) { %>, Modal<% } %>) -> | ||
|
||
# Use the User $resource to fetch all users | ||
$scope.users = User.query() | ||
|
||
$scope.delete = (user) -> | ||
$scope.delete = <% if(filters.uibootstrap) { %>Modal.confirm.delete <% } %>(user) -> | ||
User.remove id: user._id | ||
angular.forEach $scope.users, (u, i) -> | ||
$scope.users.splice i, 1 if u is user |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
'use strict'; | ||
|
||
angular.module('<%= scriptAppName %>') | ||
.controller('AdminCtrl', function ($scope, $http, Auth, User) { | ||
.controller('AdminCtrl', function ($scope, $http, Auth, User<% if(filters.uibootstrap) { %>, Modal<% } %>) { | ||
|
||
// Use the User $resource to fetch all users | ||
$scope.users = User.query(); | ||
|
||
$scope.delete = function(user) { | ||
$scope.delete = <% if(filters.uibootstrap) { %>Modal.confirm.delete(<% } %>function(user) { | ||
User.remove({ id: user._id }); | ||
angular.forEach($scope.users, function(u, i) { | ||
if (u === user) { | ||
$scope.users.splice(i, 1); | ||
} | ||
}); | ||
}; | ||
}<% if(filters.uibootstrap) { %>)<% } %>; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
app/templates/client/components/modal(uibootstrap)/modal(css).css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
.modal-primary .modal-header, | ||
.modal-info .modal-header, | ||
.modal-success .modal-header, | ||
.modal-warning .modal-header, | ||
.modal-danger .modal-header { | ||
color: #fff; | ||
border-radius: 5px 5px 0 0; | ||
} | ||
.modal-primary .modal-header { | ||
background: #428bca; | ||
} | ||
.modal-info .modal-header { | ||
background: #5bc0de; | ||
} | ||
.modal-success .modal-header { | ||
background: #5cb85c; | ||
} | ||
.modal-warning .modal-header { | ||
background: #f0ad4e; | ||
} | ||
.modal-danger .modal-header { | ||
background: #d9534f; | ||
} |
11 changes: 11 additions & 0 deletions
11
app/templates/client/components/modal(uibootstrap)/modal(html).html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<div class="modal-header"> | ||
<button ng-if="modal.dismissable" type="button" ng-click="$dismiss()" class="close">×</button> | ||
<h4 ng-if="modal.title" ng-bind="modal.title" class="modal-title"></h4> | ||
</div> | ||
<div class="modal-body"> | ||
<p ng-if="modal.text" ng-bind="modal.text"></p> | ||
<div ng-if="modal.html" ng-bind-html="modal.html"></div> | ||
</div> | ||
<div class="modal-footer"> | ||
<button ng-repeat="button in modal.buttons" ng-class="button.classes" ng-click="button.click($event)" ng-bind="button.text" class="btn"></button> | ||
</div> |
8 changes: 8 additions & 0 deletions
8
app/templates/client/components/modal(uibootstrap)/modal(jade).jade
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.modal-header | ||
button.close(ng-if='modal.dismissable', type='button', ng-click='$dismiss()') × | ||
h4.modal-title(ng-if='modal.title', ng-bind='modal.title') | ||
.modal-body | ||
p(ng-if='modal.text', ng-bind='modal.text') | ||
div(ng-if='modal.html', ng-bind-html='modal.html') | ||
.modal-footer | ||
button.btn(ng-repeat='button in modal.buttons', ng-class='button.classes', ng-click='button.click($event)', ng-bind='button.text') |
25 changes: 25 additions & 0 deletions
25
app/templates/client/components/modal(uibootstrap)/modal(less).less
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
.modal-primary, | ||
.modal-info, | ||
.modal-success, | ||
.modal-warning, | ||
.modal-danger { | ||
.modal-header { | ||
color: #fff; | ||
border-radius: 5px 5px 0 0; | ||
} | ||
} | ||
.modal-primary .modal-header { | ||
background: @brand-primary; | ||
} | ||
.modal-info .modal-header { | ||
background: @brand-info; | ||
} | ||
.modal-success .modal-header { | ||
background: @brand-success; | ||
} | ||
.modal-warning .modal-header { | ||
background: @brand-warning; | ||
} | ||
.modal-danger .modal-header { | ||
background: @brand-danger; | ||
} |
25 changes: 25 additions & 0 deletions
25
app/templates/client/components/modal(uibootstrap)/modal(sass).scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
.modal-primary, | ||
.modal-info, | ||
.modal-success, | ||
.modal-warning, | ||
.modal-danger { | ||
.modal-header { | ||
color: #fff; | ||
border-radius: 5px 5px 0 0; | ||
} | ||
} | ||
.modal-primary .modal-header { | ||
background: $brand-primary; | ||
} | ||
.modal-info .modal-header { | ||
background: $brand-info; | ||
} | ||
.modal-success .modal-header { | ||
background: $brand-success; | ||
} | ||
.modal-warning .modal-header { | ||
background: $brand-warning; | ||
} | ||
.modal-danger .modal-header { | ||
background: $brand-danger; | ||
} |
23 changes: 23 additions & 0 deletions
23
app/templates/client/components/modal(uibootstrap)/modal(stylus).styl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
.modal-primary | ||
.modal-info | ||
.modal-success | ||
.modal-warning | ||
.modal-danger | ||
.modal-header | ||
color #fff | ||
border-radius 5px 5px 0 0 | ||
|
||
.modal-primary .modal-header | ||
background #428bca | ||
|
||
.modal-info .modal-header | ||
background #5bc0de | ||
|
||
.modal-success .modal-header | ||
background #5cb85c | ||
|
||
.modal-warning .modal-header | ||
background #f0ad4e | ||
|
||
.modal-danger .modal-header | ||
background #d9534f |
71 changes: 71 additions & 0 deletions
71
app/templates/client/components/modal(uibootstrap)/modal.service(coffee).coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
'use strict' | ||
|
||
angular.module '<%= scriptAppName %>' | ||
.factory 'Modal', ($rootScope, $modal) -> | ||
|
||
### | ||
Opens a modal | ||
@param {Object} scope - an object to be merged with modal's scope | ||
@param {String} modalClass - (optional) class(es) to be applied to the modal | ||
@return {Object} - the instance $modal.open() returns | ||
### | ||
openModal = (scope, modalClass) -> | ||
modalScope = $rootScope.$new() | ||
scope = scope or {} | ||
modalClass = modalClass or 'modal-default' | ||
angular.extend modalScope, scope | ||
$modal.open | ||
templateUrl: 'components/modal/modal.html' | ||
windowClass: modalClass | ||
scope: modalScope | ||
|
||
|
||
# Public API here | ||
|
||
# Confirmation modals | ||
confirm: | ||
|
||
### | ||
Create a function to open a delete confirmation modal (ex. ng-click='myModalFn(name, arg1, arg2...)') | ||
@param {Function} del - callback, ran when delete is confirmed | ||
@return {Function} - the function to open the modal (ex. myModalFn) | ||
### | ||
delete: (del) -> | ||
del = del or angular.noop | ||
|
||
### | ||
Open a delete confirmation modal | ||
@param {String} name - name or info to show on modal | ||
@param {All} - any additional args are passed staight to del callback | ||
### | ||
-> | ||
args = Array::slice.call arguments | ||
name = args.shift() | ||
deleteModal = undefined | ||
deleteModal = openModal( | ||
modal: | ||
dismissable: true | ||
title: 'Confirm Delete' | ||
html: '<p>Are you sure you want to delete <strong>' + name + '</strong> ?</p>' | ||
buttons: [ | ||
{ | ||
classes: 'btn-danger' | ||
text: 'Delete' | ||
click: (e) -> | ||
deleteModal.close e | ||
return | ||
} | ||
{ | ||
classes: 'btn-default' | ||
text: 'Cancel' | ||
click: (e) -> | ||
deleteModal.dismiss e | ||
return | ||
} | ||
] | ||
, 'modal-danger') | ||
deleteModal.result.then (event) -> | ||
del.apply event, args | ||
return | ||
|
||
return |
77 changes: 77 additions & 0 deletions
77
app/templates/client/components/modal(uibootstrap)/modal.service(js).js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
'use strict'; | ||
|
||
angular.module('<%= scriptAppName %>') | ||
.factory('Modal', function ($rootScope, $modal) { | ||
/** | ||
* Opens a modal | ||
* @param {Object} scope - an object to be merged with modal's scope | ||
* @param {String} modalClass - (optional) class(es) to be applied to the modal | ||
* @return {Object} - the instance $modal.open() returns | ||
*/ | ||
function openModal(scope, modalClass) { | ||
var modalScope = $rootScope.$new(); | ||
scope = scope || {}; | ||
modalClass = modalClass || 'modal-default'; | ||
|
||
angular.extend(modalScope, scope); | ||
|
||
return $modal.open({ | ||
templateUrl: 'components/modal/modal.html', | ||
windowClass: modalClass, | ||
scope: modalScope | ||
}); | ||
} | ||
|
||
// Public API here | ||
return { | ||
|
||
/* Confirmation modals */ | ||
confirm: { | ||
|
||
/** | ||
* Create a function to open a delete confirmation modal (ex. ng-click='myModalFn(name, arg1, arg2...)') | ||
* @param {Function} del - callback, ran when delete is confirmed | ||
* @return {Function} - the function to open the modal (ex. myModalFn) | ||
*/ | ||
delete: function(del) { | ||
del = del || angular.noop; | ||
|
||
/** | ||
* Open a delete confirmation modal | ||
* @param {String} name - name or info to show on modal | ||
* @param {All} - any additional args are passed staight to del callback | ||
*/ | ||
return function() { | ||
var args = Array.prototype.slice.call(arguments), | ||
name = args.shift(), | ||
deleteModal; | ||
|
||
deleteModal = openModal({ | ||
modal: { | ||
dismissable: true, | ||
title: 'Confirm Delete', | ||
html: '<p>Are you sure you want to delete <strong>' + name + '</strong> ?</p>', | ||
buttons: [{ | ||
classes: 'btn-danger', | ||
text: 'Delete', | ||
click: function(e) { | ||
deleteModal.close(e); | ||
} | ||
}, { | ||
classes: 'btn-default', | ||
text: 'Cancel', | ||
click: function(e) { | ||
deleteModal.dismiss(e); | ||
} | ||
}] | ||
} | ||
}, 'modal-danger'); | ||
|
||
deleteModal.result.then(function(event) { | ||
del.apply(event, args); | ||
}); | ||
}; | ||
} | ||
} | ||
}; | ||
}); |