mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Added edit function to web interface
This commit is contained in:
parent
98e1926613
commit
c33fcf1dc1
@ -47,7 +47,8 @@
|
||||
{% endif %}
|
||||
</td>
|
||||
<td class="text">
|
||||
<h1 class="headerwithextra">{{ info.artist }}</h1>
|
||||
<h1 id="main_entity_name" class="headerwithextra">{{ info.artist }}</h1>
|
||||
{% if adminmode %}{% include 'icons/edit.jinja' %}{% endif %}
|
||||
{% if competes %}<span class="rank"><a href="/charts_artists?max=100">#{{ info.position }}</a></span>{% endif %}
|
||||
<br/>
|
||||
{% if competes and included %}
|
||||
|
12
maloja/web/jinja/icons/edit.jinja
Normal file
12
maloja/web/jinja/icons/edit.jinja
Normal file
@ -0,0 +1,12 @@
|
||||
<script src="/edit.js"></script>
|
||||
<div title="Edit" id="editicon" class="clickable_icon" onclick="editEntity()">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="20px" y="20px"
|
||||
viewBox="0 0 59.985 59.985" style="enable-background:new 0 0 59.985 59.985;" xml:space="preserve">
|
||||
<path d="M5.243,44.844L42.378,7.708l9.899,9.899L15.141,54.742L5.243,44.844z"/>
|
||||
<path d="M56.521,13.364l1.414-1.414c1.322-1.322,2.05-3.079,2.05-4.949s-0.728-3.627-2.05-4.949S54.855,0,52.985,0
|
||||
s-3.627,0.729-4.95,2.051l-1.414,1.414L56.521,13.364z"/>
|
||||
<path d="M4.099,46.527L0.051,58.669c-0.12,0.359-0.026,0.756,0.242,1.023c0.19,0.19,0.446,0.293,0.707,0.293
|
||||
c0.106,0,0.212-0.017,0.316-0.052l12.141-4.047L4.099,46.527z"/>
|
||||
<path d="M43.793,6.294l1.415-1.415l9.899,9.899l-1.415,1.415L43.793,6.294z"/>
|
||||
</svg>
|
||||
</div>
|
@ -42,7 +42,7 @@
|
||||
</td>
|
||||
<td class="text">
|
||||
<span>{{ links.links(track.artists) }}</span><br/>
|
||||
<h1 class="headerwithextra">{{ info.track.title }}</h1>
|
||||
<h1 id="main_entity_name" class="headerwithextra">{{ info.track.title }}</h1>
|
||||
{{ awards.certs(track) }}
|
||||
<span class="rank"><a href="/charts_tracks?max=100">#{{ info.position }}</a></span>
|
||||
<br/>
|
||||
|
@ -72,6 +72,10 @@ div#settingsicon {
|
||||
right:30px;
|
||||
top:30px;
|
||||
}
|
||||
div#editicon {
|
||||
height:20px;
|
||||
width:20px;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
@ -10,3 +10,42 @@ function deleteScrobble(id,element) {
|
||||
neo.xhttpreq("/apis/mlj_1/delete_scrobble",data={'timestamp':id},method="POST",callback=(()=>null),json=true);
|
||||
|
||||
}
|
||||
|
||||
|
||||
function selectAll(e) {
|
||||
// https://stackoverflow.com/a/6150060/6651341
|
||||
var range = document.createRange();
|
||||
range.selectNodeContents(e);
|
||||
var sel = window.getSelection();
|
||||
sel.removeAllRanges();
|
||||
sel.addRange(range);
|
||||
}
|
||||
|
||||
function editEntity() {
|
||||
var namefield = document.getElementById('main_entity_name');
|
||||
namefield.contentEditable = "plaintext-only";
|
||||
|
||||
// dont allow new lines, done on enter
|
||||
namefield.addEventListener('keypress',function(e){
|
||||
if (e.which === 13) {
|
||||
e.preventDefault();
|
||||
doneEditing();
|
||||
}
|
||||
|
||||
})
|
||||
// emergency, not pretty because it will move cursor
|
||||
namefield.addEventListener('input',function(e){
|
||||
if (namefield.innerHTML.includes("\n")) {
|
||||
namefield.innerHTML = namefield.innerHTML.replace("\n","");
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
namefield.focus();
|
||||
selectAll(namefield);
|
||||
}
|
||||
|
||||
function doneEditing() {
|
||||
var namefield = document.getElementById('main_entity_name');
|
||||
namefield.contentEditable = "false";
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user