untick all entries

This commit is contained in:
Ville Rantanen
2016-07-18 15:21:44 +03:00
parent 3e784b89ec
commit 8ff96b7d13
3 changed files with 50 additions and 26 deletions

11
shop.py
View File

@@ -249,8 +249,6 @@ def restore_md():
flash('Backup restored')
return redirect(url_for('show_shop',shopid=shopid))
@app.route('/toggle', methods=['POST'])
def toggle_item():
if not session.get('logged_in'):
@@ -266,16 +264,21 @@ def toggle_item():
if key=='toggleAll':
# Special meaning: toggle all rows
req_row=-1
if key=='unTickAll':
# Special meaning: untick all rows
req_row=-2
if req_row==None:
return redirect(url_for('show_shop',shopid=shopid))
data_dir=os.path.join(DATADIR, ownername)
data_file=os.path.join(data_dir, shopname+".md")
backup=data_file+".bkp"
contents_file=open(data_file,'rt')
contents=contents_file.read().decode('utf-8').split("\n")
contents_file.close()
changed=False
for i,row in enumerate(contents):
if i==req_row or req_row==-1:
if i==req_row or req_row<0:
if req_row!=-2: # no ticking if unticking all
if '[ ]' in row:
contents[i]=row.replace('[ ]','[x]')
if '[x]' in row:
@@ -283,6 +286,8 @@ def toggle_item():
if row!=contents[i]:
changed=True
if changed:
if req_row==-1 or req_row==-2:
copyfile(data_file, backup)
contents_file=open(data_file,'wt')
contents_file.write("\n".join(contents).encode('utf-8'))
contents_file.close()

View File

@@ -23,6 +23,9 @@ hr { border-color: #377ba8; }
.add-entry dl { font-weight: bold; }
.metanav { text-align: left; font-size: 1.2em;
background: #fafafa; font-weight: normal; }
.button-panel-row { margin-top: 1em; }
.button-panel-col { float: left; display: block; margin-right: 1em;
min-width: 23ex;}
.flash { background: #cee5F5; padding: 0.5em;
border: 1px solid #aacbe2; }
.error { background: #f0d6d6; padding: 0.5em; }

View File

@@ -30,23 +30,39 @@
<dt><input type=hidden name=shopid value={{ shopid }}><input class="submit submitNextTo" type=submit value="Add items">
</dl>
</form>
<form action="{{ url_for('remove_toggled') }}" method=post class=add-entry>
<dl><input type=hidden name=shopid value={{ shopid }}><input class=submit type=submit onclick="return confirm('Do you really want to remove ticked entries?');" value="Remove ticked">
</dl>
<hr>
<div class="button-panel-row">
<span class="button-panel-col">
<form action="{{ url_for('toggle_item') }}" method=post>
<input type=hidden name=shopid value="{{ shopid }}">
<input class=submit type=submit name=toggleAll value="Invert selection">
</form>
<form action="{{ url_for('toggle_item') }}" method=post class=add-entry>
<dl><input type=hidden name=shopid value="{{ shopid }}"><input class=submit type=submit name=toggleAll value="Invert selection">
</dl>
</span>
<span class="button-panel">
<form action="{{ url_for('toggle_item') }}" method=post>
<input type=hidden name=shopid value="{{ shopid }}">
<input class=submit type=submit name=unTickAll value="Untick all items" onclick="return confirm('Do you really want to untick all entries?');">
</form>
<form action="{{ url_for('sort_flip') }}" method=post class=add-entry>
<dl><input type=hidden name=shopid value="{{ shopid }}">
</span>
</div>
<div class="button-panel-row">
<span class="button-panel-col">
<form action="{{ url_for('sort_flip') }}" method=post>
<input type=hidden name=shopid value="{{ shopid }}">
{% if autosort %}
<input class=submit type=submit name=toggleAll value="Autosort mode: On">
{% else %}
<input class=submit type=submit name=toggleAll value="Autosort mode: Off">
{% endif %}
</dl>
</form>
</span>
<span class="button-panel">
<form action="{{ url_for('remove_toggled') }}" method=post>
<input type=hidden name=shopid value={{ shopid }}>
<input class=submit type=submit onclick="return confirm('Do you really want to remove ticked entries?');" value="Remove ticked">
</form>
</span>
</div>
</div>
<form id="disp_edit" class=hidden name="area_edit" action="{{ url_for('edit_md') }}" method=post class=add-entry>
<dl>Edit content file: