Skip to content
Permalink
Browse files Browse the repository at this point in the history
[UI] Fix SelectPicker not rendering properly
  • Loading branch information
NeuroAssassin committed Dec 1, 2020
1 parent 261f00f commit a6b9785
Showing 1 changed file with 41 additions and 16 deletions.
57 changes: 41 additions & 16 deletions reddash/app/home/templates/guild.html
Expand Up @@ -930,20 +930,20 @@ <h5>{{ data['message'] }}</h5>
img.attr("src", `${img.attr("data-src-url")}png`)
}
}

function safe(str) {
return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
}
</script>

{% if data['status'] == 1 and data['data']['status'] == 1 %}

{% if 'aliascc' in data['data']['permslist'] %}
{% if 'aliascc' in data['data']['permslist'] and false%}
<script>
/* ---------------------------------------------------------------------------------------------------------------------
Aliases group
--------------------------------------------------------------------------------------------------------------------- */

function safe(str) {
return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
}

// Alias modal
$(document).on('click', '.editaliasbutton', function () {
var command = $(this).parent().parent().data("command")
Expand Down Expand Up @@ -1186,28 +1186,35 @@ <h5>{{ data['message'] }}</h5>
} else if (json.status === 1 && json.data.status === 0) {
$("#targetstatus").html(`{{ _('Failed to fetch targets') }}: ${json.data.message}`)
} else {
let big_ol_dict = {}
select.html("")

var chopt = [`<optgroup label="{{ _('Channels') }}">`]
for (let [id, name] of json.data.CHANNELS) {
chopt.push(`<option value=${id}>${name}</option>`)
chopt.push(`<option value=${id} class="selectpicker-element-${id}">Loading...</option>`)
big_ol_dict[id] = name
}
chopt.push("</optgroup>")
select.append(chopt.join(""))

var ropt = [`<optgroup label="{{ _('Roles') }}">`]
for (let [id, name] of json.data.ROLES) {
ropt.push(`<option value=${id}>${name}</option>`)
ropt.push(`<option value=${id} class="selectpicker-element-${id}">Loading...</option>`)
big_ol_dict[id] = name
}
ropt.push("</optgroup>")
select.append(ropt.join(""))

var uopt = [`<optgroup label="{{ _('Users') }}">`]
for (let [id, name] of json.data.USERS) {
uopt.push(`<option value=${id}>${name}</option>`)
uopt.push(`<option value=${id} class="selectpicker-element-${id}">Loading...</option>`)
big_ol_dict[id] = name
}
uopt.push("</optgroup>")
select.append(uopt.join(""))
for (let [id, name] of Object.entries(big_ol_dict)) {
$(`.selectpicker-element-${id}`).text(name)
}
}
select.selectpicker({ title: "{{ _('Choose target') }}" })
select.removeAttr("disabled")
Expand Down Expand Up @@ -1299,18 +1306,24 @@ <h5>{{ data['message'] }}</h5>
$("#rulesdiv").html("")
var overall = ['<h3 style="margin-bottom: 10px">{{ _("Cog rules") }}</h3>']
var allcoglines = ["<ul>"]

let big_ol_dict_two = {}
let cog_counter = 0

for (let [cog, rules] of Object.entries(json.data.COG)) {
var coglines = []
for (let rule of rules) {
if (rule.type === "Default") {
coglines.unshift(`<li>{{ _('By default, users are') }} ${rule.permission} {{ _('permission to use the') }} <code>${cog}</code> {{ _('cog') }}.</li>`)
} else if (rule.type === "Role") {
coglines.push(`<li>{{ _('Users with the') }} <code>${rule.name}</code> {{ _('role') }} (${rule.id}) {{ _('are') }} ${rule.permission} {{ _('permission to use the') }} <code>${cog}</code> {{ _('cog') }}.</li>`)
coglines.push(`<li>{{ _('Users with the') }} <code id="cog-rules-${cog_counter}">Loading...</code> {{ _('role') }} (${rule.id}) {{ _('are') }} ${rule.permission} {{ _('permission to use the') }} <code>${cog}</code> {{ _('cog') }}.</li>`)
} else if (rule.type === "Channel") {
coglines.push(`<li>{{ _('Users in the') }} <code>${rule.name}</code> {{ _('channel') }} (${rule.id}) {{ _('are') }} ${rule.permission} {{ _('permission to use the') }} <code>${cog}</code> {{ _('cog') }}.</li>`)
coglines.push(`<li>{{ _('Users in the') }} <code id="cog-rules-${cog_counter}">Loading...</code> {{ _('channel') }} (${rule.id}) {{ _('are') }} ${rule.permission} {{ _('permission to use the') }} <code>${cog}</code> {{ _('cog') }}.</li>`)
} else {
coglines.push(`<li>{{ _('User') }} <code>${rule.name}</code> (${rule.id}) {{ _('is') }} ${rule.permission} {{ _('permission to use the') }} <code>${cog}</code> {{ _('cog') }}.</li>`)
coglines.push(`<li>{{ _('User') }} <code id="cog-rules-${cog_counter}">Loading...</code> (${rule.id}) {{ _('is') }} ${rule.permission} {{ _('permission to use the') }} <code>${cog}</code> {{ _('cog') }}.</li>`)
}
big_ol_dict_two[`cog-rules-${cog_counter}`] = rule.name
cog_counter += 1
}
if (coglines) {
allcoglines = allcoglines.concat(coglines)
Expand All @@ -1324,18 +1337,23 @@ <h5>{{ data['message'] }}</h5>

overall.push('<h3 style="margin-bottom: 10px">{{ _("Command rules") }}</h3>')
var allcmdlines = ["<ul>"]

let cmd_counter = 0

for (let [cmd, rules] of Object.entries(json.data.COMMAND)) {
var cmdlines = []
for (let rule of rules) {
if (rule.type === "Default") {
cmdlines.unshift(`<li>{{ _('By default, users are') }} ${rule.permission} {{ _('permission to use the') }} <code>${cmd}</code> {{ _('command') }}.</li>`)
} else if (rule.type === "Role") {
cmdlines.push(`<li>{{ _('Users with the') }} <code>${rule.name}</code> {{ _('role') }} (${rule.id}) {{ _('are') }} ${rule.permission} {{ _('permission to use the') }} <code>${cmd}</code> {{ _('command') }}.</li>`)
cmdlines.push(`<li>{{ _('Users with the') }} <code id="cmd-rules-${cmd_counter}">Loading...</code> {{ _('role') }} (${rule.id}) {{ _('are') }} ${rule.permission} {{ _('permission to use the') }} <code>${cmd}</code> {{ _('command') }}.</li>`)
} else if (rule.type === "Channel") {
cmdlines.push(`<li>{{ _('Users in the') }} <code>${rule.name}</code> {{ _('channel') }} (${rule.id}) {{ _('are') }} ${rule.permission} {{ _('permission to use the') }} <code>${cmd}</code> {{ _('command') }}.</li>`)
cmdlines.push(`<li>{{ _('Users in the') }} <code id="cmd-rules-${cmd_counter}">Loading...</code> {{ _('channel') }} (${rule.id}) {{ _('are') }} ${rule.permission} {{ _('permission to use the') }} <code>${cmd}</code> {{ _('command') }}.</li>`)
} else {
cmdlines.push(`<li>{{ _('User') }} <code>${rule.name}</code> (${rule.id}) {{ _('is') }} ${rule.permission} {{ _('permission to use the') }} <code>${cmd}</code> {{ _('command') }}.</li>`)
cmdlines.push(`<li>{{ _('User') }} <code id="cmd-rules-${cmd_counter}">Loading...</code> (${rule.id}) {{ _('is') }} ${rule.permission} {{ _('permission to use the') }} <code>${cmd}</code> {{ _('command') }}.</li>`)
}
big_ol_dict_two[`cmd-rules-${cmd_counter}`] = rule.name
cmd_counter += 1
}
if (cmdlines) {
allcmdlines = allcmdlines.concat(cmdlines)
Expand All @@ -1347,6 +1365,9 @@ <h5>{{ data['message'] }}</h5>
}
overall = overall.concat(allcmdlines)
$("#rulesdiv").html(overall.join(""))
for (let [id, name] of Object.entries(big_ol_dict_two)) {
$(`#${id}`).text(name)
}
$("#fetchrulesstatus").html("{{ _('Refreshed rules') }}.")
}
}
Expand Down Expand Up @@ -1378,18 +1399,20 @@ <h5>{{ data['message'] }}</h5>

$(document).on('click', '.adminroleoption', function () {
var elm = $(this)
let random_number = Math.floor(Math.random() * Math.floor(100000))
$("#adminrolelist").append(`
<li>
<div class="row">
<div class="col-md-10 col-8">
<input class="form-control adminroleinput" value="${elm.text()}" disabled=True data-id="${elm.attr("data-id")}">
<input class="form-control adminroleinput" value="Loading..." disabled=True data-id="${elm.attr("data-id")}" id="admin-role-${random_number}">
</div>
<div class="col-md-1 col-1">
<span class="admin-role-x clickable"><i class="tim-icons icon-simple-remove" style="float: right; margin-top: 10px;"></i></span>
</div>
</div>
</li>
`)
$(`#admin-role-${random_number}`).val(elm.text())
elm.remove()
})

Expand Down Expand Up @@ -1442,18 +1465,20 @@ <h5>{{ data['message'] }}</h5>

$(document).on('click', '.modroleoption', function () {
var elm = $(this)
let random_number = Math.floor(Math.random() * Math.floor(100000))
$("#modrolelist").append(`
<li>
<div class="row">
<div class="col-md-10 col-8">
<input class="form-control modroleinput" value="${elm.text()}" disabled=True data-id="${elm.attr("data-id")}">
<input class="form-control modroleinput" value="Loading..." disabled=True data-id="${elm.attr("data-id")}" id="mod-role-${random_number}">
</div>
<div class="col-md-1 col-1">
<span class="mod-role-x clickable"><i class="tim-icons icon-simple-remove" style="float: right; margin-top: 10px;"></i></span>
</div>
</div>
</li>
`)
$(`#mod-role-${random_number}`).val(elm.text())
elm.remove()
})

Expand Down

0 comments on commit a6b9785

Please sign in to comment.