Merge pull request #1664 from riyad/auto-complete-everywhere

Cleanup auto-completion and add it to all GFM inputs
This commit is contained in:
Dmitriy Zaporozhets 2012-10-10 01:45:03 -07:00
commit 60b4c88e3a
12 changed files with 89 additions and 66 deletions

View file

@ -12,7 +12,7 @@
= f.label :title do
%strong= "Subject *"
.input
= f.text_field :title, maxlength: 255, class: "xxlarge"
= f.text_field :title, maxlength: 255, class: "xxlarge gfm-input"
.issue_middle_block
.issue_assignee
= f.label :assignee_id do
@ -37,7 +37,7 @@
.clearfix
= f.label :description, "Details"
.input
= f.text_area :description, maxlength: 2000, class: "xxlarge", rows: 14
= f.text_area :description, maxlength: 2000, class: "xxlarge gfm-input", rows: 14
%p.hint Issues are parsed with #{link_to "GitLab Flavored Markdown", help_markdown_path, target: '_blank'}.

View file

@ -28,6 +28,8 @@
My profile
= link_to 'Logout', destroy_user_session_path, class: "logout", method: :delete
= render "layouts/init_auto_complete"
:javascript
$(function(){
$("#search").autocomplete({

View file

@ -0,0 +1,17 @@
:javascript
$(function() {
autocompleteMembersUrl = "#{ "/api/v2/projects/#{@project.code}/members" if @project }";
autocompleteMembersParams.private_token = "#{current_user.authentication_token}";
autocompleteEmojiData = #{raw emoji_autocomplete_source};
// convert the list so that the items have the right format for completion
autocompleteEmojiData = $.map(autocompleteEmojiData, function(value) {
return {
name: value,
insert: value+':',
image: '#{image_path("emoji")}/'+value+'.png'
}
});
setupGfmAutoComplete();
});

View file

@ -38,7 +38,7 @@
.top_box_content
= f.label :title do
%strong= "Title *"
.input= f.text_field :title, class: "input-xxlarge pad", maxlength: 255, rows: 5
.input= f.text_field :title, class: "input-xxlarge pad gfm-input", maxlength: 255, rows: 5
.middle_box_content
= f.label :assignee_id do
%i.icon-user

View file

@ -36,49 +36,3 @@
%a.file_upload.btn.small Upload File
= f.file_field :attachment, class: "input-file"
%span.hint Any file less than 10 MB
:javascript
$(function(){
// init auto-completion of team members
var membersUrl = "#{root_url}/api/v2/projects/#{@project.code}/members";
var membersParams = {
private_token: "#{current_user.authentication_token}",
page: 1,
};
var membersData = [];
$('.gfm-input').atWho('@', function(query, callback) {
(function getMoreMembers() {
$.getJSON(membersUrl, membersParams).
success(function(members) {
// pick the data we need
var newMembersData = $.map(members, function(member) { return member.name });
// add the new page of data to the rest
$.merge(membersData, newMembersData);
// show the pop-up with a copy of the current data
callback(membersData.slice(0));
// are we past the last page?
if (newMembersData.length == 0) {
// set static data and stop callbacks
$('.gfm-input').atWho('@', { data: membersData, callback: null });
} else {
// get next page
getMoreMembers();
}
});
// next request will get the next page
membersParams.page += 1;
})();
});
// init auto-completion of emoji
var emoji = #{emoji_for_completion};
// convert the list so that the items have the right format for completion
emoji = $.map(emoji, function(value) {return { key: value+':', name: value }});
$('.gfm-input').atWho(':', {
data: emoji,
tpl: "<li data-value='${key}'>${name} #{escape_javascript image_tag('emoji/${name}.png', :size => '20x20')}</li>"
});
});

View file

@ -10,4 +10,5 @@
- else
:plain
$(".note-form-holder").replaceWith("#{escape_javascript(render 'form')}");
setupGfmAutoComplete();

View file

@ -21,7 +21,7 @@
.bottom_box_content
= f.label :content
.input= f.text_area :content, class: 'span8'
.input= f.text_area :content, class: 'span8 gfm-input'
.actions
= f.submit 'Save', class: "save-btn btn"
= link_to "Cancel", project_wiki_path(@project, :index), class: "btn cancel-btn"