1
0
mirror of https://github.com/dkmstr/openuds.git synced 2024-12-22 13:34:04 +03:00

Added "multiple deletions" feature

This commit is contained in:
Adolfo Gómez García 2015-09-23 03:31:26 +02:00
parent 2d7a2d6049
commit 80bf6d77f1
3 changed files with 96 additions and 53 deletions

View File

@ -20,7 +20,6 @@ gui.providers.link = (event) ->
prevTables = []
clearDetails = ->
gui.doLog "Clearing details"
$.each prevTables, (undefined_, tbl) ->
$tbl = $(tbl).dataTable()
$tbl.fnClearTable()
@ -58,15 +57,8 @@ gui.providers.link = (event) ->
getPermission: (selected) ->
gui.doLog "Selected", selected
container: "providers-placeholder"
rowSelect: "single"
rowSelect: "multi"
onCheck: (check, items) -> # Check if item can be deleted
#if( check == 'delete' ) {
# for( var i in items ) {
# if( items[i].services_count > 0)
# return false;
# }
# return true;
# }
true
onData: (data) ->
@ -99,7 +91,7 @@ gui.providers.link = (event) ->
servicesTable = services.table(
icon: 'services'
container: "services-placeholder"
rowSelect: "single"
rowSelect: "multi"
onRowSelect: (sselected) ->
gui.tools.blockUI()
sId = sselected[0].id
@ -152,7 +144,13 @@ gui.providers.link = (event) ->
permission: api.permissions.MANAGEMENT
text: gettext("Maintenance")
css: "disabled"
click: (val, value, btn, tbl, refreshFnc) ->
click: (vals, value, btn, tbl, refreshFnc) ->
if vals.length > 1
return
val = vals[0]
gui.promptModal gettext("Maintenance Mode"), (if val.maintenance_mode is false then gettext("Enter Maintenance Mode?") else gettext("Exit Maintenance Mode?")),
onYes: ->
gui.doLog 'Val: ', val
@ -166,12 +164,13 @@ gui.providers.link = (event) ->
return
select: (val, value, btn, tbl, refreshFnc) ->
unless val
$(btn).removeClass("btn3d-warning").addClass "disabled"
select: (vals, value, btn, tbl, refreshFnc) ->
unless vals.length == 1
$(btn).removeClass("btn-warning").addClass "disabled"
$(btn).empty().append(gettext("Maintenance"))
return
$(btn).removeClass("disabled").addClass "btn3d-warning"
val = vals[0]
$(btn).removeClass("disabled").addClass "btn-warning"
$(btn).empty().append('<div>' + (if val.maintenance_mode is false then gettext('Enter maintenance Mode') else gettext('Exit Maintenance Mode')) + '</div>')
return
}

View File

@ -237,22 +237,22 @@
false # This may be used on button or href, better disable execution of it
btns = []
if tblParams.buttons
if tblParams.buttons
# Generic click handler generator for this table
clickHandlerFor = (handler, action, newHandler) ->
handleFnc = handler or (val, action, tbl) ->
gui.doLog "Default handler called for ", action
gui.doLog "Setting click handler for ", handler, action, newHandler
handleFnc = handler or (sel, action, dtable, refreshFnc) ->
gui.doLog "Default handler called for ", sel, action
return
(btn) ->
tbl = $("#" + tableId).dataTable()
val = @fnGetSelectedData()[0]
fnc = (btn, sel, dtable) ->
gui.doLog "click handler: ", action, btn, sel, dtable
setTimeout (->
if newHandler
handleFnc action, tbl, refreshFnc
handleFnc action, dtable, refreshFnc
else
handleFnc val, action, tbl, refreshFnc
handleFnc sel, action, dtable, refreshFnc
return
), 0
return
@ -262,8 +262,7 @@
# methods for buttons on row select
editSelected = (btn, obj, node) ->
sel = @fnGetSelectedData()
editSelected = (btn, sel, dtable) ->
enable = (if sel.length is 1 then onCheck("edit", sel) else false)
if enable
$(btn).removeClass("disabled").addClass "btn-success"
@ -271,17 +270,15 @@
$(btn).removeClass("btn-success").addClass "disabled"
return
deleteSelected = (btn, obj, node) ->
sel = @fnGetSelectedData()
enable = (if sel.length is 1 then onCheck("delete", sel) else false)
deleteSelected = (btn, sel, dtable) ->
enable = (if sel.length >= 1 then onCheck("delete", sel) else false)
if enable
$(btn).removeClass("disabled").addClass "btn-danger"
else
$(btn).removeClass("btn-danger").addClass "disabled"
return
permissionsSelected = (btn, obj, node) ->
sel = @fnGetSelectedData()
permissionsSelected = (btn, sel, dtable) ->
enable = (if sel.length is 1 then onCheck("delete", sel) else false)
if enable
$(btn).removeClass("disabled").addClass "btn-success"
@ -325,14 +322,20 @@
type: "text"
content: gui.config.dataTableButtons["new"].text
css: gui.config.dataTableButtons["new"].css
fnClick: clickHandlerFor(tblParams.onNew, "new", true)
fnClick: () ->
selecteds = dTable.rows({selected: true}).data()
gui.doLog "New click: ", selecteds, dTable, refreshFnc
tblParams.onNew "new", dTable, refreshFnc
when "edit"
if self.rest.permission() >= api.permissions.MANAGEMENT
btn =
type: "text"
content: gui.config.dataTableButtons.edit.text
fnSelect: editSelected
fnClick: clickHandlerFor(tblParams.onEdit, "edit")
fnClick: () ->
selecteds = dTable.rows({selected: true}).data()
gui.doLog "Edit click: ", selecteds, dTable, refreshFnc
tblParams.onEdit selecteds[0], "edit", dTable, refreshFnc
css: gui.config.dataTableButtons.edit.css
when "delete"
if self.rest.permission() >= api.permissions.MANAGEMENT
@ -340,8 +343,11 @@
type: "text"
content: gui.config.dataTableButtons["delete"].text
fnSelect: deleteSelected
fnClick: clickHandlerFor(tblParams.onDelete, "delete")
css: gui.config.dataTableButtons["delete"].css
fnClick: () ->
selecteds = dTable.rows({selected: true}).data()
gui.doLog "delete click: ", selecteds, dTable, refreshFnc
tblParams.onDelete selecteds, "delete", dTable, refreshFnc
when "refresh"
btn =
type: "text"
@ -376,20 +382,17 @@
css: css
if value.click
btn.fnClick = (btn) ->
tbl = $("#" + tableId).dataTable()
val = @fnGetSelectedData()[0]
btn.fnClick = () ->
selecteds = dTable.rows({selected: true}).data()
setTimeout (->
value.click val, value, btn, tbl, refreshFnc
value.click selecteds, value, this, dTable, refreshFnc
return
), 0
return
if value.select
btn.fnSelect = (btn) ->
tbl = $("#" + tableId).dataTable()
val = @fnGetSelectedData()[0]
btn.fnSelect = (btn, selecteds, dtable) ->
setTimeout (->
value.select val, value, btn, tbl, refreshFnc
value.select selecteds, value, btn, dTable, refreshFnc
return
), 0
return
@ -457,16 +460,34 @@
rowDeselectedFnc rows, dt
return
# For storing on select callbacks
selCallbackList = []
# Add buttons
for btn in btns
$div = $('div.'+tbId)
if btn.type == 'text'
btnId = gui.genRamdonId('btn')
$div.append('<button id="' + btnId + '" class="' + btn.css + '">' + btn.content + '</button>')
$('#'+btnId).on('click', btn.fnClick)
$btn = $('#'+btnId)
$btn.on 'click', btn.fnClick
if btn.fnSelect?
selCallbackList.push
btnId: '#' + btnId
callback: btn.fnSelect
else
$div.append('<div style="float: left;">' + btn.content + '</div>')
# Listener for callbacks
selCallback = (e, dt, type, indexes) ->
for v in selCallbackList
rows = dt.rows({selected: true}).data()
v.callback($(v.btnId), rows, dt)
dTable.on 'select', selCallback
dTable.on 'deselect', selCallback
# Fix form
$("#" + tableId + "_filter input").addClass "form-control"

View File

@ -62,7 +62,7 @@
custom:
text: null
css: "btn btn-default btn3d-tables"
css: "btn btn-default btn-tables"
gui.genRamdonId = (prefix) ->
prefix = prefix or ""
@ -398,20 +398,43 @@
return
gui.methods.del = (parent, modalTitle, modalErrorMsg) ->
(value, event, table, refreshFnc) ->
gui.doLog value
name = value.name or value.friendly_name
content = gettext("Are you sure do you want to delete ") + "<b>" + name + "</b>"
(values, type, table, refreshFnc) ->
names = ((value.name or value.friendly_name) for value in values).join(', ')
content = gettext("Are you sure do you want to delete ") + values.length + ' ' + gettext('items:') + " <b>" + names + "</b>"
modalId = gui.launchModal(modalTitle, content,
actionButton: "<button type=\"button\" class=\"btn btn-danger button-accept\">" + gettext("Delete") + "</button>"
)
# Will show results once
msgs = []
count = values.length
deletedFnc = (name, errorMsg) ->
count -= 1
if errorMsg?
msgs.push '<span class="text-danger">' + gettext("Error deleting") + " <b>" + name + "</b>: " + errorMsg + '</span>'
else
msgs.push gettext("Successfully deleted") + " <b>" + name + "</b>"
if count == 0
gui.tools.unblockUI()
refreshFnc()
gui.launchModal gettext('Deletion results'), '<ul><li>' + msgs.join('</li><li>') + '</li></ul>',
actionButton: " "
closeButton: '<button type="button" class="btn btn-default" data-dismiss="modal">Ok</button>'
$(modalId + " .button-accept").click ->
$(modalId).modal "hide"
parent.rest.del value.id, (->
refreshFnc()
gui.notify gettext("Sucess"), "success"
return
), gui.failRequestModalFnc(modalErrorMsg)
gui.tools.blockUI()
for value in values
((value) ->
parent.rest.del value.id, (->
name = value.name or value.friendly_name
deletedFnc name
return
), (jqXHR, textStatus, errorThrown) -> # fail on put
deletedFnc name, jqXHR.responseText)(value)
return
return