Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gyuricska Milán
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
4f31c740
authored
Nov 25, 2013
by
Kálmán Viktor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rework confirmation js part
parent
1450d8ee
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
58 additions
and
24 deletions
+58
-24
circle/dashboard/static/dashboard/dashboard.js
+23
-18
circle/dashboard/static/dashboard/vm-list.js
+9
-3
circle/dashboard/templates/dashboard/confirm/ajax-delete.html
+1
-1
circle/dashboard/templates/dashboard/confirm/mass-delete.html
+18
-0
circle/dashboard/views.py
+7
-2
No files found.
circle/dashboard/static/dashboard/dashboard.js
View file @
4f31c740
...
...
@@ -49,7 +49,12 @@ $(function () {
var
vm_pk
=
$
(
this
).
data
(
'vm-pk'
);
text
=
"Are you sure you want to delete this VM?"
;
var
dir
=
window
.
location
.
pathname
.
indexOf
(
'list'
)
==
-
1
;
addModalConfirmation
(
text
,
vm_pk
,
deleteVm
,
dir
);
addModalConfirmation
(
deleteVm
,
{
'url'
:
'/dashboard/vm/delete/'
+
vm_pk
+
'/'
,
'data'
:
[],
'vm_pk'
:
vm_pk
,
'redirect'
:
dir
});
return
false
;
});
});
...
...
@@ -79,17 +84,17 @@ function refreshSliders() {
/* deletes the VM with the pk
* if dir is true, then redirect to the dashboard landing page
* else it adds a success message */
function
deleteVm
(
pk
,
dir
)
{
function
deleteVm
(
data
)
{
$
.
ajax
({
type
:
'POST'
,
data
:
{
'redirect'
:
d
ir
},
url
:
'/dashboard/vm/delete/'
+
pk
+
'/'
,
data
:
{
'redirect'
:
d
ata
[
'redirect'
]
},
url
:
data
[
'url'
]
,
headers
:
{
"X-CSRFToken"
:
getCookie
(
'csrftoken'
)},
success
:
function
(
data
,
textStatus
,
xhr
)
{
if
(
!
d
ir
)
{
success
:
function
(
re
,
textStatus
,
xhr
)
{
if
(
!
d
ata
[
'redirect'
]
)
{
selected
=
[];
addMessage
(
data
[
'message'
],
'success'
);
$
(
'a[data-vm-pk="'
+
pk
+
'"]'
).
closest
(
'tr'
).
fadeOut
(
function
()
{
addMessage
(
re
[
'message'
],
'success'
);
$
(
'a[data-vm-pk="'
+
data
[
'vm_pk'
]
+
'"]'
).
closest
(
'tr'
).
fadeOut
(
function
()
{
$
(
this
).
remove
();
});
}
else
{
...
...
@@ -102,22 +107,22 @@ function deleteVm(pk, dir) {
});
}
function
massDeleteVm
()
{
function
massDeleteVm
(
data
)
{
$
.
ajax
({
traditional
:
true
,
url
:
'/dashboard/vm/mass-delete/'
,
url
:
data
[
'url'
]
,
headers
:
{
"X-CSRFToken"
:
getCookie
(
'csrftoken'
)},
type
:
'POST'
,
data
:
{
'vms'
:
collectIds
(
selected
)
},
success
:
function
(
data
,
textStatus
,
xhr
)
{
data
:
{
'vms'
:
data
[
'data'
][
'v'
]
},
success
:
function
(
re
,
textStatus
,
xhr
)
{
for
(
var
i
=
0
;
i
<
selected
.
length
;
i
++
)
$
(
'.vm-list-table tbody tr'
).
eq
(
selected
[
i
]).
fadeOut
(
500
,
function
()
{
$
(
'.vm-list-table tbody tr'
).
eq
(
data
[
'data'
][
'selected'
]
[
i
]).
fadeOut
(
500
,
function
()
{
// reset group buttons
selected
=
[]
$
(
'.vm-list-group-control a'
).
attr
(
'disabled'
,
true
);
$
(
this
).
remove
();
});
addMessage
(
data
[
'message'
],
'success'
);
addMessage
(
re
[
'message'
],
'success'
);
},
error
:
function
(
xhr
,
textStatus
,
error
)
{
// TODO this
...
...
@@ -134,11 +139,11 @@ function addMessage(text, type) {
}
function
addModalConfirmation
(
text
,
data
,
func
,
dir
)
{
function
addModalConfirmation
(
func
,
data
)
{
$
.
ajax
({
type
:
'GET'
,
url
:
'/dashboard/vm/delete/'
+
data
+
'/'
,
data
:
{
'text'
:
text
}
,
url
:
data
[
'url'
]
,
data
:
jQuery
.
param
(
data
[
'data'
])
,
success
:
function
(
result
)
{
$
(
'body'
).
append
(
result
);
$
(
'#confirmation-modal'
).
modal
(
'show'
);
...
...
@@ -146,7 +151,7 @@ function addModalConfirmation(text, data, func, dir) {
$
(
'#confirmation-modal'
).
remove
();
});
$
(
'#confirmation-modal-button'
).
click
(
function
()
{
func
(
data
,
dir
);
func
(
data
);
$
(
'#confirmation-modal'
).
modal
(
'hide'
);
});
}
...
...
circle/dashboard/static/dashboard/vm-list.js
View file @
4f31c740
...
...
@@ -103,9 +103,15 @@ $(function() {
/* mass vm delete */
$
(
'#vm-list-group-delete'
).
click
(
function
()
{
text
=
"Are you sure you want to delete the selected VMs?"
;
random_vm_pk
=
$
(
'.vm-delete'
).
eq
(
0
).
data
(
'vm-pk'
);
addModalConfirmation
(
text
,
random_vm_pk
,
massDeleteVm
,
false
);
addModalConfirmation
(
massDeleteVm
,
{
'url'
:
'/dashboard/vm/mass-delete/'
,
'data'
:
{
'selected'
:
selected
,
'v'
:
collectIds
(
selected
)
}
}
);
return
false
;
});
});
...
...
circle/dashboard/templates/dashboard/confirm/ajax-delete.html
View file @
4f31c740
...
...
@@ -2,7 +2,7 @@
<div
class=
"modal-dialog"
>
<div
class=
"modal-content"
>
<div
class=
"modal-body"
>
{{ request.GET.text }}
Are you sure you want to delete
<strong>
{{ object }}
</strong>
?
<br
/>
<div
class=
"pull-right"
>
<button
type=
"button"
class=
"btn btn-default"
data-dismiss=
"modal"
>
Cancel
</button>
...
...
circle/dashboard/templates/dashboard/confirm/mass-delete.html
0 → 100644
View file @
4f31c740
<div
class=
"modal fade"
id=
"confirmation-modal"
tabindex=
"-1"
role=
"dialog"
>
<div
class=
"modal-dialog"
>
<div
class=
"modal-content"
>
<div
class=
"modal-body"
>
Are you sure you want to delete these objects
<br
/>
{% for o in objects %}
<strong>
{{ o }}
</strong>
{% if not forloop.last %},{% endif %}
{% endfor %}
?
<div
class=
"pull-right"
style=
"margin-top: 40px;"
>
<button
type=
"button"
class=
"btn btn-default"
data-dismiss=
"modal"
>
Cancel
</button>
<button
id=
"confirmation-modal-button"
type=
"button"
class=
"btn btn-danger"
>
Delete
</button>
</div>
<div
class=
"clearfix"
></div>
</div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
circle/dashboard/views.py
View file @
4f31c740
...
...
@@ -9,7 +9,7 @@ from django.core.exceptions import PermissionDenied
from
django.core
import
signing
from
django.core.urlresolvers
import
reverse
,
reverse_lazy
from
django.http
import
HttpResponse
,
HttpResponseRedirect
from
django.shortcuts
import
redirect
from
django.shortcuts
import
redirect
,
render
from
django.views.decorators.http
import
require_POST
from
django.views.generic.detail
import
SingleObjectMixin
from
django.views.generic
import
TemplateView
,
DetailView
,
View
,
DeleteView
...
...
@@ -332,8 +332,13 @@ class VmDelete(DeleteView):
return
reverse_lazy
(
'dashboard.index'
)
@require_POST
def
mass_delete_vm
(
request
,
**
kwargs
):
if
request
.
method
==
"GET"
:
vms
=
request
.
GET
.
getlist
(
'v[]'
)
objects
=
Instance
.
objects
.
filter
(
pk__in
=
vms
)
return
render
(
request
,
"dashboard/confirm/mass-delete.html"
,
{
'objects'
:
objects
})
vms
=
request
.
POST
.
getlist
(
'vms'
)
names
=
[]
if
vms
is
not
None
:
...
...
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