Use initAction() instead initScope()
initScope() for actions is deprecated in Ocata. This patch use initAction() instead initScope(). New scope is now provided as the second argument of perform(). Change-Id: I6cc514faab93087cc46b96622f5aa27abc85f186
This commit is contained in:
parent
1b529bf087
commit
c82a581f46
@ -48,7 +48,7 @@
|
||||
};
|
||||
|
||||
var service = {
|
||||
initScope: initScope,
|
||||
initAction: initAction,
|
||||
perform: perform,
|
||||
allowed: allowed
|
||||
};
|
||||
@ -57,10 +57,15 @@
|
||||
|
||||
//////////////
|
||||
|
||||
function initScope() {
|
||||
// fixme: include this function in your service
|
||||
// if you plan to emit events to the parent controller,
|
||||
// otherwise remove it
|
||||
function initAction() {
|
||||
}
|
||||
|
||||
function perform() {
|
||||
// fixme: if newScope is unnecessary, remove it
|
||||
/* eslint-disable no-unused-vars */
|
||||
function perform(selected, newScope) {
|
||||
// modal title, buttons
|
||||
var title, submitText, submitIcon;
|
||||
title = gettext("Create {{cookiecutter.panel_func}}");
|
||||
@ -74,10 +79,11 @@
|
||||
|
||||
function allowed() {
|
||||
return $qExtensions.booleanAsPromise(true);
|
||||
//return policy.ifAllowed({ rules: [['{{cookiecutter.panel}}', 'add_{{cookiecutter.panel}}']] });
|
||||
// fixme: if you need to set policy, change as follow
|
||||
//return policy.ifAllowed({ rules: [['{{cookiecutter.panel}}', 'create_{{cookiecutter.panel}}']] });
|
||||
}
|
||||
|
||||
function submit(){
|
||||
function submit() {
|
||||
model.cleanProperties();
|
||||
return api.create{{cookiecutter.panel_func}}(model.spec).then(success);
|
||||
}
|
||||
@ -87,9 +93,9 @@
|
||||
toast.add('success', interpolate(message.success, [response.data.id]));
|
||||
var result = actionResult.getActionResult()
|
||||
.created(resourceType, response.data.id);
|
||||
if(result.result.failed.length == 0 && result.result.created.length > 0){
|
||||
if (result.result.failed.length === 0 && result.result.created.length > 0) {
|
||||
$location.path('/{{cookiecutter.dashboard}}/{{cookiecutter.panel}}s');
|
||||
}else{
|
||||
} else {
|
||||
return result.result;
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,14 @@
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* @ngDoc factory
|
||||
* @name horizon.dashboard.{{cookiecutter.panel_group}}.{{cookiecutter.panel}}s.delete.service
|
||||
* @Description
|
||||
* Brings up the delete {{cookiecutter.panel}}s confirmation modal dialog.
|
||||
* On submit, delete selected resources.
|
||||
* On cancel, do nothing.
|
||||
*/
|
||||
angular
|
||||
.module('horizon.dashboard.{{cookiecutter.panel_group}}.{{cookiecutter.panel}}s')
|
||||
.factory('horizon.dashboard.{{cookiecutter.panel_group}}.{{cookiecutter.panel}}s.delete.service', deleteService);
|
||||
@ -33,16 +41,9 @@
|
||||
'horizon.dashboard.{{cookiecutter.panel_group}}.{{cookiecutter.panel}}s.events'
|
||||
];
|
||||
|
||||
/**
|
||||
* @ngDoc factory
|
||||
* @name horizon.dashboard.{{cookiecutter.panel_group}}.{{cookiecutter.panel}}s.delete.service
|
||||
* @Description
|
||||
* Brings up the delete {{cookiecutter.panel}}s confirmation modal dialog.
|
||||
* On submit, delete selected resources.
|
||||
* On cancel, do nothing.
|
||||
*/
|
||||
function deleteService(
|
||||
$location, $q, api, policy, actionResult, gettext, $qExtensions, deleteModal, toast, resourceType, events
|
||||
$location, $q, api, policy, actionResult, gettext, $qExtensions,
|
||||
deleteModal, toast, resourceType, events
|
||||
) {
|
||||
var scope;
|
||||
var context = {
|
||||
@ -51,34 +52,38 @@
|
||||
successEvent: events.DELETE_SUCCESS
|
||||
};
|
||||
var service = {
|
||||
initScope: initScope,
|
||||
initAction: initAction,
|
||||
allowed: allowed,
|
||||
perform: perform
|
||||
};
|
||||
var notAllowedMessage = gettext("You are not allowed to delete {{cookiecutter.panel}}s: %s");
|
||||
var notAllowedMessage =
|
||||
gettext("You are not allowed to delete {{cookiecutter.panel}}s: %s");
|
||||
|
||||
return service;
|
||||
|
||||
//////////////
|
||||
|
||||
// include this function in your service
|
||||
// if you plan to emit events to the parent controller
|
||||
function initScope($scope) {
|
||||
scope = $scope;
|
||||
// fixme: include this function in your service
|
||||
// if you plan to emit events to the parent controller,
|
||||
// otherwise remove it
|
||||
function initAction() {
|
||||
}
|
||||
|
||||
function allowed() {
|
||||
return $qExtensions.booleanAsPromise(true);
|
||||
// fixme: if you need to set policy, change as follow
|
||||
//return policy.ifAllowed({ rules: [['{{cookiecutter.panel}}', 'delete_{{cookiecutter.panel}}']] });
|
||||
}
|
||||
|
||||
// delete selected resource objects
|
||||
function perform(selected) {
|
||||
var selected = angular.isArray(selected) ? selected : [selected];
|
||||
function perform(selected, newScope) {
|
||||
scope = newScope;
|
||||
selected = angular.isArray(selected) ? selected : [selected];
|
||||
context.labels = labelize(selected.length);
|
||||
return $qExtensions.allSettled(selected.map(checkPermission)).then(afterCheck);
|
||||
}
|
||||
|
||||
function labelize(count){
|
||||
function labelize(count) {
|
||||
return {
|
||||
title: ngettext('Confirm Delete {{cookiecutter.panel_func}}',
|
||||
'Confirm Delete {{cookiecutter.panel_func}}s', count),
|
||||
@ -101,7 +106,7 @@
|
||||
}
|
||||
|
||||
// for batch delete
|
||||
function afterCheck(result){
|
||||
function afterCheck(result) {
|
||||
var outcome = $q.reject(); // Reject the promise by default
|
||||
if (result.fail.length > 0) {
|
||||
toast.add('error', getMessage(notAllowedMessage, result.fail));
|
||||
@ -123,9 +128,9 @@
|
||||
deleteModalResult.fail.forEach(function markFailed(item) {
|
||||
result.failed(resourceType, getEntity(item).id);
|
||||
});
|
||||
if(result.result.failed.length == 0 && result.result.deleted.length > 0){
|
||||
if (result.result.failed.length === 0 && result.result.deleted.length > 0) {
|
||||
$location.path('/{{cookiecutter.dashboard}}/{{cookiecutter.panel}}s');
|
||||
}else{
|
||||
} else {
|
||||
return result.result;
|
||||
}
|
||||
}
|
||||
@ -144,7 +149,7 @@
|
||||
}
|
||||
|
||||
// call delete REST API
|
||||
function deleteEntity(id){
|
||||
function deleteEntity(id) {
|
||||
return api.delete{{cookiecutter.panel_func}}(id, true);
|
||||
}
|
||||
}
|
||||
|
@ -48,7 +48,7 @@
|
||||
};
|
||||
|
||||
var service = {
|
||||
initScope: initScope,
|
||||
initAction: initAction,
|
||||
perform: perform,
|
||||
allowed: allowed
|
||||
};
|
||||
@ -59,10 +59,15 @@
|
||||
|
||||
//////////////
|
||||
|
||||
function initScope() {
|
||||
// fixme: include this function in your service
|
||||
// if you plan to emit events to the parent controller,
|
||||
// otherwise remove it
|
||||
function initAction() {
|
||||
}
|
||||
|
||||
function perform(selected) {
|
||||
// fixme: if newScope is unnecessary, remove it
|
||||
/* eslint-disable no-unused-vars */
|
||||
function perform(selected, newScope) {
|
||||
// modal title, buttons
|
||||
var title, submitText, submitIcon;
|
||||
title = gettext("Update {{cookiecutter.panel_func}}");
|
||||
@ -93,10 +98,11 @@
|
||||
|
||||
function allowed() {
|
||||
return $qExtensions.booleanAsPromise(true);
|
||||
//return policy.ifAllowed({ rules: [['{{cookiecutter.panel}}', 'add_{{cookiecutter.panel}}']] });
|
||||
// fixme: if you need to set policy, change as follow
|
||||
//return policy.ifAllowed({ rules: [['{{cookiecutter.panel}}', 'update_{{cookiecutter.panel}}']] });
|
||||
}
|
||||
|
||||
function submit(){
|
||||
function submit() {
|
||||
model.cleanProperties();
|
||||
return api.update{{cookiecutter.panel_func}}(id, model.spec).then(success);
|
||||
}
|
||||
@ -106,9 +112,9 @@
|
||||
toast.add('success', interpolate(message.success, [response.data.id]));
|
||||
var result = actionResult.getActionResult()
|
||||
.updated(resourceType, response.data.id);
|
||||
if(result.result.failed.length == 0 && result.result.updated.length > 0){
|
||||
if (result.result.failed.length === 0 && result.result.updated.length > 0) {
|
||||
$location.path('/{{cookiecutter.dashboard}}/{{cookiecutter.panel}}s');
|
||||
}else{
|
||||
} else {
|
||||
return result.result;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user