Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFR] Add default value parameter for create view and create-button directive #696

Merged
merged 3 commits into from
Sep 21, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/blog/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
.sortDir('DESC')
.listActions(['edit']),
nga.field('', 'template').label('')
.template('<span class="pull-right"><ma-filtered-list-button entity-name="comments" filter="{ post_id: entry.values.id }" size="sm"></ma-filtered-list-button></span>')
.template('<span class="pull-right"><ma-filtered-list-button entity-name="comments" filter="{ post_id: entry.values.id }" size="sm"></ma-filtered-list-button><ma-create-button entity-name="comments" size="sm" label="Create related comment" default-values="{ post_id: entry.values.id }"></ma-create-button></span>')
]);

post.showView() // a showView displays one entry in full page - allows to display more data than in a a list
Expand Down
49 changes: 23 additions & 26 deletions src/javascripts/ng-admin/Crud/button/maBackButton.js
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>&nbsp;<span class="hidden-xs">{{ ::label }}</span>
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>&nbsp;<span class="hidden-xs">{{ ::label }}</span>
</a>`
};
}
};
}

maBackButtonDirective.$inject = ['$window'];
maBackButtonDirective.$inject = ['$window'];

return maBackButtonDirective;
});
module.exports = maBackButtonDirective;
61 changes: 27 additions & 34 deletions src/javascripts/ng-admin/Crud/button/maBatchDeleteButton.js
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>&nbsp;<span class="hidden-xs">{{ ::label }}</span>
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span>&nbsp;<span class="hidden-xs">{{ ::label }}</span>
</span>`
};
}

};
}

maBatchDeleteButtonDirective.$inject = ['$state'];
maBatchDeleteButtonDirective.$inject = ['$state'];

return maBatchDeleteButtonDirective;
});
module.exports = maBatchDeleteButtonDirective;
69 changes: 32 additions & 37 deletions src/javascripts/ng-admin/Crud/button/maCreateButton.js
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>&nbsp;<span class="hidden-xs">{{ ::label }}</span>
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>&nbsp;<span class="hidden-xs">{{ ::label }}</span>
</a>`
};
}
};
}

maCreateButtonDirective.$inject = ['$state'];
maCreateButtonDirective.$inject = ['$state'];

return maCreateButtonDirective;
});
module.exports = maCreateButtonDirective;
73 changes: 32 additions & 41 deletions src/javascripts/ng-admin/Crud/button/maDeleteButton.js
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>&nbsp;<span class="hidden-xs">{{ ::label }}</span>
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span>&nbsp;<span class="hidden-xs">{{ ::label }}</span>
</a>`
};
}

};
}

maDeleteButtonDirective.$inject = ['$state'];
maDeleteButtonDirective.$inject = ['$state'];

return maDeleteButtonDirective;
});
module.exports = maDeleteButtonDirective;
71 changes: 32 additions & 39 deletions src/javascripts/ng-admin/Crud/button/maEditButton.js
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>&nbsp;<span class="hidden-xs">{{ ::label }}</span>
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>&nbsp;<span class="hidden-xs">{{ ::label }}</span>
</a>`
};
}
};
}

maEditButtonDirective.$inject = ['$state'];
maEditButtonDirective.$inject = ['$state'];

return maEditButtonDirective;
});
module.exports = maEditButtonDirective;
Loading