@home.route('/save_as', methods=['GET', 'POST'])
@login_required
def save_as():
    if (request.method == 'POST'):
        if (BTN_SAVE in request.form):
            submit_type = 'Save'
        elif (BTN_CANCEL in request.form):
            submit_type = 'Cancel'
        else:
            submit_type = None
    form = SaveAsForm()
    current_document = current_user.get_filename()
    if (request.method == 'POST'):
        if (BTN_CANCEL in request.form):
            if current_document:
                return redirect(get_back_url())
            else:
                return render_template('index.html')
        if form.validate_on_submit():
            if (not current_document):
                flash('No document currently open')
                return render_template('index.html')
            eml_node = load_eml(filename=current_document)
            if (not eml_node):
                flash(f'Unable to open {current_document}')
                return render_template('index.html')
            new_document = form.filename.data
            return_value = save_old_to_new(old_filename=current_document, new_filename=new_document, eml_node=eml_node)
            if isinstance(return_value, str):
                flash(return_value)
                new_filename = current_document
            else:
                copy_uploads(current_document, new_document)
                current_user.set_filename(filename=new_document)
                flash(f'Saved as {new_document}')
            new_page = PAGE_TITLE
            return redirect(url_for(new_page, filename=new_document))
    if current_document:
        help = get_helps(['save_as_document'])
        return render_template('save_as.html', filename=current_document, title='Save As', form=form, help=help)
    else:
        flash('No document currently open')
        return render_template('index.html')
@home.route('/save_as', methods=['GET', 'POST'])
@login_required
def save_as():
    if (request.method == 'POST'):
        if (BTN_SAVE in request.form):
            submit_type = 'Save'
        elif (BTN_CANCEL in request.form):
            submit_type = 'Cancel'
        else:
            submit_type = None
    form = SaveAsForm()
    current_document = current_user.get_filename()
    if (request.method == 'POST'):
        if (BTN_CANCEL in request.form):
            if current_document:
                return redirect(get_back_url())
            else:
                return render_template('index.html')
        if form.validate_on_submit():
            if (not current_document):
                flash('No document currently open')
                return render_template('index.html')
            eml_node = load_eml(filename=current_document)
            if (not eml_node):
                flash(f'Unable to open {current_document}')
                return render_template('index.html')
            new_document = form.filename.data
            return_value = save_old_to_new(old_filename=current_document, new_filename=new_document, eml_node=eml_node)
            if isinstance(return_value, str):
                flash(return_value)
                new_filename = current_document
            else:
                copy_uploads(current_document, new_document)
                current_user.set_filename(filename=new_document)
                flash(f'Saved as {new_document}')
            new_page = PAGE_TITLE
            return redirect(url_for(new_page, filename=new_document))
    if current_document:
        help = get_helps(['save_as_document'])
        return render_template('save_as.html', filename=current_document, title='Save As', form=form, help=help)
    else:
        flash('No document currently open')
        return render_template('index.html')