diff --git a/templates/repo.html b/templates/repo.html index 5fec0c6c24..2a8a25f429 100644 --- a/templates/repo.html +++ b/templates/repo.html @@ -125,7 +125,10 @@ {% if view_history %} {{ dirent.obj_name }} {% else %} - {{ dirent.obj_name }} + + {{ dirent.obj_name }} + 打开本地文件 + {% endif %} @@ -151,7 +154,10 @@ {% if view_history %} {{ dirent.props.obj_name }} {% else %} - {{ dirent.props.obj_name }} + + {{ dirent.props.obj_name }} + 打开本地文件 + {% endif %} {{ dirent.file_size|filesizeformat }} @@ -221,6 +227,16 @@ {% endif %} + +
+

+
+ +
+

您还没有将同步目录 {{repo.name}} 同步到本地

+

点此同步

+
+ {% endblock %} {% block extra_script %} @@ -410,5 +426,77 @@ $('#upload-file, #add-new-dir').hover( {% include "snippets/bottom_bar.html" %} {% endif %} + +function send_open_local_file_request(path) { + var callback = 'xx'; + url = '{{ applet_root }}/open-local-file/?repo_id={{ repo.id }}'; + url += '&path=' + encodeURIComponent(path); + url += '&callback=' + callback; + $.ajax({ + url: url, + dataType: 'jsonp', + jsonpCallback: callback, + crossDomain: true, + success: function(data) { + if (data['exists'] === false) { + // repo doesn't exist on local machine + $('#redirect-download').modal({appendTo:'#main'}); + + } else if (data['no_assoc'] === true) { + // no application to open the file + $('#open-local-file-error').html('找不到打开该类型文件的程序。\nSeafile 将为你打开该文件所在目录'); + $('#open-local-file-error-dlg').modal({appendTo:'#main'}); + + } else if (data['error']) { + // other error + $('#open-local-file-error').html('打开本地文件时出错'); + $('#open-local-file-error-dlg').modal({appendTo:'#main'}); + + } else { + // open file successfully, nothing to do + } + } + }); +} + +// When user clicks 'open local file': +// +// - First, check client version to determine is this operation supported by client +// - second check whether repo exists on local machine, then: +// - if exists, send an open local file requst +// - if not exits, redirect to repo download page + + +$('a.open-local-file').click(function () { + var path = $(this).attr('data'); + var local_applet_running = false; + + $.ajax({ + url: '{{ applet_root }}/seafile_access_check/', + dataType: 'jsonp', + jsonpCallback: 'xx', + crossDomain: true, + success: function(version) { + local_applet_running = true; + if (version < 3) { + update_url = '升级'; + $('#open-local-file-error').html('您的 Seafile 客户端版本太低,请' + update_url + '到最新版本'); + $('#open-local-file-error-dlg').modal({appendTo:'#main'}); + } else { + send_open_local_file_request(path); + } + }, + }); + + // if jsonp response doesn't arrive in 2 seconds, we can say local client + // is not running yet. + setTimeout(function() { + if (!local_applet_running) { + $('#open-local-file-error').html('请确认本地 Seafile 程序已启动'); + $('#open-local-file-error-dlg').modal({appendTo:'#main'}); + } + }, 2000); +}); + {% endblock %} diff --git a/templates/seafile_access_check.html b/templates/seafile_access_check.html index 72f9296cc7..afdf1f4c3c 100644 --- a/templates/seafile_access_check.html +++ b/templates/seafile_access_check.html @@ -18,7 +18,7 @@ $(function() { jsonpCallback: 'xx', crossDomain: true, success: function(version) { - if (version !== 2) { + if (version < 2) { version_mismatch = true; } else { req_success = true; diff --git a/views.py b/views.py index aeba28812a..c1561d891e 100644 --- a/views.py +++ b/views.py @@ -238,6 +238,7 @@ def render_repo(request, repo_id, error=''): "zipped" : zipped, "error" : error, "accessible_repos" : accessible_repos, + "applet_root": get_ccnetapplet_root() }, context_instance=RequestContext(request)) @login_required