Created
August 29, 2018 02:49
-
-
Save tak1827/35fb7fdd222ddb043ad9693a5c1da38d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*********************************** | |
vi app/views/issues/_form.html.erb | |
***********************************/ | |
<p><label for="issue_tracker_id"><%= l(:field_tracker) %><span class="required"> *</span></label> <%= text_field_tag :issue_tracker_autocomplete, trackers_options_for_select(@issue), {:required => true, :onchange => "updateIssueFrom('#{escape_javascript update_issue_form_path(@project, @issue)}', this)"} %><%= f.hidden_field :tracker_id %></p> | |
$("#issue_status_id").each(function(){ | |
$(this).val($(this).find("option[selected=selected]").val()); | |
}); | |
$.each(tracker_list, function(i, v) { | |
if (v.id == $("#issue_tracker_id").val()) $("#issue_tracker_autocomplete").val(v.label); | |
}); | |
var tracker_list = <%= raw [].concat(@issue.allowed_target_trackers.collect{|t| {:id => t.id, :label => t.name}}).to_json %>; | |
observeAutocompleteField('issue_tracker_autocomplete', '', { | |
source: tracker_list, | |
minLength: 0, | |
select: function(event, ui){$('#issue_tracker_id').val(ui.item.id);}, | |
change: function(event, ui){ | |
var trackers = $.grep(tracker_list, function(item, i){ | |
return( | |
item.label.toLowerCase()==$('#issue_tracker_autocomplete').val().toLowerCase() | |
); | |
}); | |
if(trackers.length==1){ | |
$('#issue_tracker_autocomplete').val(trackers[0].label); | |
$('#issue_tracker_id').val(trackers[0].id); | |
}else{ | |
$('#issue_tracker_autocomplete, #issue_tracker_id').val(''); | |
} | |
updateIssueFrom('#{escape_javascript update_issue_form_path(@project, @issue)}', this) | |
}, | |
create: function(){ | |
$(this).data('ui-autocomplete')._renderMenu = function(ul, items){ | |
var self = this; | |
$.each(items, function(index, item){ | |
self._renderItemData(ul, item); | |
}); | |
}; | |
$(this).data('ui-autocomplete')._renderItem = function(ul, item){ | |
ul.css({'background':'#eee','overflow':'scroll'}); | |
return $('<li style="white-space:nowrap">') | |
.append('<div>'+item.label+'</div>') | |
.appendTo(ul); | |
}; | |
} | |
}); | |
$('#issue_tracker_autocomplete').focus(function(){ | |
$(this).data("uiAutocomplete").search($(this).val()); | |
}); | |
/*********************************** | |
vi app/views/issues/_attributes.html.erb | |
***********************************/ | |
<p><label><%= l(:field_assigned_to) %><span class="required"> *</span></label> <%= text_field_tag :issue_assigned_to_autocomplete, @issue.assigned_to ? @issue.assigned_to.name : '', :required => true %><%= f.hidden_field :assigned_to_id %></p> | |
var assignner_list = <%= raw [{:id => User.current.id, :label => "<< #{l(:label_me)} >>", :category => 'User'}] | |
.concat(@issue.assignable_users.select{|u|u.is_a?(User)}.map{|u|{:id => u.id, :label => u.name, :category => 'User'}}) | |
.concat(@issue.assignable_users.select{|u|u.is_a?(Group)}.map{|u|{:id => u.id, :label => u.name, :category => 'Group'}}).to_json %>; | |
observeAutocompleteField('issue_assigned_to_autocomplete', '', { | |
source: assignner_list, | |
minLength: 0, | |
select: function(event, ui){$('#issue_assigned_to_id').val(ui.item.id);}, | |
change: function(event, ui){ | |
var assigners = $.grep(assignner_list, function(item, i){return(item.label.toLowerCase()==$('#issue_assigned_to_autocomplete').val().toLowerCase());}); | |
if(assigners.length==1){ | |
$('#issue_assigned_to_autocomplete').val(assigners[0].label); | |
$('#issue_assigned_to_id').val(assigners[0].id); | |
}else{ | |
$('#issue_assigned_to_autocomplete, #issue_assigned_to_id').val(''); | |
} | |
}, | |
create: function(){ | |
$(this).data('ui-autocomplete')._renderMenu = function(ul, items){ | |
var self = this, category = null; | |
$.each(items, function(index, item){ | |
if(item.category!=category && item.category=='Group'){ | |
ul.append("<li class='ui-autocomplete-group' style='padding-top:2px'>") | |
.append("<div> -- <i class='icon icon-group'></i><%= l(:label_group_plural) %> -- </div>"); | |
} | |
category=item.category; | |
self._renderItemData(ul, item); | |
}); | |
self.widget().menu( "option", "items", "> li:not(.ui-autocomplete-group)" ); | |
}; | |
$(this).data('ui-autocomplete')._renderItem = function(ul, item){ | |
ul.css({'background':'#eee','overflow':'scroll'}); | |
return $('<li style="white-space:nowrap">') | |
.append('<div>'+item.label+'</div>') | |
.appendTo(ul); | |
}; | |
} | |
}); | |
$('#issue_assigned_to_autocomplete').focus(function(){ | |
$(this).data("uiAutocomplete").search($(this).val()); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment