-
Notifications
You must be signed in to change notification settings - Fork 723
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #696 from marmelab/create_default_value
[RFR] Add default value parameter for create view and create-button directive
- Loading branch information
Showing
9 changed files
with
213 additions
and
261 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,27 @@ | ||
/*global define*/ | ||
|
||
define(function () { | ||
'use strict'; | ||
|
||
function maBackButtonDirective($window) { | ||
return { | ||
restrict: 'E', | ||
scope: { | ||
size: '@', | ||
label: '@', | ||
}, | ||
link: function ($scope) { | ||
$scope.label = $scope.label || 'Back'; | ||
|
||
$scope.back = function () { | ||
$window.history.back(); | ||
}; | ||
}, | ||
template: | ||
/** | ||
* Link to previous page | ||
* | ||
* Usage: | ||
* <ma-back-button entry="entry" size="xs"></ma-back-button> | ||
*/ | ||
function maBackButtonDirective($window) { | ||
return { | ||
restrict: 'E', | ||
scope: { | ||
size: '@', | ||
label: '@', | ||
}, | ||
link: function (scope) { | ||
scope.label = scope.label || 'Back'; | ||
scope.back = () => $window.history.back(); | ||
}, | ||
template: | ||
` <a class="btn btn-default" ng-class="size ? \'btn-\' + size : \'\'" ng-click="back()"> | ||
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span> <span class="hidden-xs">{{ ::label }}</span> | ||
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span> <span class="hidden-xs">{{ ::label }}</span> | ||
</a>` | ||
}; | ||
} | ||
}; | ||
} | ||
|
||
maBackButtonDirective.$inject = ['$window']; | ||
maBackButtonDirective.$inject = ['$window']; | ||
|
||
return maBackButtonDirective; | ||
}); | ||
module.exports = maBackButtonDirective; |
61 changes: 27 additions & 34 deletions
61
src/javascripts/ng-admin/Crud/button/maBatchDeleteButton.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 |
---|---|---|
@@ -1,40 +1,33 @@ | ||
/*global define*/ | ||
function maBatchDeleteButtonDirective($state) { | ||
return { | ||
restrict: 'E', | ||
scope: { | ||
entity: '&', | ||
selection: '&', | ||
label: '@', | ||
}, | ||
link: function ($scope) { | ||
$scope.label = $scope.label || 'Delete'; | ||
|
||
define(function () { | ||
'use strict'; | ||
$scope.gotoBatchDelete = function () { | ||
var entity = $scope.entity(); | ||
var ids = $scope.selection().map(function(entry) { | ||
return entry.identifierValue; | ||
}); | ||
|
||
function maBatchDeleteButtonDirective($state) { | ||
return { | ||
restrict: 'E', | ||
scope: { | ||
entity: '&', | ||
selection: '&', | ||
label: '@', | ||
}, | ||
link: function ($scope) { | ||
$scope.label = $scope.label || 'Delete'; | ||
|
||
$scope.gotoBatchDelete = function () { | ||
var entity = $scope.entity(); | ||
var ids = $scope.selection().map(function(entry) { | ||
return entry.identifierValue; | ||
}); | ||
|
||
$state.go('batchDelete', angular.extend({ | ||
ids: ids, | ||
entity: $scope.entity().name() | ||
}, $state.params)); | ||
}; | ||
}, | ||
template: | ||
$state.go('batchDelete', angular.extend({ | ||
ids: ids, | ||
entity: $scope.entity().name() | ||
}, $state.params)); | ||
}; | ||
}, | ||
template: | ||
`<span ng-click="gotoBatchDelete()"> | ||
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span> <span class="hidden-xs">{{ ::label }}</span> | ||
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span> <span class="hidden-xs">{{ ::label }}</span> | ||
</span>` | ||
}; | ||
} | ||
|
||
}; | ||
} | ||
|
||
maBatchDeleteButtonDirective.$inject = ['$state']; | ||
maBatchDeleteButtonDirective.$inject = ['$state']; | ||
|
||
return maBatchDeleteButtonDirective; | ||
}); | ||
module.exports = maBatchDeleteButtonDirective; |
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,41 +1,36 @@ | ||
/*global define*/ | ||
|
||
define(function () { | ||
'use strict'; | ||
|
||
function maCreateButtonDirective($state) { | ||
return { | ||
restrict: 'E', | ||
scope: { | ||
entity: '&', | ||
size: '@', | ||
label: '@', | ||
}, | ||
link: function (scope) { | ||
scope.label = scope.label || 'Create'; | ||
|
||
scope.gotoCreate = function () { | ||
if ($state.params.entity == scope.entity().name()) { | ||
// link to the same entity, so preserve active filters | ||
$state.go($state.get('create'), angular.extend({ | ||
entity: scope.entity().name(), | ||
}, $state.params)); | ||
} else { | ||
// link to anoter entity, so forget filters | ||
$state.go($state.get('create'), { | ||
entity: scope.entity().name(), | ||
}); | ||
} | ||
}; | ||
}, | ||
template: | ||
/** | ||
* Link to create | ||
* | ||
* Usage: | ||
* <ma-create-button entity="entity" default-values="{}" size="xs"></ma-create-button> | ||
*/ | ||
function maCreateButtonDirective($state) { | ||
return { | ||
restrict: 'E', | ||
scope: { | ||
entity: '&', | ||
entityName: '@', | ||
defaultValues: '&', | ||
size: '@', | ||
label: '@', | ||
}, | ||
link: function (scope, element, attrs) { | ||
scope.gotoCreate = () => { | ||
var entityName = scope.entity() ? scope.entity().name() : attrs.entityName; | ||
var params = entityName == $state.params.entity ? $state.params : {}; | ||
params.entity = entityName; | ||
params.defaultValues = scope.defaultValues(); | ||
$state.go($state.get('create'), params); | ||
}; | ||
scope.label = scope.label || 'Create'; | ||
}, | ||
template: | ||
` <a class="btn btn-default" ng-class="size ? \'btn-\' + size : \'\'" ng-click="gotoCreate()"> | ||
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span> <span class="hidden-xs">{{ ::label }}</span> | ||
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span> <span class="hidden-xs">{{ ::label }}</span> | ||
</a>` | ||
}; | ||
} | ||
}; | ||
} | ||
|
||
maCreateButtonDirective.$inject = ['$state']; | ||
maCreateButtonDirective.$inject = ['$state']; | ||
|
||
return maCreateButtonDirective; | ||
}); | ||
module.exports = maCreateButtonDirective; |
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,45 +1,36 @@ | ||
/*global define*/ | ||
|
||
define(function () { | ||
'use strict'; | ||
|
||
function maDeleteButtonDirective($state) { | ||
return { | ||
restrict: 'E', | ||
scope: { | ||
entity: '&', | ||
entry: '&', | ||
size: '@', | ||
label: '@', | ||
}, | ||
link: function (scope) { | ||
scope.label = scope.label || 'Delete'; | ||
scope.gotoDelete = function () { | ||
if ($state.params.entity == scope.entity().name()) { | ||
// link to the same entity, so preserve active filters | ||
$state.go($state.get('delete'), angular.extend({ | ||
entity: scope.entity().name(), | ||
id: scope.entry().identifierValue | ||
}, $state.params)); | ||
} else { | ||
// link to anoter entity, so forget filters | ||
$state.go($state.get('delete'), { | ||
entity: scope.entity().name(), | ||
id: scope.entry().identifierValue | ||
}); | ||
} | ||
|
||
}; | ||
}, | ||
template: | ||
/** | ||
* Link to delete | ||
* | ||
* Usage: | ||
* <ma-delete-button entity="entity" entry="entry" size="xs"></ma-delete-button> | ||
*/ | ||
function maDeleteButtonDirective($state) { | ||
return { | ||
restrict: 'E', | ||
scope: { | ||
entity: '&', | ||
entityName: '@', | ||
entry: '&', | ||
size: '@', | ||
label: '@', | ||
}, | ||
link: function (scope, element, attrs) { | ||
scope.gotoDelete = () => { | ||
var entityName = scope.entity() ? scope.entity().name() : attrs.entityName; | ||
var params = entityName == $state.params.entity ? $state.params : {}; | ||
params.entity = entityName; | ||
params.id = scope.entry().identifierValue; | ||
$state.go($state.get('delete'), params); | ||
} | ||
scope.label = scope.label || 'Delete'; | ||
}, | ||
template: | ||
` <a class="btn btn-default" ng-class="size ? \'btn-\' + size : \'\'" ng-click="gotoDelete()"> | ||
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span> <span class="hidden-xs">{{ ::label }}</span> | ||
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span> <span class="hidden-xs">{{ ::label }}</span> | ||
</a>` | ||
}; | ||
} | ||
|
||
}; | ||
} | ||
|
||
maDeleteButtonDirective.$inject = ['$state']; | ||
maDeleteButtonDirective.$inject = ['$state']; | ||
|
||
return maDeleteButtonDirective; | ||
}); | ||
module.exports = maDeleteButtonDirective; |
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,43 +1,36 @@ | ||
/*global define*/ | ||
|
||
define(function () { | ||
'use strict'; | ||
|
||
function maEditButtonDirective($state) { | ||
return { | ||
restrict: 'E', | ||
scope: { | ||
entity: '&', | ||
entry: '&', | ||
size: '@', | ||
label: '@', | ||
}, | ||
link: function (scope) { | ||
scope.label = scope.label || 'Edit'; | ||
scope.gotoEdit = function () { | ||
if ($state.params.entity == scope.entity().name()) { | ||
// link to the same entity, so preserve active filters | ||
$state.go($state.get('edit'), angular.extend({ | ||
entity: scope.entity().name(), | ||
id: scope.entry().identifierValue | ||
}, $state.params)); | ||
} else { | ||
// link to anoter entity, so forget filters | ||
$state.go($state.get('edit'), { | ||
entity: scope.entity().name(), | ||
id: scope.entry().identifierValue | ||
}); | ||
} | ||
}; | ||
}, | ||
template: | ||
/** | ||
* Link to edit | ||
* | ||
* Usage: | ||
* <ma-edit-button entity="entity" entry="entry" size="xs"></ma-edit-button> | ||
*/ | ||
function maEditButtonDirective($state) { | ||
return { | ||
restrict: 'E', | ||
scope: { | ||
entity: '&', | ||
entityName: '@', | ||
entry: '&', | ||
size: '@', | ||
label: '@', | ||
}, | ||
link: function (scope, element, attrs) { | ||
scope.gotoEdit = () => { | ||
var entityName = scope.entity() ? scope.entity().name() : attrs.entityName; | ||
var params = entityName == $state.params.entity ? $state.params : {}; | ||
params.entity = entityName; | ||
params.id = scope.entry().identifierValue; | ||
$state.go($state.get('edit'), params); | ||
} | ||
scope.label = scope.label || 'Edit'; | ||
}, | ||
template: | ||
` <a class="btn btn-default" ng-class="size ? \'btn-\' + size : \'\'" ng-click="gotoEdit()"> | ||
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> <span class="hidden-xs">{{ ::label }}</span> | ||
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> <span class="hidden-xs">{{ ::label }}</span> | ||
</a>` | ||
}; | ||
} | ||
}; | ||
} | ||
|
||
maEditButtonDirective.$inject = ['$state']; | ||
maEditButtonDirective.$inject = ['$state']; | ||
|
||
return maEditButtonDirective; | ||
}); | ||
module.exports = maEditButtonDirective; |
Oops, something went wrong.