From b56cf1882d5e91b2ff8f96094bdd9ef8ca1fb6ea Mon Sep 17 00:00:00 2001 From: lins05 Date: Fri, 10 Aug 2012 13:28:35 +0800 Subject: [PATCH] add 'open-local-file' link --- templates/repo.html | 83 +++++++++++++++++++++++++++++++++++++++++++-- views.py | 1 + 2 files changed, 82 insertions(+), 2 deletions(-) diff --git a/templates/repo.html b/templates/repo.html index c2c59eccc9..0fa8c78bdc 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 }} @@ -222,6 +228,18 @@ {% endif %} + +
+

请确认本地 Seafile 程序已启动

+ 关闭 +
+ +
+

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

+

点此同步

+ 关闭 +
+ {% endblock %} {% block extra_script %} @@ -411,5 +429,66 @@ $('#upload-file, #add-new-dir').hover( {% include "snippets/bottom_bar.html" %} {% endif %} + +function send_open_local_file_request(repo_id, 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) { + // nothing to do + }, + }); +} + +// when user clicks 'open local file', first check whether repo exists +// on local machine, then: +// - if exists, send an open requst +// - if not exits, redirect to repo download page +// if local seafile client is not running, show a dialog to tell the user + +$('a.open-local-file').click(function () { + var repo_id = '{{repo.id}}'; + var path = $(this).attr('data'); + + var local_applet_running = false; + var callback = 'xx'; + + url = '{{ applet_root }}/repo-query/?repo_id=' + repo_id + url += '&callback=' + callback; + $.ajax({ + url: url, + dataType: 'jsonp', + jsonpCallback: callback, + crossDomain: true, + success: function(data) { + local_applet_running = true; + + if (data['exists']) { + send_open_local_file_request(repo_id, path); + } else { + // this repo does not exist on local machine, redirect to + // download page + download_url = '{{ SITE_ROOT }}download/repo/?repo_id={{ repo.id }}'; + $('#redirect-download-url').attr('href', download_url); + $('#redirect-download').modal({appendTo:'#main'}); + } + }, + }); + + // 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-dlg').modal({appendTo:'#main'}); + } + }, 2000); +}); + {% endblock %} diff --git a/views.py b/views.py index 60b9ea9f77..399f762c9b 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