mirror of
https://github.com/haiwen/seahub.git
synced 2025-08-25 18:20:48 +00:00
add 'open-local-file' link
This commit is contained in:
parent
72dd6f61da
commit
b56cf1882d
@ -125,7 +125,10 @@
|
||||
{% 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>
|
||||
{% 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 %}
|
||||
|
||||
<td></td>
|
||||
@ -151,7 +154,10 @@
|
||||
{% 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>
|
||||
{% 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 %}
|
||||
|
||||
<td>{{ dirent.file_size|filesizeformat }}</td>
|
||||
@ -222,6 +228,18 @@
|
||||
<button class="simplemodal-close">取消</button>
|
||||
</form>
|
||||
{% 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 %}
|
||||
|
||||
{% 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);
|
||||
});
|
||||
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
Loading…
Reference in New Issue
Block a user