Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
94
Merge Requests
10
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
65fb81e6
authored
Jan 30, 2014
by
Kálmán Viktor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: delete templates and leases
parent
67bf3744
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
132 additions
and
3 deletions
+132
-3
circle/dashboard/static/dashboard/template-list.js
+61
-0
circle/dashboard/templates/dashboard/template-list.html
+4
-0
circle/dashboard/templates/dashboard/template-list/column-lease-actions.html
+1
-1
circle/dashboard/templates/dashboard/template-list/column-template-actions.html
+1
-1
circle/dashboard/urls.py
+5
-1
circle/dashboard/views.py
+60
-0
No files found.
circle/dashboard/static/dashboard/template-list.js
0 → 100644
View file @
65fb81e6
$
(
function
()
{
/* for template removes buttons */
$
(
'.template-delete'
).
click
(
function
()
{
var
template_pk
=
$
(
this
).
data
(
'template-pk'
);
addModalConfirmation
(
deleteTemplate
,
{
'url'
:
'/dashboard/template/delete/'
+
template_pk
+
'/'
,
'data'
:
[],
'template_pk'
:
template_pk
,
});
return
false
;
});
/* for lease removes buttons */
$
(
'.lease-delete'
).
click
(
function
()
{
var
lease_pk
=
$
(
this
).
data
(
'lease-pk'
);
addModalConfirmation
(
deleteLease
,
{
'url'
:
'/dashboard/lease/delete/'
+
lease_pk
+
'/'
,
'data'
:
[],
'lease_pk'
:
lease_pk
,
});
return
false
;
});
});
// send POST request then delete the row in table
function
deleteTemplate
(
data
)
{
$
.
ajax
({
type
:
'POST'
,
url
:
data
[
'url'
],
headers
:
{
"X-CSRFToken"
:
getCookie
(
'csrftoken'
)},
success
:
function
(
re
,
textStatus
,
xhr
)
{
addMessage
(
re
[
'message'
],
'success'
);
$
(
'a[data-template-pk="'
+
data
[
'template_pk'
]
+
'"]'
).
closest
(
'tr'
).
fadeOut
(
function
()
{
$
(
this
).
remove
();
});
},
error
:
function
(
xhr
,
textStatus
,
error
)
{
addMessage
(
'Uh oh :('
,
'danger'
)
}
});
}
// send POST request then delete the row in table
function
deleteLease
(
data
)
{
$
.
ajax
({
type
:
'POST'
,
url
:
data
[
'url'
],
headers
:
{
"X-CSRFToken"
:
getCookie
(
'csrftoken'
)},
success
:
function
(
re
,
textStatus
,
xhr
)
{
addMessage
(
re
[
'message'
],
'success'
);
$
(
'a[data-lease-pk="'
+
data
[
'lease_pk'
]
+
'"]'
).
closest
(
'tr'
).
fadeOut
(
function
()
{
$
(
this
).
remove
();
});
},
error
:
function
(
xhr
,
textStatus
,
error
)
{
addMessage
(
'Uh oh :('
,
'danger'
)
}
});
}
circle/dashboard/templates/dashboard/template-list.html
View file @
65fb81e6
...
...
@@ -67,3 +67,7 @@
}
</style>
{% endblock %}
{% block extra_js %}
<script
src=
"{{ STATIC_URL}}dashboard/template-list.js"
></script>
{% endblock %}
circle/dashboard/templates/dashboard/template-list/column-lease-actions.html
View file @
65fb81e6
...
...
@@ -2,6 +2,6 @@
<a
href=
"{% url "
dashboard
.
views
.
lease-detail
"
pk=
record.pk
%}"
id=
"template-list-edit-button"
class=
"btn btn-default btn-xs"
title
data-original-title=
"{% trans "
Edit
"
%}"
>
<i
class=
"icon-edit"
></i>
</a>
<a
href=
"#"
class=
"btn btn-danger btn-xs"
title
data-original-
title=
"{% trans "
Delete
"
%}"
>
<a
data-lease-pk=
"{{ record.pk }}"
href=
"{% url "
dashboard
.
views
.
lease-delete
"
pk=
record.pk
%}"
class=
"btn btn-danger btn-xs lease-delete"
title=
"{% trans "
Delete
"
%}"
>
<i
class=
"icon-remove"
></i>
</a>
circle/dashboard/templates/dashboard/template-list/column-template-actions.html
View file @
65fb81e6
...
...
@@ -5,6 +5,6 @@
<a
href=
"{% url "
dashboard
.
views
.
template-detail
"
pk=
record.pk%}"
id=
"template-list-edit-button"
class=
"btn btn-default btn-xs"
title
data-original-title=
"{% trans "
Edit
"
%}"
>
<i
class=
"icon-edit"
></i>
</a>
<a
href=
"#"
class=
"btn btn-danger btn-xs"
title
data-original-
title=
"{% trans "
Delete
"
%}"
>
<a
data-template-pk=
"{{ record.pk }}"
href=
"{% url "
dashboard
.
views
.
template-delete
"
pk=
record.pk
%}"
class=
"btn btn-danger btn-xs template-delete"
title=
"{% trans "
Delete
"
%}"
>
<i
class=
"icon-remove"
></i>
</a>
circle/dashboard/urls.py
View file @
65fb81e6
...
...
@@ -6,7 +6,7 @@ from .views import (
VmDelete
,
VmMassDelete
,
vm_activity
,
NodeList
,
NodeDetailView
,
PortDelete
,
TransferOwnershipView
,
TransferOwnershipConfirmView
,
NodeDelete
,
TemplateList
,
LeaseDetail
,
NodeCreate
,
LeaseCreate
,
TemplateCreate
,
FavouriteView
,
NodeStatus
,
GroupList
,
FavouriteView
,
NodeStatus
,
GroupList
,
TemplateDelete
,
LeaseDelete
,
)
urlpatterns
=
patterns
(
...
...
@@ -16,12 +16,16 @@ urlpatterns = patterns(
name
=
"dashboard.views.lease-detail"
),
url
(
r'^lease/create/$'
,
LeaseCreate
.
as_view
(),
name
=
"dashboard.views.lease-create"
),
url
(
r'^lease/delete/(?P<pk>\d+)/$'
,
LeaseDelete
.
as_view
(),
name
=
"dashboard.views.lease-delete"
),
url
(
r'^template/create/$'
,
TemplateCreate
.
as_view
(),
name
=
"dashboard.views.template-create"
),
url
(
r'^template/(?P<pk>\d+)/$'
,
TemplateDetail
.
as_view
(),
name
=
'dashboard.views.template-detail'
),
url
(
r"^template/list/$"
,
TemplateList
.
as_view
(),
name
=
"dashboard.views.template-list"
),
url
(
r"^template/delete/(?P<pk>\d+)/$"
,
TemplateDelete
.
as_view
(),
name
=
"dashboard.views.template-delete"
),
url
(
r'^vm/(?P<pk>\d+)/remove_port/(?P<rule>\d+)/$'
,
PortDelete
.
as_view
(),
name
=
'dashboard.views.remove-port'
),
url
(
r'^vm/(?P<pk>\d+)/$'
,
VmDetailView
.
as_view
(),
...
...
circle/dashboard/views.py
View file @
65fb81e6
...
...
@@ -534,6 +534,37 @@ class TemplateList(LoginRequiredMixin, SingleTableView):
'user'
,
self
.
request
.
user
)
.
all
()
class
TemplateDelete
(
LoginRequiredMixin
,
DeleteView
):
model
=
InstanceTemplate
def
get_success_url
(
self
):
return
reverse
(
"dashboard.views.template-list"
)
def
get_template_names
(
self
):
if
self
.
request
.
is_ajax
():
return
[
'dashboard/confirm/ajax-delete.html'
]
else
:
return
[
'dashboard/confirm/base-delete.html'
]
def
delete
(
self
,
request
,
*
args
,
**
kwargs
):
object
=
self
.
get_object
()
if
not
object
.
has_level
(
request
.
user
,
'owner'
):
raise
PermissionDenied
()
object
.
delete
()
success_url
=
self
.
get_success_url
()
success_message
=
_
(
"Template successfully deleted!"
)
if
request
.
is_ajax
():
return
HttpResponse
(
json
.
dumps
({
'message'
:
success_message
}),
content_type
=
"application/json"
,
)
else
:
messages
.
success
(
request
,
success_message
)
return
HttpResponseRedirect
(
success_url
)
class
VmList
(
LoginRequiredMixin
,
SingleTableView
):
template_name
=
"dashboard/vm-list.html"
table_class
=
VmListTable
...
...
@@ -958,6 +989,35 @@ class LeaseDetail(LoginRequiredMixin, SuccessMessageMixin, UpdateView):
return
reverse_lazy
(
"dashboard.views.lease-detail"
,
kwargs
=
self
.
kwargs
)
class
LeaseDelete
(
LoginRequiredMixin
,
SuperuserRequiredMixin
,
DeleteView
):
model
=
Lease
def
get_success_url
(
self
):
return
reverse
(
"dashboard.views.template-list"
)
def
get_template_names
(
self
):
if
self
.
request
.
is_ajax
():
return
[
'dashboard/confirm/ajax-delete.html'
]
else
:
return
[
'dashboard/confirm/base-delete.html'
]
def
delete
(
self
,
request
,
*
args
,
**
kwargs
):
object
=
self
.
get_object
()
object
.
delete
()
success_url
=
self
.
get_success_url
()
success_message
=
_
(
"Lease successfully deleted!"
)
if
request
.
is_ajax
():
return
HttpResponse
(
json
.
dumps
({
'message'
:
success_message
}),
content_type
=
"application/json"
,
)
else
:
messages
.
success
(
request
,
success_message
)
return
HttpResponseRedirect
(
success_url
)
@require_POST
def
vm_activity
(
request
,
pk
):
object
=
Instance
.
objects
.
get
(
pk
=
pk
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment