1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-08-25 18:20:48 +00:00

check seafile version before send open-file request

This commit is contained in:
lins05 2012-08-10 18:49:55 +08:00
parent b56cf1882d
commit 5bd32f07c4

View File

@ -230,14 +230,12 @@
{% endif %} {% endif %}
<div id="open-local-file-error-dlg" class="hide"> <div id="open-local-file-error-dlg" class="hide">
<p id="open-local-file-error" class="error">请确认本地 Seafile 程序已启动</p> <p id="open-local-file-error" class="error"></p>
<buton class="simplemodal-close">关闭</button>
</div> </div>
<div id="redirect-download" class="hide"> <div id="redirect-download" class="hide">
<p>您还没有将同步目录 {{repo.name}} 同步到本地</p> <p>您还没有将同步目录 {{repo.name}} 同步到本地</p>
<p><a id="redirect-download-url" href="">点此同步</a></p> <p><a id="redirect-download-url" href="">点此同步</a></p>
<buton class="simplemodal-close">关闭</button>
</div> </div>
{% endblock %} {% endblock %}
@ -441,25 +439,35 @@ function send_open_local_file_request(repo_id, path) {
jsonpCallback: callback, jsonpCallback: callback,
crossDomain: true, crossDomain: true,
success: function(data) { success: function(data) {
// nothing to do if (data['error']) {
}, if (data['no_assoc']) {
$('#open-local-file-error').html('找不到打开该类型文件的程序');
} else {
$('#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 whether repo exists // When user clicks 'open local file':
// on local machine, then: //
// - if exists, send an open requst // - 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 // - 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 () { $('a.open-local-file').click(function () {
var repo_id = '{{repo.id}}'; var repo_id = '{{repo.id}}';
var path = $(this).attr('data'); var path = $(this).attr('data');
var local_applet_running = false; function check_repo_exist() {
var callback = 'xx'; var callback = 'xx';
url = '{{ applet_root }}/repo-query/?repo_id=' + repo_id;
url = '{{ applet_root }}/repo-query/?repo_id=' + repo_id
url += '&callback=' + callback; url += '&callback=' + callback;
$.ajax({ $.ajax({
url: url, url: url,
@ -467,11 +475,14 @@ $('a.open-local-file').click(function () {
jsonpCallback: callback, jsonpCallback: callback,
crossDomain: true, crossDomain: true,
success: function(data) { success: function(data) {
local_applet_running = true; if (data['error']) {
$('#open-local-file-error').html('打开本地文件时出错');
$('#open-local-file-error-dlg').modal({appendTo:'#main'});
if (data['exists']) { } else if (data['exists'] === true) {
send_open_local_file_request(repo_id, path); send_open_local_file_request(repo_id, path);
} else {
} else if (data['exists'] === false) {
// this repo does not exist on local machine, redirect to // this repo does not exist on local machine, redirect to
// download page // download page
download_url = '{{ SITE_ROOT }}download/repo/?repo_id={{ repo.id }}'; download_url = '{{ SITE_ROOT }}download/repo/?repo_id={{ repo.id }}';
@ -480,11 +491,31 @@ $('a.open-local-file').click(function () {
} }
}, },
}); });
}
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 = '<a href="http://www.seafile.com/download/">升级</a>';
$('#open-local-file-error').html('您的 Seafile 客户端版本太低,请' + update_url + '到最新版本');
$('#open-local-file-error-dlg').modal({appendTo:'#main'});
} else {
check_repo_exist();
}
},
});
// if jsonp response doesn't arrive in 2 seconds, we can say local client // if jsonp response doesn't arrive in 2 seconds, we can say local client
// is not running yet. // is not running yet.
setTimeout(function() { setTimeout(function() {
if (!local_applet_running) { if (!local_applet_running) {
$('#open-local-file-error').html('请确认本地 Seafile 程序已启动');
$('#open-local-file-error-dlg').modal({appendTo:'#main'}); $('#open-local-file-error-dlg').modal({appendTo:'#main'});
} }
}, 2000); }, 2000);