1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-02 07:27:04 +00:00

improved recommend-to-group & clean up code

This commit is contained in:
llj
2012-10-22 17:15:35 +08:00
parent 5795f4c304
commit d9bbed6f04
5 changed files with 82 additions and 62 deletions

View File

@@ -10,16 +10,29 @@ var group_list = []
{% for group in groups %}
group_list.push('{{ group.props.group_name }} <{{ group.props.creator_name }}>');
{% endfor %}
if (group_list.length == 1) {
$('#recommend-groups').val(group_list[0]);
}
$('#recommend-to-group-caret').css('left', $('#recommend').offset().left);
$('#recommend').click(function() {
$('#recommend-form').modal({appendTo: '#main'});
addAutocomplete('#recommend-groups', '#recommend-form', group_list);
$('.ui-autocomplete').css({'max-height': window.innerHeight - $('.ui-autocomplete-input').offset().top - $('.ui-autocomplete-input').height() - 10, 'overflow': 'auto'});
if ($('#recommend-to-group-form').hasClass('hide')) {
$('#recommend-to-group-form, #recommend-to-group-caret').removeClass('hide');
} else {
$('#recommend-to-group-form, #recommend-to-group-caret').addClass('hide');
}
});
$(document).click(function(e) {
var target = e.target || event.srcElement;
if (!$('#recommend, #recommend-to-group-form, #recommend-to-group-caret').is(target) && !($('#recommend-to-group-form, #recommend-to-group-caret').find('*').is(target))) {
$('#recommend-to-group-form, #recommend-to-group-caret').addClass('hide');
}
});
$('#main').append('<div id="to-group" class="hide">{{ repo_group_str|escapejs }}</div><div id="to-group-caret" class="hide"><div id="comment-outer-caret"><div id="comment-inner-caret"></div></div></div>');
$('#recommend-submit').click(function() {
if (!$.trim($('#recommend-to-group-form [name="message"]').val())) {
apply_form_error('recommend-form', '推荐语不能为空。');
return false;
}
});
$('#main').append('<div id="to-group" class="hide">{{ repo_group_str|escapejs }}</div><div id="to-group-caret" class="hide"><div class="outer-caret"><div class="inner-caret"></div></div></div>');
$('#to-group').css({'width':$('#to-group').width(), 'left':$('#click-into-group').offset().left - $('#to-group').width()/3});
$('#to-group-caret').css('left', $('#click-into-group').offset().left);
$('#click-into-group').click(function() {
@@ -44,10 +57,4 @@ $(document).click(function(e) {
$('#to-group, #to-group-caret').addClass('hide');
}
});
$('#recommend-submit').click(function() {
if (!$.trim($('#recommend-msg').val())) {
apply_form_error('recommend-form', '推荐语不能为空。');
return false;
}
});
{% endif %}

View File

@@ -1,25 +1,28 @@
{% load url from future %}
<form action="{% url 'group_recommend' %}" method="post" id="recommend-form" class="hide">{% csrf_token %}
<form action="{% url 'group_recommend' %}" method="post" id="recommend-to-group-form" class="hide">{% csrf_token %}
<h3>推荐
{% for name, link in zipped %}
{% if forloop.last %}
{{ name }}
<span class="op-target">{{ name }}</span>
{% endif %}
{% endfor %}
到群组:
</h3>
<div>
{% for group in groups %}
<input type="checkbox" name="groups" value="{{ group.id }}" {% if forloop.first and forloop.last %} checked {% endif %}>{{ group.group_name }}<br>
{% endfor %}
<div class="groups">
{% for group in groups %}
<input type="checkbox" name="groups" value="{{ group.id }}" id="{{ group.id }}" {% if forloop.first and forloop.last %}checked="checked"{% endif %} class="group-checkbox"><label for="{{ group.id }}" class="group-name">{{ group.group_name }}</label>
{% endfor %}
</div>
<label>推荐语:</label><br />
<textarea name="message" id="recommend-msg"></textarea><br />
<label>推荐语:</label>
<textarea name="message"></textarea>
<input type="hidden" name="repo_id" value="{{ repo.id }}" />
<input type="hidden" name="path" value="{{ path }}" />
<input type="hidden" name="attach_type" value="{{ attach_type }}" />
<p class="error hide"></p>
<input type="submit" id="recommend-submit" class="submit" value="提交" />
<button class="simplemodal-close">取消</button>
</form>
<div id="recommend-to-group-caret" class="hide">
<div class="outer-caret">
<div class="inner-caret"></div>
</div>
</div>