Commits

Akash Sinha committed 1713208

File upload functionality moved from index2 to index, index2 has been removed, as well as its link from itemviews bar also.

Comments (0)

Files changed (8)

MoinMoin/apps/frontend/views.py

 logging = log.getLogger(__name__)
 
 from MoinMoin.i18n import _, L_, N_
-from MoinMoin.themes import render_template, get_editor_info
+from MoinMoin.themes import render_template, get_editor_info, contenttype_to_class
 from MoinMoin.apps.frontend import frontend
 from MoinMoin.items import Item, NonExistent
 from MoinMoin.items import ROWS_META, COLS, ROWS_DATA
                           )
 
 
-# XXX this has some functional redundancy with "index", solve that later
-@frontend.route('/+index2/<itemname:item_name>', methods=['GET'])
-def index2(item_name):
-    # flat index using jquery-file-upload (see also jfu_server)
-    return render_template('index2.html',
-                           item_name=item_name,
-                          )
-
-@frontend.route('/+jfu-server/<itemname:item_name>', methods=['GET', 'POST'])
+@frontend.route('/+jfu-server/<itemname:item_name>', methods=['POST'])
 def jfu_server(item_name):
     """jquery-file-upload server component
     """
-    if request.method == 'GET':
-        try:
-            item = Item.create(item_name)
-        except AccessDeniedError:
-            abort(403)
-        files = []
-        for full_name, rel_name, mimetype in item.flat_index():
-            url = url_for('.show_item', item_name=full_name)
-            url_download = url_for('.download_item', item_name=full_name)
-            files.append(dict(name=rel_name, url=url, url_download=url_download, size=0))
-        return jsonify(files=files)
-    if request.method == 'POST':
-        data_file = request.files.get('data_file')
-        subitem_name = data_file.filename
-        item_name = item_name + u'/' + subitem_name
-        try:
-            item = Item.create(item_name)
-            revno, size = item.modify()
-            item_modified.send(app._get_current_object(),
-                               item_name=item_name)
-            return jsonify(name=subitem_name,
-                           size=size,
-                           url=url_for('.show_item', item_name=item_name, rev=revno),
-                           url_download=url_for('.download_item', item_name=item_name, rev=revno),
-                          )
-        except AccessDeniedError:
-            abort(403)
-
+    data_file = request.files.get('data_file')
+    subitem_name = data_file.filename
+    item_name = item_name + u'/' + subitem_name
+    try:
+        item = Item.create(item_name)
+        revno, size = item.modify()
+        item_modified.send(app._get_current_object(),
+                           item_name=item_name)
+        return jsonify(name=subitem_name,
+                       size=size,
+                       url=url_for('.show_item', item_name=item_name, rev=revno),
+                       contenttype=contenttype_to_class(item.contenttype),
+                      )
+    except AccessDeniedError:
+        abort(403)
 
 
 @frontend.route('/+index/<itemname:item_name>')

MoinMoin/config/default.py

         ('frontend.modify_item', L_('Modify'), L_('Edit or Upload'), True, ),
         ('special.supplementation', None, None, False, ),
         ('frontend.index', L_('Index'), L_('List sub-items'), False, ),
-        ('frontend.index2', L_('Index'), L_('List sub-items'), False, ),
         ('special.comments', L_('Comments'), L_('Switch showing comments on or off'), True, ),
         ('frontend.highlight_item', L_('Highlight'), L_('Show with Syntax-Highlighting'), True, ),
         ('frontend.show_item_meta', L_('Meta'), L_('Display Metadata'), True, ),

MoinMoin/static/js/jfu.js

         this.url = container.find('form:first').attr('action');
         this.dropZone = container.find('form:first');
         this.uploadTable = container.find('.files:first');
-        this.downloadTable = this.uploadTable;
+        this.downloadTable = $("#moin-new-index");
         this.progressAllNode = container.find('.file_upload_overall_progress div:first');
         this.uploadTemplate = this.uploadTable.find('.file_upload_template:first');
-        this.downloadTemplate = this.uploadTable.find('.file_download_template:first');
+        this.downloadTemplate = this.downloadTable.find('.file_download_template:first');
         this.multiButtons = container.find('.file_upload_buttons:first');
         
         this.formatFileName = function (name) {
         };
 
         this.buildMultiDownloadRow = function (files, handler) {
-            var rows = $('<tbody style="display:none;"/>');
             $.each(files, function (index, file) {
                 rows.append(handler.buildDownloadRow(file, handler).show());
             });
             }
             var fileName = handler.formatFileName(file.name),
                 fileUrl = file.url,
-                fileUrlDownload = file.url_download,
+                fileContenttype = file.contenttype,
                 downloadRow = handler.downloadTemplate
                     .clone().removeAttr('id');
             downloadRow.attr('data-id', file.id || file.name);
-            downloadRow.find('.file_name a')
+            downloadRow.find('a')
                 .text(fileName);
-            downloadRow.find('.file_name a')
+            downloadRow.find('a')
                 .attr('href', fileUrl || null);
-            downloadRow.find('.file_download a')
-                .text('DL');
-            downloadRow.find('.file_download a')
-                .attr('href', fileUrlDownload || null)
-                .each(handler.enableDragToDesktop);
+            downloadRow.find('a')
+                .attr('class', fileContenttype || null);
             return downloadRow;
         };
         
             if (!uploadHandler.uploadTable.find('.file_upload_progress div:visible:first').length) {
                 uploadHandler.multiButtons.find('.file_upload_start:first, .file_upload_cancel:first').fadeOut();
             }
+            if (!uploadHandler.downloadTable.find("h3:visible").length) {
+                uploadHandler.downloadTable.find("h3:first").fadeIn();
+                $(".moin-index-separator").fadeIn();
+            }
         };
 
         this.initEventHandlers = function () {
 $(function () {
     // Initialize jQuery File Upload (Extended User Interface Version):
     $('#file_upload').fileUploadUIX();
-
-    // Load existing files:
-    $.getJSON($('#file_upload').fileUploadUIX('option', 'url'), function (files) {
-        var fileUploadOptions = $('#file_upload').fileUploadUIX('option');
-        $.each(files, function (index, file) {
-            fileUploadOptions.buildDownloadRow(file, fileUploadOptions)
-                .appendTo(fileUploadOptions.downloadTable).fadeIn();
-        });
-    });
 });

MoinMoin/templates/forms.html

     </dd>
     {% endif %}
 {% endmacro %}
+
+{% macro render_file_uploader(submit_url) %}
+    <div id="file_upload">
+        <form action="{{ submit_url }}" method="POST" enctype="multipart/form-data">
+            <input type="file" name="data_file" multiple>
+            <button type="submit">{{ _("Upload") }}</button>
+            <div class="file_upload_label" style="margin: 0;">{{ _("Upload files") }}</div>
+        </form>
+        <div class="file_upload_overall_progress"><div style="display:none;"></div></div>
+        <div class="file_upload_buttons">
+            <button class="file_upload_start" style="display:none;">{{ _("Start All") }}</button> 
+            <button class="file_upload_cancel" style="display:none;">{{ _("Cancel All") }}</button> 
+        </div>
+        <table class="files">
+            <tr class="file_upload_template" style="display:none;">
+                <td class="file_upload_start"><button>{{ _("Start") }}</button></td>
+                <td class="file_upload_cancel"><button>{{ _("Cancel") }}</button></td>
+                <td class="file_name"></td>
+                <td class="file_upload_progress"><div></div></td>
+            </tr>
+        </table>
+    </div>
+    <link rel="stylesheet" href="{{ url_for('serve.files', name='jquery_file_upload', filename='jquery.fileupload-ui.css') }}">
+    <script src="{{ url_for('serve.files', name='jquery_file_upload', filename='jquery.fileupload.js') }}"></script>
+    <script src="{{ url_for('serve.files', name='jquery_file_upload', filename='jquery.fileupload-ui.js') }}"></script>
+{% endmacro %}

MoinMoin/templates/index.html

 {% extends theme("show.html") %}
+{% import "forms.html" as forms %}
 
 {% block content %}
     <h1>{{ _("Index of subitems of '%(item_name)s'", item_name=item_name) }}</h1>
         <span class="moin-path-separator">{{ ("/") }}</span>
     {% endfor %}
     </div>
+    <div id="moin-new-index" class="moin-item-index">
+        <h3 style="display: none;">{{ _("Recently uploaded items") }}</h3>
+        <div class="file_download_template" style="display: none;">
+            <a></a>
+        </div>
+    </div>
+    <div class="moin-index-separator"></div>
     {% if index %}
-    <div id="moin-item-index">
+    <div class="moin-item-index">
         {% set maxchars = 20 %}
         {% for fullname, relname, contenttype, hassubitem in index %}
             <div>
     </div>
     <div class="moin-clr"></div>
     {% endif %}
+    {% set submit_url = url_for('.jfu_server', item_name=item_name) %}
+    {{ forms.render_file_uploader(submit_url) }}
+    <script src="{{ url_for('static', filename='js/jfu.js') }}"></script>
 {% endblock %}

MoinMoin/templates/index2.html

-{% extends theme("show.html") %}
-
-{% block theme_stylesheets %}
-{{ super() }}
-<link rel="stylesheet" href="{{ url_for('serve.files', name='jquery_file_upload', filename='jquery.fileupload-ui.css') }}">
-{% endblock %}
-
-{% block content %}
-    <h1>{{ _("Index of subitems of '%(item_name)s'", item_name=item_name) }}</h1>
-<div id="file_upload">
-    <form action="{{ url_for('.jfu_server', item_name=item_name) }}" method="POST" enctype="multipart/form-data">
-        <input type="file" name="data_file" multiple>
-        <button type="submit">Upload</button>
-        <div class="file_upload_label">Upload files</div>
-    </form>
-    <div class="file_upload_overall_progress"><div style="display:none;"></div></div>
-    <div class="file_upload_buttons">
-        <button class="file_upload_start" style="display:none;">Start All</button> 
-        <button class="file_upload_cancel" style="display:none;">Cancel All</button> 
-    </div>
-    <table class="files">
-        <tr class="file_upload_template" style="display:none;">
-            <td class="file_upload_start"><button>Start</button></td>
-            <td class="file_upload_cancel"><button>Cancel</button></td>
-            <td class="file_name"></td>
-            <td class="file_upload_progress"><div></div></td>
-        </tr>
-        <tr class="file_download_template" style="display:none;">
-            <td class="file_download" colspan="2"><a></a></td>
-            <td class="file_name" colspan="2"><a></a></td>
-        </tr>
-    </table>
-</div>
-<script src="{{ url_for('serve.files', name='jquery_file_upload', filename='jquery.fileupload.js') }}"></script>
-<script src="{{ url_for('serve.files', name='jquery_file_upload', filename='jquery.fileupload-ui.js') }}"></script>
-<script src="{{ url_for('static', filename='js/jfu.js') }}"></script>
-{% endblock %}

MoinMoin/templates/itemviews.html

 <ul class="moin-itemviews">
     {% for endpoint, label, title, check_exists in cfg.item_views if not endpoint in cfg.endpoints_excluded %}
         {% if (not check_exists or check_exists and exists) and endpoint in [
-               'frontend.show_item', 'frontend.index', 'frontend.index2',
+               'frontend.show_item', 'frontend.index',
                'frontend.highlight_item', 'frontend.show_item_meta', 'frontend.download_item',
                'frontend.history', 'frontend.backrefs', 'frontend.sitemap',
                'frontend.similar_names',

MoinMoin/themes/modernized/static/css/common.css

 #moin-letters a:hover,
 #moin-letters a.selected { background: #4477FF; border-radius: 5px; color: #FFFFFF; text-decoration: none; }
 #moin-global-index,
-#moin-item-index { width: 100%; margin-left: 0.5em; }
+.moin-item-index { width: 100%; margin-left: 0.5em; }
 #moin-global-index div,
-#moin-item-index div { float: left; width: 15em; }
+.moin-item-index div { float: left; width: 15em; }
 .moin-select-contenttypes { float: right; position: relative; width: 14em; }
 .moin-select-contenttypes .moin-contenttypes-wrapper { position: absolute; top: 0; left: 0; color: #342D7E; background: #FFFFFF; border: 1px solid #342D7E; width: 14em; }
 .moin-contenttypes-wrapper div { cursor: pointer; margin: 0.1em; padding: 0.2em 1.3em 0.2em 0.2em; background: transparent url("../img/moin-moveup.png") no-repeat center right; } 
 .moin-index-path { margin-left: 0.5em; }
 .moin-index-path:before { content: url("../img/moin-parent.png"); margin: 0 0.3em; }
 .moin-path-separator { font-size: 120%; color: #4477FF; }
+.moin-index-separator { clear: both; border-top: 1px dashed #CCCCCC; width: 80%; display: none; }
 
 /* diffs */
 .moin-diff { width:99%; table-layout: fixed; }