mirror of
https://github.com/haiwen/seahub.git
synced 2025-08-26 02:30:02 +00:00
add 'open-local-file' link
This commit is contained in:
parent
72dd6f61da
commit
b56cf1882d
@ -125,7 +125,10 @@
|
|||||||
{% if view_history %}
|
{% if view_history %}
|
||||||
<td><a href="{{ SITE_ROOT }}repo/{{ repo.id }}/?commit_id={{ current_commit.id }}&p={{ path|urlencode }}{{ dirent.obj_name|urlencode }}">{{ dirent.obj_name }}</a></td>
|
<td><a href="{{ SITE_ROOT }}repo/{{ repo.id }}/?commit_id={{ current_commit.id }}&p={{ path|urlencode }}{{ dirent.obj_name|urlencode }}">{{ dirent.obj_name }}</a></td>
|
||||||
{% else %}
|
{% else %}
|
||||||
<td><a href="{{ SITE_ROOT }}repo/{{ repo.id }}/?p={{ path|urlencode }}{{ dirent.obj_name|urlencode }}">{{ dirent.obj_name }}</a></td>
|
<td>
|
||||||
|
<a href="{{ SITE_ROOT }}repo/{{ repo.id }}/?p={{ path|urlencode }}{{ dirent.obj_name|urlencode }}">{{ dirent.obj_name }}</a>
|
||||||
|
<a href="#" class="open-local-file" data="{{path}}{{dirent.obj_name}}">打开本地文件</a>
|
||||||
|
</td>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<td></td>
|
<td></td>
|
||||||
@ -151,7 +154,10 @@
|
|||||||
{% if view_history %}
|
{% if view_history %}
|
||||||
<td><a class="op" href="{{ SITE_ROOT }}repo/{{ repo.props.id }}/files/?obj_id={{ dirent.props.obj_id }}&commit_id={{ current_commit.id }}&p={{ path|urlencode }}{{ dirent.obj_name|urlencode }}">{{ dirent.props.obj_name }}</a></td>
|
<td><a class="op" href="{{ SITE_ROOT }}repo/{{ repo.props.id }}/files/?obj_id={{ dirent.props.obj_id }}&commit_id={{ current_commit.id }}&p={{ path|urlencode }}{{ dirent.obj_name|urlencode }}">{{ dirent.props.obj_name }}</a></td>
|
||||||
{% else %}
|
{% else %}
|
||||||
<td><a class="op" href="{{ SITE_ROOT }}repo/{{ repo.props.id }}/files/?p={{ path|urlencode }}{{ dirent.obj_name|urlencode }}">{{ dirent.props.obj_name }}</a></td>
|
<td>
|
||||||
|
<a class="op" href="{{ SITE_ROOT }}repo/{{ repo.props.id }}/files/?p={{ path|urlencode }}{{ dirent.obj_name|urlencode }}">{{ dirent.props.obj_name }}</a>
|
||||||
|
<a href="#" class="open-local-file" data="{{path}}{{dirent.obj_name}}">打开本地文件</a>
|
||||||
|
</td>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<td>{{ dirent.file_size|filesizeformat }}</td>
|
<td>{{ dirent.file_size|filesizeformat }}</td>
|
||||||
@ -222,6 +228,18 @@
|
|||||||
<button class="simplemodal-close">取消</button>
|
<button class="simplemodal-close">取消</button>
|
||||||
</form>
|
</form>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
<div id="open-local-file-error-dlg" class="hide">
|
||||||
|
<p id="open-local-file-error" class="error">请确认本地 Seafile 程序已启动</p>
|
||||||
|
<buton class="simplemodal-close">关闭</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="redirect-download" class="hide">
|
||||||
|
<p>您还没有将同步目录 {{repo.name}} 同步到本地</p>
|
||||||
|
<p><a id="redirect-download-url" href="">点此同步</a></p>
|
||||||
|
<buton class="simplemodal-close">关闭</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block extra_script %}
|
{% block extra_script %}
|
||||||
@ -411,5 +429,66 @@ $('#upload-file, #add-new-dir').hover(
|
|||||||
|
|
||||||
{% include "snippets/bottom_bar.html" %}
|
{% include "snippets/bottom_bar.html" %}
|
||||||
{% endif %}
|
{% 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);
|
||||||
|
});
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
1
views.py
1
views.py
@ -238,6 +238,7 @@ def render_repo(request, repo_id, error=''):
|
|||||||
"zipped" : zipped,
|
"zipped" : zipped,
|
||||||
"error" : error,
|
"error" : error,
|
||||||
"accessible_repos" : accessible_repos,
|
"accessible_repos" : accessible_repos,
|
||||||
|
"applet_root": get_ccnetapplet_root()
|
||||||
}, context_instance=RequestContext(request))
|
}, context_instance=RequestContext(request))
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
|
Loading…
Reference in New Issue
Block a user