Fixes in pastafari

This commit is contained in:
Antonio de la Rosa 2022-04-25 01:25:03 +02:00
parent ff93c78831
commit b4d3f1807f
3 changed files with 87 additions and 12 deletions

View file

@ -501,11 +501,14 @@ def pastafari2_make_task():
db=g.connection
ids=json.loads(request.form.get('ids', '[]'))
json_ids=json.dumps(ids)
arr_ids=[]
task_file=request.form.get('task', '')
task_path=request.form.get('task', '')
task_file=task_file.replace('/', '.')
task_file=task_path.replace('/', '.')
task_file=task_file.replace('.py', '')
@ -518,6 +521,14 @@ def pastafari2_make_task():
send_task=request.args.get('send_task', '')
error=0
txt_error=''
error_form={}
task=Task(db)
task_id=0
#if not os.path.isfile(task)
if send_task=='':
@ -526,13 +537,28 @@ def pastafari2_make_task():
if hasattr(task_first, 'form'):
url_exec=url_for('.pastafari2_make_task', ids=ids, task_file=task_file, send_task=1)
url_exec=url_for('.pastafari2_make_task', send_task=1)
return t.load_template('maketask.phtml', form=task_first.form(t, yes_error=False, pass_values=False), url_exec=url_exec)
return t.load_template('maketask.phtml', title=I18n.lang('pastafari2', 'make_task', 'Make task'), form=task_first.form(t, yes_error=False, pass_values=False), url_exec=url_exec, ids=json_ids, task_file=task_path)
error=0
txt_error=''
error_form={}
elif send_task!='':
if hasattr(task_first, 'form'):
#Check form
if not task_first.check_form(request.form):
error=1
txt_error=I18n.lang('pastafari2', 'error_fields_required', 'Errors: fields required')
for k,v in task_first.arr_form.items():
if task_first.arr_form[k].error:
error_form['#'+k+'_error']=task_first.arr_form[k].txt_error
return {'error': error, 'txt_error': txt_error, 'error_form': error_form, 'task_id': task_id}
pass
#print(ids)
for v in ids:
@ -542,11 +568,7 @@ def pastafari2_make_task():
#print(where_sql)
task=Task(db)
task_id=0
path_task='modules.pastafari2.tasks.system.updates'
path_task=task_file
#Load task, check if have question

View file

@ -159,6 +159,23 @@ $(document).ready(function () {
return false;
}
else {
//Make a normal submit to url_task for make_task form
var form=$("<form/>", { 'action': url_task, 'method': 'POST'});
form.append( $('<input>', {'type': 'hidden', 'name': 'ids', 'value': JSON.stringify(server_ids)}) )
form.append( $('<input>', {'type': 'hidden', 'name': 'task', 'value': task}) )
$("body").append(form);
form.submit();
return false;
}
}
$('#layer_loading').show();

View file

@ -0,0 +1,36 @@
<%inherit file="dashboard.phtml"/>
<%block name="content">
<form method="post" name="update_servers" id="update_servers" action="${url_exec}">
${form|n}
<input type="hidden" name="ids" value="${ids|h}" />
<input type="hidden" name="task" value="${task_file}" />
${csrf_token()|n}
<p><input type="submit" value="${lang('pastafari','execute_task', 'Execute task')}" /></p>
</form>
</%block>
<%block name="jscript_block">
<script language="Javascript" src="${make_media_url('js/jsutils/posting2.js', 'monit')}"></script>
<script language="Javascript" src="${make_media_url('js/jsutils/ajax_list.js', 'monit')}"></script>
<script>
var options={url: "${url_exec}", loading: '#layer_loading', success: function (data) {
task_id=data.task_id;
if(task_id>0) {
location.href="${url_for('.pastafari2_multiprogress')}?task_id="+task_id;
}
}, error_data: function (data) {
console.log(JSON.stringify(data));
}
};
jQuery('#update_servers').sendPost(options);
</script>
</%block>