1
0
mirror of https://github.com/dkmstr/openuds.git synced 2025-01-24 02:04:09 +03:00

Adding Access calendars admin

This commit is contained in:
Adolfo Gómez García 2016-02-23 09:44:40 +01:00
parent 6587d9ba2c
commit 8376e81532
12 changed files with 546 additions and 264 deletions

View File

@ -60,13 +60,26 @@ class AccessCalendars(DetailHandler):
'''
Processes the transports detail requests of a Service Pool
'''
@staticmethod
def as_dict(item):
return {
'id': item.uuid,
'calendarId': item.calendar.uuid,
'name': item.calendar.name,
'access': item.access,
'priority': item.priority,
}
def getItems(self, parent, item):
return [{
'id': i.uuid,
'name': i.calendar.name,
'action': ALLOW if i.allow else DENY,
'priority': i.priority,
} for i in parent.calendaraccess_set.all()]
try:
if item is None:
return [AccessCalendars.as_dict(i) for i in parent.calendaraccess_set.all()]
else:
i = CalendarAccess.objects.get(uuid=processUuid(item))
return AccessCalendars.as_dict(i)
except Exception:
raise InvalidItemException()
def getTitle(self, parent):
return _('Access restrictions by calendar')
@ -75,28 +88,28 @@ class AccessCalendars(DetailHandler):
return [
{'priority': {'title': _('Priority'), 'type': 'numeric', 'width': '6em'}},
{'name': {'title': _('Name')}},
{'action': {'title': _('Rule')}},
{'access': {'title': _('Access')}},
]
def saveItem(self, parent, item):
# If already exists
uuid = self._params['id']
uuid = processUuid(self._params['id']) if 'id' in self._params else None
calendar = Calendar.objects.get(uuid=processUuid(self._params['calendarId']))
allow = self._params['allow'].upper() == ALLOW
access = self._params['access'].upper()
priority = int(self._params['priority'])
try:
if uuid is not None:
calAccess = CalendarAccess.objects.get(uuid=uuid)
calAccess.calendar = calendar
calAccess.servicePool = parent
calAccess.allow = allow
calAccess.access = access
calAccess.priority = priority
calAccess.save()
except CalendarAccess.DoesNotExist:
CalendarAccess.objects.create(uuid=uuid, calendar=calendar, servicePool=parent, allow=allow, priority=priority)
else:
CalendarAccess.objects.create(calendar=calendar, servicePool=parent, access=access, priority=priority)
return self.success()
def deleteItem(self, parent, item):
Calendar.objects.get(uuid=processUuid(self._args[0])).delete()
CalendarAccess.objects.get(uuid=processUuid(self._args[0])).delete()

View File

@ -105,7 +105,7 @@ class ServicesPools(ModelHandler):
'user_services_count': item.userServices.count(),
'restrained': item.isRestrained(),
'show_transports': item.show_transports,
'allowAccessByDefault': item.fallbackAccess,
'fallbackAccess': item.fallbackAccess,
'permission': permissions.getEffectivePermission(self._user, item),
'info': Services.serviceInfo(item.service),
}

View File

@ -1,4 +1,4 @@
# jshint strict: true
# jshint strict: true
"use strict"
@api = @api ? {}
$ = jQuery
@ -152,7 +152,7 @@ class BasicModelRest
constructor: (path, options) ->
options = options or {}
path = path or ""
# Requests paths
@path = path
@getPath = options.getPath or path
@ -172,8 +172,11 @@ class BasicModelRest
api.doLog "success function not provided for " + path
return
fail_fnc = options.fail or ->
fail_fnc = options.fail or (jqXHR, textStatus, errorThrown) ->
api.doLog "failFnc not provided for " + path
gui.tools.unblockUI()
gui.notify 'Error ocurred: ' + textStatus, 'danger'
cacheKey = options.cacheKey or path
api.doLog 'CacheKey ', cacheKey
if path is "."
@ -283,7 +286,7 @@ class BasicModelRest
return api.permissions.NONE
getPermissions: (id, success_fnc, fail_fnc) ->
path = "permissions/" + @path + '/' + id
path = "permissions/" + @path + '/' + id
@_requestPath path,
cacheKey: "."
success: success_fnc
@ -356,7 +359,7 @@ class DetailModelRestApi extends BasicModelRest
permission: () ->
if @moptions.permission? then @moptions.permission else api.permissions.ALL
create: (data, success_fnc, fail_fnc) ->
@put data,
success: success_fnc
@ -407,7 +410,7 @@ api.providers.maintenance = (id, success_fnc, fail_fnc) ->
@get
id: id + "/maintenance"
success: success_fnc
fail: fail_fnc
fail: fail_fnc
api.authenticators = new BasicModelRest("authenticators")

View File

@ -0,0 +1,93 @@
gui.servicesPools.accessCalendars = (servPool, info) ->
accessCalendars = new GuiElement(api.servicesPools.detail(servPool.id, "access", { permission: servPool.permission }), "access")
accessCalendarsTable = accessCalendars.table(
doNotLoadData: true
icon: 'assigned'
container: "access-placeholder"
rowSelect: "multi"
buttons: [
"new"
"edit"
"delete"
"xls"
]
onCheck: (action, selected) ->
if action == 'edit'
return true
for v in selected
if v.id == -1
return false # No action allowed on DEFAULT
return true
onData: (data) ->
data.push
id: -1,
name: 'DEFAULT',
priority: '<span style="visibility: hidden;font-size: 0px;">10000000</span>FallBack',
access: servPool.fallbackAccess
gui.doLog data
onNew: (value, table, refreshFnc) ->
api.templates.get "pool_add_access", (tmpl) ->
api.calendars.overview (data) ->
modalId = gui.launchModal(gettext("Add access calendar"), api.templates.evaluate(tmpl,
calendars: data
priority: 1
calendarId: ''
access: 'ALLOW'
))
$(modalId + " .button-accept").on "click", (event) ->
priority = $(modalId + " #id_priority").val()
calendar = $(modalId + " #id_calendar_select").val()
access = $(modalId + " #id_access_select").val()
accessCalendars.rest.create
calendarId: calendar
access: access
priority: priority
, (data) ->
$(modalId).modal "hide"
refreshFnc()
return
return
# Makes form "beautyfull" :-)
gui.tools.applyCustoms modalId
return
return
return
onEdit: (value, event, table, refreshFnc) ->
if value.id == -1
alert('Changing default')
return
api.templates.get "pool_add_access", (tmpl) ->
accessCalendars.rest.item value.id, (item) ->
api.calendars.overview (data) ->
gui.doLog "Item: ", item
modalId = gui.launchModal(gettext("Edit access calendar"), api.templates.evaluate(tmpl,
calendars: data
priority: item.priority
calendarId: item.calendarId
access: item.access
))
$(modalId + " .button-accept").on "click", (event) ->
alert('Saving')
$(modalId).modal "hide"
refreshFnc()
return
# Makes form "beautyfull" :-)
gui.tools.applyCustoms modalId
return
return
return
onDelete: gui.methods.del(accessCalendars, gettext("Remove access calendar"), gettext("Access calendar removal error"))
)
return [accessCalendarsTable]

View File

@ -0,0 +1,90 @@
gui.servicesPools.publications = (servPool, info) ->
pubApi = api.servicesPools.detail(servPool.id, "publications")
publications = new GuiElement(pubApi, "publications", { permission: servPool.permission })
# Publications table
publicationsTable = publications.table(
doNotLoadData: true
icon: 'publications'
container: "publications-placeholder"
doNotLoadData: true
rowSelect: "single"
buttons: [
"new"
{
text: gettext("Cancel")
css: "disabled"
disabled: true
click: (val, value, btn, tbl, refreshFnc) ->
gui.doLog val, val[0]
gui.forms.confirmModal gettext("Publish"), gettext("Cancel publication?"),
onYes: ->
pubApi.invoke val[0].id + "/cancel", ->
refreshFnc()
return
return
return
select: (vals, self, btn, tbl, refreshFnc) ->
unless vals.length == 1
$(btn).addClass "disabled"
$(btn).prop('disabled', true)
return
val = vals[0]
if val.state == 'K'
$(btn).empty().append(gettext("Force Cancel"))
else
$(btn).empty().append(gettext("Cancel"))
# Waiting for publication, Preparing or running
gui.doLog "State: ", val.state
if ["P", "W", "L", "K"].indexOf(val.state) != -1
$(btn).removeClass("disabled").prop('disabled', false)
else
$(btn).addClass("disabled").prop('disabled', true)
return
}
"xls"
]
onNew: (action, tbl, refreshFnc) ->
# Ask for "reason" for publication
api.templates.get "publish", (tmpl) ->
content = api.templates.evaluate(tmpl,
)
modalId = gui.launchModal(gettext("Publish"), content,
actionButton: "<button type=\"button\" class=\"btn btn-success button-accept\">" + gettext("Publish") + "</button>"
)
gui.tools.applyCustoms modalId
$(modalId + " .button-accept").click ->
chlog = encodeURIComponent($('#id_publish_log').val())
$(modalId).modal "hide"
pubApi.invoke "publish", (->
refreshFnc()
changelog.refresh()
# Also changelog
return
),
gui.failRequestModalFnc(gettext("Failed creating publication")),
{ params: 'changelog=' + chlog }
return
return
)
# changelog
clApi = api.servicesPools.detail(servPool.id, "changelog")
changelog = new GuiElement(clApi, "changelog", { permission: servPool.permission })
clTable = changelog.table(
icon: 'publications'
doNotLoadData: true
container: "changelog-placeholder"
rowSelect: "single"
)
return [publicationsTable, clTable]

View File

@ -0,0 +1,60 @@
gui.servicesPools.transports = (servPool, info) ->
transports = new GuiElement(api.servicesPools.detail(servPool.id, "transports", { permission: servPool.permission }), "transports")
# Transports items table
transportsTable = transports.table(
doNotLoadData: true
icon: 'transports'
container: "transports-placeholder"
doNotLoadData: true
rowSelect: "multi"
buttons: [
"new"
"delete"
"xls"
]
onNew: (value, table, refreshFnc) ->
api.templates.get "pool_add_transport", (tmpl) ->
api.transports.overview (data) ->
gui.doLog "Data Received: ", servPool, data
valid = []
for i in data
if (i.protocol in servPool.info.allowedProtocols)
valid.push(i)
modalId = gui.launchModal(gettext("Add transport"), api.templates.evaluate(tmpl,
transports: valid
))
$(modalId + " .button-accept").on "click", (event) ->
transport = $(modalId + " #id_transport_select").val()
if transport is -1
gui.notify gettext("You must provide a transport"), "danger"
else # Save & close modal
transports.rest.create
id: transport
, (data) ->
$(modalId).modal "hide"
refreshFnc()
return
return
# Makes form "beautyfull" :-)
gui.tools.applyCustoms modalId
return
return
return
onDelete: gui.methods.del(transports, gettext("Remove transport"), gettext("Transport removal error"))
onData: (data) ->
$.each data, (undefined_, value) ->
style = "display:inline-block; background: url(data:image/png;base64," + value.type.icon + "); ; background-size: 16px 16px; background-repeat: no-repeat; width: 16px; height: 16px; vertical-align: middle;"
value.trans_type = value.type.name
value.name = "<span style=\"" + style + "\"></span> " + value.name
return
return
)
return [transportsTable]

View File

@ -1,10 +1,10 @@
# jshint strict: true
# jshint strict: true
gui.servicesPools = new GuiElement(api.servicesPools, "servicespools")
gui.servicesPools.link = (event) ->
"use strict"
gui.clearWorkspace()
editMode = false # To indicate if editing or not. Used for disabling "os manager", due to the fact that os manager are different for apps and vdi
# Clears the details
# Memory saver :-)
prevTables = []
@ -88,7 +88,7 @@ gui.servicesPools.link = (event) ->
return
#
#
preFnc = (formId) ->
$fld = $(formId + " [name=\"service_id\"]")
$fld.on "change", (event) ->
@ -131,7 +131,7 @@ gui.servicesPools.link = (event) ->
logs: "logs-placeholder"
)
gui.setLinksEvents()
# Append tabs click events
$(".bottom_tabs").on "click", (event) ->
gui.doLog event.target
@ -141,10 +141,10 @@ gui.servicesPools.link = (event) ->
), 10
return
#
# * Services pools part
#
#
servicesPoolsTable = gui.servicesPools.table(
icon: 'pools'
callback: renderer
@ -188,19 +188,19 @@ gui.servicesPools.link = (event) ->
# Load provider "info"
gui.methods.typedShow gui.servicesPools, selected[0], '#pool-info-placeholder .well', gettext('Error accessing data')
#
#
# * Cache Part
#
#
cachedItems = null
# If service does not supports cache, do not show it
# Shows/hides cache
if info.uses_cache or info.uses_cache_l2
$("#cache-placeholder_tab").removeClass "hidden"
cachedItems = new GuiElement(api.servicesPools.detail(servPool.id, "cache", { permission: servPool.permission }), "cache")
# Cached items table
prevCacheLogTbl = null
cachedItemsTable = cachedItems.table(
@ -234,17 +234,17 @@ gui.servicesPools.link = (event) ->
prevTables.push cachedItemsTable
else
$("#cache-placeholder_tab").addClass "hidden"
#
# * Groups part
#
#
groups = null
# Shows/hides groups
if info.must_assign_manually is false
$("#groups-placeholder_tab").removeClass "hidden"
groups = new GuiElement(api.servicesPools.detail(servPool.id, "groups", { permission: servPool.permission }), "groups")
# Groups items table
groupsTable = groups.table(
doNotLoadData: true
@ -275,7 +275,7 @@ gui.servicesPools.link = (event) ->
$select.append "<option value=\"" + value.id + "\">" + value.name + "</option>"
return
# Refresh selectpicker if item is such
$select.selectpicker "refresh" if $select.hasClass("selectpicker")
return
@ -297,7 +297,7 @@ gui.servicesPools.link = (event) ->
return
# Makes form "beautyfull" :-)
gui.tools.applyCustoms modalId
return
@ -317,10 +317,10 @@ gui.servicesPools.link = (event) ->
prevTables.push groupsTable
else
$("#groups-placeholder_tab").addClass "hidden"
#
# * Assigned services part
#
#
prevAssignedLogTbl = null
assignedServices = new GuiElement(api.servicesPools.detail(servPool.id, "services", { permission: servPool.permission }), "services")
assignedServicesTable = assignedServices.table(
@ -336,7 +336,7 @@ gui.servicesPools.link = (event) ->
"delete"
"xls"
])
onData: (data) ->
fillState data
$.each data, (index, value) ->
@ -360,203 +360,36 @@ gui.servicesPools.link = (event) ->
onDelete: gui.methods.del(assignedServices, gettext("Remove Assigned service"), gettext("Deletion error"))
)
# Log of assigned services (right under assigned services)
prevTables.push assignedServicesTable
#
# * Transports part
#
transports = new GuiElement(api.servicesPools.detail(servPool.id, "transports", { permission: servPool.permission }), "transports")
# Transports items table
transportsTable = transports.table(
doNotLoadData: true
icon: 'transports'
container: "transports-placeholder"
doNotLoadData: true
rowSelect: "multi"
buttons: [
"new"
"delete"
"xls"
]
onNew: (value, table, refreshFnc) ->
api.templates.get "pool_add_transport", (tmpl) ->
api.transports.overview (data) ->
gui.doLog "Data Received: ", servPool, data
valid = []
for i in data
if (i.protocol in servPool.info.allowedProtocols)
valid.push(i)
modalId = gui.launchModal(gettext("Add transport"), api.templates.evaluate(tmpl,
transports: valid
))
$(modalId + " .button-accept").on "click", (event) ->
transport = $(modalId + " #id_transport_select").val()
if transport is -1
gui.notify gettext("You must provide a transport"), "danger"
else # Save & close modal
transports.rest.create
id: transport
, (data) ->
$(modalId).modal "hide"
refreshFnc()
return
#
for v in gui.servicesPools.transports(servPool, info)
prevTables.push v
return
# Makes form "beautyfull" :-)
gui.tools.applyCustoms modalId
return
return
return
onDelete: gui.methods.del(transports, gettext("Remove transport"), gettext("Transport removal error"))
onData: (data) ->
$.each data, (undefined_, value) ->
style = "display:inline-block; background: url(data:image/png;base64," + value.type.icon + "); ; background-size: 16px 16px; background-repeat: no-repeat; width: 16px; height: 16px; vertical-align: middle;"
value.trans_type = value.type.name
value.name = "<span style=\"" + style + "\"></span> " + value.name
return
return
)
prevTables.push transportsTable
#
# * Publications part
#
publications = null
changelog = null
clTable = null
#
if info.needs_publication
$("#publications-placeholder_tab").removeClass "hidden"
pubApi = api.servicesPools.detail(servPool.id, "publications")
publications = new GuiElement(pubApi, "publications", { permission: servPool.permission })
# Publications table
publicationsTable = publications.table(
doNotLoadData: true
icon: 'publications'
container: "publications-placeholder"
doNotLoadData: true
rowSelect: "single"
buttons: [
"new"
{
text: gettext("Cancel")
css: "disabled"
disabled: true
click: (val, value, btn, tbl, refreshFnc) ->
gui.doLog val, val[0]
gui.forms.confirmModal gettext("Publish"), gettext("Cancel publication?"),
onYes: ->
pubApi.invoke val[0].id + "/cancel", ->
refreshFnc()
return
return
return
select: (vals, self, btn, tbl, refreshFnc) ->
unless vals.length == 1
$(btn).addClass "disabled"
$(btn).prop('disabled', true)
return
val = vals[0]
if val.state == 'K'
$(btn).empty().append(gettext("Force Cancel"))
else
$(btn).empty().append(gettext("Cancel"))
# Waiting for publication, Preparing or running
gui.doLog "State: ", val.state
if ["P", "W", "L", "K"].indexOf(val.state) != -1
$(btn).removeClass("disabled").prop('disabled', false)
else
$(btn).addClass("disabled").prop('disabled', true)
return
}
"xls"
]
onNew: (action, tbl, refreshFnc) ->
# Ask for "reason" for publication
api.templates.get "publish", (tmpl) ->
content = api.templates.evaluate(tmpl,
)
modalId = gui.launchModal(gettext("Publish"), content,
actionButton: "<button type=\"button\" class=\"btn btn-success button-accept\">" + gettext("Publish") + "</button>"
)
gui.tools.applyCustoms modalId
$(modalId + " .button-accept").click ->
chlog = encodeURIComponent($('#id_publish_log').val())
$(modalId).modal "hide"
pubApi.invoke "publish", (->
refreshFnc()
changelog.refresh()
# Also changelog
return
),
gui.failRequestModalFnc(gettext("Failed creating publication")),
{ params: 'changelog=' + chlog }
return
return
)
prevTables.push publicationsTable
# changelog
clApi = api.servicesPools.detail(servPool.id, "changelog")
changelog = new GuiElement(clApi, "changelog", { permission: servPool.permission })
clTable = changelog.table(
icon: 'publications'
doNotLoadData: true
container: "changelog-placeholder"
rowSelect: "single"
)
prevTables.push clTable
for v in gui.servicesPools.publications(servPool, info)
prevTables.push v
else
$("#publications-placeholder_tab").addClass "hidden"
#
#
# Access calendars
#
accessCalendars = new GuiElement(api.servicesPools.detail(servPool.id, "access", { permission: servPool.permission }), "access")
accessCalendarsTable = accessCalendars.table(
doNotLoadData: false
icon: 'assigned'
container: "access-placeholder"
rowSelect: "multi"
buttons: [
"new"
"delete"
"xls"
]
onData: (data) ->
data.push
id: -1,
name: 'DEFAULT',
priority: '<span style="visibility: hidden;">10000000</span>FallBack',
action: servPool.allowAccessByDefault
)
prevTables.push accessCalendarsTable
for v in gui.servicesPools.accessCalendars(servPool, info)
prevTables.push v
#
# * Log table
#
#
logTable = gui.servicesPools.logTable(servPool.id,
doNotLoadData: true
container: "logs-placeholder"
@ -564,7 +397,7 @@ gui.servicesPools.link = (event) ->
prevTables.push logTable
return
# Pre-process data received to add "icon" to deployed service
onData: (data) ->
gui.doLog "onData", data
@ -606,4 +439,4 @@ gui.servicesPools.link = (event) ->
onDelete: gui.methods.del(gui.servicesPools, gettext("Delete") + " service pool", "Service pool " + gettext("deletion error"))
)
return
return
return

View File

@ -0,0 +1,154 @@
# Generic "methods" for editing, creating, etc...
gui.methods = {}
gui.methods.typedTestButton = (rest, text, css, type) ->
[
text: text
css: css
action: (event, form_selector, closeFnc) ->
fields = gui.forms.read(form_selector)
gui.doLog "Fields: ", fields
rest.test type, fields, ((data) ->
if data == 'ok'
text = gettext("Test passed successfully")
kind = 'success'
else
text = gettext("Test failed:") + " #{data}</b>"
kind = 'danger'
gui.notify text, kind
# gui.launchModal gettext("Test result"), text,
# actionButton: " "
return
), gui.failRequestModalFnc(gettext("Test error"))
return
]
# "Generic" edit method to set onEdit table
gui.methods.typedEdit = (parent, modalTitle, modalErrorMsg, options) ->
options = options or {}
(value, event, table, refreshFnc) ->
gui.tools.blockUI()
parent.rest.gui value.type, ((guiDefinition) ->
buttons = gui.methods.typedTestButton(parent.rest, options.testButton.text, options.testButton.css, value.type) if options.testButton
tabs = (if options.guiProcessor then options.guiProcessor(guiDefinition) else guiDefinition) # Preprocess fields (probably generate tabs...)
parent.rest.item value.id, (item) ->
gui.tools.unblockUI()
gui.forms.launchModal
title: modalTitle + " <b>" + value.name + "</b>"
fields: tabs
item: item
preprocessor: options.preprocessor
buttons: buttons
success: (form_selector, closeFnc) ->
fields = gui.forms.read(form_selector)
fields.data_type = value.type
fields = (if options.fieldsProcessor then options.fieldsProcessor(fields) else fields)
parent.rest.save fields, ((data) -> # Success on put
closeFnc()
refreshFnc()
gui.notify gettext("Edition successfully done"), "success"
return
), gui.failRequestModalFnc(modalErrorMsg, true) # Fail on put, show modal message
return
return
return
), gui.failRequestModalFnc(modalErrorMsg, true)
return
gui.methods.typedShow = (parent, value, placeholder, modalErrorMsg, options) ->
options = options or {}
parent.rest.gui value.type, ((guiDefinition) ->
formId = gui.genRamdonId('ovw-')
parent.rest.item value.id, (item) ->
gui.doLog "Item", item, "Gui", guiDefinition
data = []
flds = gui.forms.fieldsToHtml(guiDefinition, item, "readonly")
gui.doLog(flds)
html = api.templates.evaluate "tmpl_comp_overview_record",
id: formId
legend: gettext('Overview')
fields: flds.html
$(placeholder).html(html)
gui.tools.applyCustoms '#' + formId
return
), gui.failRequestModalFnc(modalErrorMsg, true)
return
# "Generic" new method to set onNew table
gui.methods.typedNew = (parent, modalTitle, modalErrorMsg, options) ->
options = options or {}
(type, table, refreshFnc) ->
gui.tools.blockUI()
parent.rest.gui type, ((guiDefinition) ->
gui.tools.unblockUI()
buttons = gui.methods.typedTestButton(parent.rest, options.testButton.text, options.testButton.css, type) if options.testButton
tabs = (if options.guiProcessor then options.guiProcessor(guiDefinition) else guiDefinition) # Preprocess fields (probably generate tabs...)
title = modalTitle
title += " " + gettext("of type") + " <b>" + parent.types[type].name + "</b>" if parent.types[type]?
gui.forms.launchModal
title: title
fields: tabs
item: null
preprocessor: options.preprocessor
buttons: buttons
success: (form_selector, closeFnc) ->
fields = gui.forms.read(form_selector)
fields.data_type = type if parent.types[type]?
fields = (if options.fieldsProcessor then options.fieldsProcessor(fields) else fields) # Process fields before creating?
parent.rest.create fields, ((data) -> # Success on put
closeFnc()
refreshFnc()
gui.notify gettext("Creation successfully done"), "success"
return
), gui.failRequestModalFnc(modalErrorMsg, true) # Fail on put, show modal message
return
return
), gui.failRequestModalFnc(modalErrorMsg, true)
return
gui.methods.del = (parent, modalTitle, modalErrorMsg) ->
(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 gettext("Error deleting") + " <b>" + name + '</b>: <span class="text-danger">' + 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"
gui.tools.blockUI()
for value in values
((value) ->
name = value.name or value.friendly_name
parent.rest.del value.id, (->
deletedFnc name
return
), (jqXHR, textStatus, errorThrown) -> # fail on delete
deletedFnc(name, jqXHR.responseText))(value)
return
return

View File

@ -1,22 +1,22 @@
# jshint strict: true
# jshint strict: true
((gui, $, undefined_) ->
"use strict"
# Public attributes
gui.debug = on
# "public" methods
gui.doLog = (args...)->
if gui.debug
try
console.log args
return
# nothing can be logged
gui.config = gui.config or {}
# Several convenience "constants" for tables
gui.config.dataTablesLanguage =
sLengthMenu: gettext("_MENU_ records per page")
@ -93,7 +93,7 @@
list += "<li class=\"active\">" + active + "</li>"
"<div class=\"row\"><div class=\"col-lg-12\"><ol class=\"breadcrumb\">" + list + "</ol></div></div>"
# By default, actionButton has class "button-accept", so you can use returned id + this class to select it
# and do whatever is needed (for example, insert an "on click" event (this method returns id without '#'
# Example: $('#' + id + ' .button-accept').on('click', ...
@ -106,7 +106,7 @@
footer: options.footer
button1: options.closeButton
button2: options.actionButton
# As previous, this creates the modal and shows it. in this case, the id of the modal returned already has '#'
gui.launchModal = (title, content, options) ->
options = options or {}
@ -145,14 +145,14 @@
$(data).appendTo "#content"
return
# Clean up several "internal" data
# I have discovered some "items" that are keep in memory, or that adds garbage to body (datatable && tabletools mainly)
# Whenever we change "section", we clean up as much as we can, so we can keep things as clean as possible
# Main problem where comming with "tabletools" and keeping references to all instances created
gui.cleanup = ->
gui.doLog "Cleaning up things"
# Destroy any created datatable
$.each $.fn.dataTable.fnTables(), (undefined_, tbl) ->
$tbl = $(tbl).dataTable()
@ -260,13 +260,13 @@
max: $.validator.format(gettext("Please enter a value less than or equal to {0}."))
min: $.validator.format(gettext("Please enter a value greater than or equal to {0}."))
# Set blockui params
$.blockUI.defaults.baseZ = 2000
$.fn.dataTableExt.oSort["uds-date-pre"] = (s) ->
parseInt s.split("\"")[1], 10
# Sort for "date" columns (our "dates" are in fact postfix dates rendered as dates with locale format
$.fn.dataTableExt.oSort["uds-date-asc"] = (x, y) ->
val = ((if (x < y) then -1 else ((if (x > y) then 1 else 0))))
@ -276,7 +276,7 @@
val = ((if (x < y) then 1 else ((if (x > y) then -1 else 0))))
val
# Wait a bit before activating links to give tome tine to initializations
setTimeout (->
gui.setLinksEvents()
@ -289,7 +289,6 @@
gui.dashboard.link()
return
# Generic "methods" for editing, creating, etc...
gui.methods = {}
gui.methods.typedTestButton = (rest, text, css, type) ->
@ -315,7 +314,7 @@
return
]
# "Generic" edit method to set onEdit table
gui.methods.typedEdit = (parent, modalTitle, modalErrorMsg, options) ->
options = options or {}
@ -359,7 +358,7 @@
data = []
flds = gui.forms.fieldsToHtml(guiDefinition, item, "readonly")
gui.doLog(flds)
html = api.templates.evaluate "tmpl_comp_overview_record",
html = api.templates.evaluate "tmpl_comp_overview_record",
id: formId
legend: gettext('Overview')
fields: flds.html
@ -369,7 +368,7 @@
), gui.failRequestModalFnc(modalErrorMsg, true)
return
# "Generic" new method to set onNew table
gui.methods.typedNew = (parent, modalTitle, modalErrorMsg, options) ->
options = options or {}
@ -411,7 +410,7 @@
actionButton: "<button type=\"button\" class=\"btn btn-danger button-accept\">" + gettext("Delete") + "</button>"
)
# Will show results once
# Will show results once
msgs = []
count = values.length
deletedFnc = (name, errorMsg) ->
@ -446,4 +445,4 @@
return
return
) window.gui = window.gui or {}, jQuery
) window.gui = window.gui or {}, jQuery

View File

@ -26,11 +26,11 @@
<link href="{% get_static_prefix %}adm/css/uds.css" rel="stylesheet" media="screen">
{% endcompress %}
</head>
<body>
<!-- Navigation bar -->
<div id="wrapper" class="full">
{% block menu %}{% include 'uds/admin/snippets/navbar.html' with admin=request.user.is_admin %}{% endblock %}
<!-- End of menu -->
<!-- Content -->
@ -39,7 +39,7 @@
</div>
</div>
</div>
<script src="{% url 'uds.web.views.jsCatalog' LANGUAGE_CODE %}"></script>
<script>
// Initialize a few settings, needed for api to work
@ -55,8 +55,8 @@
};
}(window.api = window.api || {}));
</script>
{% compress js %}
<!-- minified js from: 'jquery', 'jquery.cookie', 'bootstrap.min', 'bootstrap-switch.min', 'bootstrap-select.min', 'jquery.validate.min', 'jquery.blockUI', 'flot',
@ -70,7 +70,7 @@
<script src="{% get_static_prefix %}adm/js/bootstrap-datepicker.js"></script>
<script src="{% get_static_prefix %}adm/js/bootstrap-timepicker.js"></script>
<script src="{% get_static_prefix %}adm/js/datepicker-locales/bootstrap-datepicker.{{ LANGUAGE_CODE }}.min.js"></script>
<script src="{% get_static_prefix %}adm/js/bootstrap-select.min.js"></script>
<script src="{% get_static_prefix %}adm/js/jquery.validate.min.js"></script>
<script src="{% get_static_prefix %}adm/js/jquery.blockUI.js"></script>
@ -80,37 +80,38 @@
<script src="{% get_static_prefix %}adm/js/flot/jquery.flot.min.js"></script>
<script src="{% get_static_prefix %}adm/js/flot/jquery.flot.resize.min.js"></script>
<script src="{% get_static_prefix %}adm/js/flot/jquery.flot.time.min.js"></script>
<!-- for "save" from javascript -->
<script src="{% get_static_prefix %}adm/js/Blob.js"></script>
<script src="{% get_static_prefix %}adm/js/FileSaver.min.js"></script>
<script src="{% get_static_prefix %}adm/js/ZeroClipboard.js"></script>
<!-- For Image preview on file upload -->
<script src="{% get_static_prefix %}adm/js/jasny-bootstrap.min.js"></script>
<!-- template engine -->
<script src="{% get_static_prefix %}adm/js/handlebars-v4.0.2.js"></script>
<!-- First all api related stuff -->
<script type="text/coffeescript" charset="utf-8" src="{% get_static_prefix %}adm/js/api.coffee"></script>
<!-- utilities attached to api -->
<script type="text/coffeescript" charset="utf-8" src="{% get_static_prefix %}adm/js/api-tools.coffee"></script>
<!-- templates related, inserts itself into api -->
<script type="text/coffeescript" charset="utf-8" src="{% get_static_prefix %}adm/js/api-templates.coffee"></script>
<!-- export to xls, inserts itself into api -->
<script type="text/coffeescript" charset="utf-8" src="{% get_static_prefix %}adm/js/api-spreadsheet.coffee"></script>
<script type="text/coffeescript" charset="utf-8" src="{% get_static_prefix %}adm/js/gui.coffee"></script>
<script type="text/coffeescript" charset="utf-8" src="{% get_static_prefix %}adm/js/gui-methods.coffee"></script>
<script type="text/coffeescript" charset="utf-8" src="{% get_static_prefix %}adm/js/gui-tools.coffee"></script>
<script type="text/coffeescript" charset="utf-8" src="{% get_static_prefix %}adm/js/gui-form.coffee"></script>
<script type="text/coffeescript" charset="utf-8" src="{% get_static_prefix %}adm/js/gui-permissions.coffee"></script>
<script type="text/coffeescript" charset="utf-8" src="{% get_static_prefix %}adm/js/gui-element.coffee"></script>
<!-- user interface management -->
<script type="text/coffeescript" charset="utf-8" src="{% get_static_prefix %}adm/js/gui-definition.coffee"></script>
<script type="text/coffeescript" charset="utf-8" src="{% get_static_prefix %}adm/js/gui-d-dashboard.coffee"></script>
@ -119,6 +120,9 @@
<script type="text/coffeescript" charset="utf-8" src="{% get_static_prefix %}adm/js/gui-d-osmanagers.coffee"></script>
<script type="text/coffeescript" charset="utf-8" src="{% get_static_prefix %}adm/js/gui-d-connectivity.coffee"></script>
<script type="text/coffeescript" charset="utf-8" src="{% get_static_prefix %}adm/js/gui-d-servicespools.coffee"></script>
<script type="text/coffeescript" charset="utf-8" src="{% get_static_prefix %}adm/js/gui-d-servicespools-calendars.coffee"></script>
<script type="text/coffeescript" charset="utf-8" src="{% get_static_prefix %}adm/js/gui-d-servicespools-publications.coffee"></script>
<script type="text/coffeescript" charset="utf-8" src="{% get_static_prefix %}adm/js/gui-d-servicespools-transports.coffee"></script>
<script type="text/coffeescript" charset="utf-8" src="{% get_static_prefix %}adm/js/gui-d-config.coffee"></script>
<script type="text/coffeescript" charset="utf-8" src="{% get_static_prefix %}adm/js/gui-d-gallery.coffee"></script>
<script type="text/coffeescript" charset="utf-8" src="{% get_static_prefix %}adm/js/gui-d-servicespoolsgroup.coffee"></script>
@ -126,7 +130,7 @@
<script type="text/coffeescript" charset="utf-8" src="{% get_static_prefix %}adm/js/gui-d-calendar.coffee"></script>
<!-- base64 encoding -->
<script src="{% get_static_prefix %}adm/js/base64.js"></script>
<script type="text/javascript">
function showHideTooltip() {
console.log("ShowHide");
@ -140,7 +144,7 @@
placement: 'right',
title: title,
container: 'body',
delay: {
delay: {
show: 200,
hide: 100
}
@ -175,11 +179,11 @@
$.fn.datepicker.defaults.autoclose = true;
$.fn.datepicker.defaults.language = "{{ LANGUAGE_CODE }}";
});
});
</script>
{% block js %}{% endblock %}
{% endcompress %}
{% js_template_path 'uds/admin/tmpl' %}
<!-- preloading of templates -->
<!-- page contents -->
@ -207,7 +211,7 @@
{% js_template 'comp/modal' %}
{% js_template 'comp/responsive_table' %}
{% js_template 'comp/dropdown' %}
<!-- overview -->
{% js_template 'comp/overview_record' %}
@ -226,6 +230,6 @@
{% js_template 'fld/textbox' %}
{% js_template 'fld/date' %}
{% js_template 'fld/taglist' %}
</body>
</html>
</html>

View File

@ -5,8 +5,8 @@
{% verbatim %}
<select class="selectpicker show-menu-arrow show-tick {{ css }}" name="{{ name }}" data-style="btn-default" data-width="100%" id="{{ name }}_field" {{# if readonly }} disabled{{/ if }}{{# if required }} required{{/ if }} tabindex="{{ index }}">
{{#each values }}
<option value="{{ id }}"{{# ifequals id ../value }}selected{{/ ifequals }}>{{ text }}</option>
<option value="{{ id }}"{{# ifequals id ../value }} selected{{/ ifequals }}>{{ text }}</option>
{{/each}}
</select>
{% endverbatim %}
{% endblock %}
{% endblock %}

View File

@ -0,0 +1,33 @@
{% load i18n %}
{% verbatim %}
<form class="form-horizontal" role="form">
<div class="form-group">
<label for="id_priority" class="col-sm-2 control-label">{% endverbatim %}{% trans 'Priority' %}{% verbatim %}</label>
<div class="col-sm-10">
<input type="numeric" class="modal_field_data" id="id_priority" value="{{ priority }}">
</div>
</div>
<div class="form-group">
<label for="id_calendar_select" class="col-sm-2 control-label">{% endverbatim %}{% trans 'Calendar' %}{% verbatim %}</label>
<div class="col-sm-10">
<select id="id_calendar_select" class="selectpicker show-menu-arrow show-tick modal_field_data" data-style="btn-default" data-width="100%">
<option value="-1"></option>
{{# each calendars }}
<option value="{{ id }}"{{# ifequals id ../calendarId }} selected{{/ ifequals }}>{{ name }}</option>
{{/ each }}
</select>
</div>
</div>
<div class="form-group">
<label for="id_action_select" class="col-sm-2 control-label">{% endverbatim %}{% trans 'Access action' %}{% verbatim %}</label>
<div class="col-sm-10">
<select id="id_access_select" class="selectpicker show-menu-arrow show-tick modal_field_data" data-style="btn-default" data-width="100%">
<option value="ALLOW">ALLOW</option>
<option value="DENY">DENY</option>
</select>
</div>
</div>
</form>
{% endverbatim %}