{% extends "html/base_authenticated.html" %}
{#
INPUT:
- notebook - an instance of Notebook
- worksheet - an instance of Worksheet
- username  - a string containing a username
- title - a string
- select    - a string containing the control that is selected
#}

{% set system_names = worksheet.notebook().system_names() %}
{% block title %}{{ worksheet.name() }}{% endblock %}


{% block javascript %}

<!-- trying to work around JSmol collisions with jquery--->
<script type="text/javascript" src="/javascript/jquery/jquery-1.11.0.min.js"></script>
<!-- jQuery UI - interacts, widgets, drag-drop, etc. -->
<link rel="stylesheet" href="/javascript/jqueryui/css/sage/jquery-ui-1.10.4.custom.css" />
<script type="text/javascript" src="/javascript/jqueryui/js/jquery-ui-1.10.4.custom.min.js"></script>

<!-- jQuery plugins - color pickers, shift-click, AJAX forms, IE fixes, notifications -->
<link rel="stylesheet" href="/javascript/jquery/plugins/farbtastic/farbtastic.css" type="text/css" />
<script type="text/javascript" src="/javascript/jquery/plugins/farbtastic/farbtastic.min.js"></script>
<script type="text/javascript" src="/javascript/jquery/plugins/extendedclick/jquery.event.extendedclick.min.js"></script>
<script type="text/javascript" src="/javascript/jquery/plugins/form/jquery.form.min.js"></script>
<script type="text/javascript" src="/javascript/jquery/plugins/jquery.bgiframe.min.js"></script>
<link rel="stylesheet" href="/javascript/jquery/plugins/jpicker/css/jPicker-1.1.6.min.css" type="text/css" />
<script type="text/javascript" src="/javascript/jquery/plugins/jpicker/jpicker-1.1.6.min.js"></script>
<link rel="stylesheet" media="screen" type="text/css" href="/javascript/jquery/plugins/colorpicker/css/colorpicker.css" />
<script type="text/javascript" src="/javascript/jquery/plugins/colorpicker/js/colorpicker.min.js"></script>
<script type="text/javascript" src="/javascript/jquery/plugins/achtung/ui.achtung-mod.min.js"></script>

<!-- Jmol - embedded 3D graphics **needs to be before jmol_lib.js** -->
<script type="text/javascript" src="/jsmol/JSmol.min.nojq.js"></script>

{% if not worksheet.is_published() or worksheet.notebook().conf()['pub_interact'] %}
<script type="text/javascript" src="/javascript/sage/js/notebook_lib.js"></script>
<script type="text/javascript" src="/javascript/dynamic/notebook_dynamic.js"></script>
{% elif worksheet.is_published() %}
<script type="text/javascript" src="/javascript/sage/js/jmol_lib.js"></script>
{% endif %}

{% if MATHJAX %}
<script type="text/javascript" src="/javascript/mathjax/MathJax.js?config=TeX-AMS_HTML-full,../../dynamic/mathjax_sage.js"></script>
{% endif %}

<!-- Sage3d - accelerated 3D graphics -->
<script type="text/javascript" src="/javascript/sage3d/sage3d.js"></script>

{% if JEDITABLE_TINYMCE and not worksheet.docbrowser() and not worksheet.is_published() %}
<!-- TinyMCE and jEditable - in-place editing of text cells -->
<script type="text/javascript" src="/javascript/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript" src="/javascript/jquery/plugins/jeditable/jquery.jeditable.mini.js" charset="utf-8"></script>
<script type="text/javascript" src="/javascript/sage/js/tinymce.js"></script>
<script type="text/javascript" src="/javascript/tiny_mce/plugins/media/js/embed.js"></script>
{% endif %}

<script type="text/javascript">user_name= "{{ username }}";</script>
{% if worksheet.filename() %}
<script  type="text/javascript">
    worksheet_filename = "{{ worksheet.filename() }}";
    worksheet_name = {{ worksheet.name() | repr_str | safe }};
    {% if not worksheet.is_published() or worksheet.notebook().conf()['pub_interact'] %}
        server_ping_while_alive();
    {% endif %}
</script>
{% endif %}

{% endblock %}

{% block main %}
{% if notebook is defined and notebook.readonly_user(username) %}
<h1>{{ gettext('Account is read only.  You may download or delete worksheets or data.') }}</h1>
{% endif %}

<div id="worksheet-bar">
    <div class="worksheet_title">
        <a id="worksheet_title" class="worksheet_title"
           onClick="rename_worksheet(); return false;"
           title="{{ gettext('Click to rename this worksheet') }}">
            {{ worksheet.name() }}
        </a>
        <div><span class="lastedit">{{ gettext('last edited') }} {{ worksheet.html_time_last_edited(username) | safe }}</span></div>
        {% if worksheet.warn_about_other_person_editing(username) and username != 'guest' and not worksheet.docbrowser() and not worksheet.is_published() %}
        <span class="pingdown">({{ gettext('Someone else is viewing this worksheet') }})</span>
        {% endif %}
    </div>
    <div id="save-discard-buttons">
        {% if not worksheet.docbrowser() and not worksheet.is_published() %}
        <button name="button_save" title="{{ gettext('Save changes') }}" onClick="save_worksheet();">{{ gettext('Save') }}</button><button title="{{ gettext('Save changes and close window') }}" onClick="save_worksheet_and_close();" name="button_save">{{ gettext('Save & quit') }}</button><button title="{{ gettext('Discard changes to this worksheet') }}" onClick="worksheet_discard();">{{ gettext('Discard & quit') }}</button>
        {% endif %}
    </div>

    <div id="worksheet-menu">
    {% if not worksheet.is_published() %}
        <select class="worksheet"  onchange="go_option(this);" id="file-menu">
            <option title="{{ gettext('Select a file related function') }}" value=""  selected>{{ gettext('File...') }}</option>
            <option title="{{ gettext('Load a new worksheet stored in a file') }}" value="upload_worksheet_button();">{{ gettext('Load worksheet from a file...') }}</option>
            <option title="{{ gettext('Create a new worksheet') }}" value="new_worksheet();">{{ gettext('New worksheet') }}</option>
            <option title="{{ gettext('Save this worksheet to an sws file') }}" value="download_worksheet();">{{ gettext('Save worksheet to a file...') }}</option>
            <option title="{{ gettext('Print this worksheet') }}" value="print_worksheet();">{{ gettext('Print') }}</option>
            <option title="{{ gettext('Rename this worksheet') }}" value="rename_worksheet();">{{ gettext('Rename worksheet') }}</option>
            <option title="{{ gettext('Copy this worksheet') }}" value="copy_worksheet();">{{ gettext('Copy worksheet') }}</option>
            <option title="{{ gettext('Move this worksheet to the trash') }}" value="delete_worksheet('{{ worksheet.filename() }}');">{{ gettext('Delete worksheet') }}</option>
        </select>

        <select class="worksheet"  onchange="go_option(this);"  id="action-menu">
            <option title="{{ gettext('Select a worksheet function') }}" value="" selected>{{ gettext('Action...') }}</option>
            <option title="{{ gettext('Interrupt currently running calculations, if possible') }}" value="interrupt();">{{ gettext('Interrupt') }}</option>
            <option title="{{ gettext('Restart the worksheet process') }}" value="restart_sage();">{{ gettext('Restart worksheet') }}</option>
            <option title="{{ gettext('Quit the worksheet process') }}" value="save_worksheet_and_close();">{{ gettext('Save and quit worksheet') }}</option> 
            <option value="">---------------------------</option>
            <option title="{{ gettext('Evaluate all input cells in the worksheet') }}" value="evaluate_all();">{{ gettext('Evaluate All') }}</option>
            <option title="{{ gettext('Hide all output') }}" value="hide_all();">{{ gettext('Hide All Output') }}</option>
            <option title="{{ gettext('Show all output') }}" value="show_all();">{{ gettext('Show All Output') }}</option>
            <option title="{{ gettext('Delete all output') }}" value="delete_all_output();">{{ gettext('Delete All Output') }}</option>
            <option value="">---------------------------</option>
            <option title="{{ gettext('Switch to single-cell mode') }}" value="slide_mode();">{{ gettext('One Cell Mode') }}</option>
            <option title="{{ gettext('Switch to multi-cell mode') }}" value="cell_mode();">{{ gettext('Multi Cell Mode') }}</option> 
        </select>
        <select class="worksheet" onchange="handle_data_menu(this);" id="data-menu">
            <option title="{{ gettext('Select an attached file') }}" value="" selected>{{ gettext('Data...') }}</option>
            <option title="{{ gettext('Upload or create a data file in a wide range of formats') }}" value="__upload_data_file__">{{ gettext('Upload or create file...') }}</option>
            <option value="">--------------------</option>
            {% for name in worksheet.attached_data_files()|sort %}
            <option value="datafile?name={{ name }}">{{ name }}</option>
            {% endfor %}
        </select>

        {% if not worksheet.docbrowser() and not worksheet.is_published() %}
        <select onchange="go_system_select(this, {{ worksheet.system_index() }});" class="worksheet" id="systems-menu">
            {% for system_name in worksheet.notebook().systems(username) %}
            <option title="{{ gettext('Evaluate all input cells using %(i)s', i=system_names[loop.index0]) }}"
                    {{ "selected" if worksheet.system_index() == loop.index0 else "" }} value="{{ system_names[loop.index0] }}">
                {{ system_name }}
            </option>
            {% endfor %}
        </select>    
        <input type="checkbox" title="{{ gettext('Enable/disable pretty_printing') }}"
               onchange="pretty_print_check(this.checked);"
               class="worksheet" value="pretty_print" {{ "checked" if worksheet.pretty_print() else "" }} />&nbsp;{{ gettext('Typeset') }}
        <input id="3D_check", type="checkbox" title="{{ gettext('Load 3-D Live. Not recommended for worksheets with > 2 3-D Plots.') }}"
               onchange="live_3D_check(this.checked);"
               class="worksheet" value="live_3D" {{ "checked" if worksheet.live_3D() else "" }} />&nbsp;{{ gettext('Load 3-D Live') }}
        <input id="3D_use_java", type="checkbox" title="{{ gettext('Use java for 3-D. Only applies to this running of worksheet.') }}"
               onchange="3D_use_java_check(this.checked);"
               class="worksheet" value="3D_use_java"/>&nbsp;{{ gettext('Use java for 3-D') }}
         {% endif %}
    {% endif %} 
    </div>
    <div id="share-publish-buttons">
        {% if not worksheet.docbrowser() and not worksheet.is_published() %}
        {% macro cls(x) %}
        {{ "control-select" if x == select else "control" }}
        {% endmacro %}
        <a title="{{ gettext('Print this worksheet') }}" class="control" onClick="print_worksheet()">{{ gettext('Print') }}</a>
        <a class="{{ cls('use') }}" title="{{ gettext('Interactively use this worksheet') }}" href="./">{{ gettext('Worksheet') }}</a>        
        <a class="{{ cls('edit') }}" title="{{ gettext('Edit text version of this worksheet') }}" href="edit">{{ gettext('Edit') }}</a>
        <a class="{{ cls('text') }}" title="{{ gettext('View plain text version of this worksheet') }}" href="text">{{ gettext('Text') }}</a>
        <a class="{{ cls('revisions') }}" title="{{ gettext('View changes to this worksheet over time') }}" href="revisions">{{ gettext('Revisions') }}</a>
        <a class="{{ cls('share') }}" title="{{ gettext('Let others edit this worksheet') }}" href="share">{{ gettext('Share') }}</a>
        <a class="{{ cls('publish') }}" title="{{ gettext('Make this worksheet publicly viewable') }}" href="publish">{{ gettext('Publish') }}</a>
        {% endif %}
    </div>
</div>
<div class="hidden" id="slide_controls">
    <div class="slideshow_control">
        <a class="slide_arrow" onClick="slide_next()">&gt;</a>
        <a class="slide_arrow" onClick="slide_last()">&gt;&gt;</a> <span class="vbar"></span>
        <a class="cell_mode" onClick="cell_mode()">{{ gettext('Exit') }}</a>
    </div>
    <div class="slideshow_progress" id="slideshow_progress" onClick="slide_next()">
        <div class="slideshow_progress_bar" id="slideshow_progress_bar">&nbsp;</div>
        <div class="slideshow_progress_text" id="slideshow_progress_text">&nbsp;</div>
    </div>
    <div class="slideshow_control">
        <a class="slide_arrow" onClick="slide_first()">&lt;&lt;</a>
        <a class="slide_arrow" onClick="slide_prev()">&lt;</a>
    </div>
</div>
{% block worksheet_main %}{% endblock %}
{% endblock %}
