| Conditions | 1 |
| Paths | 1 |
| Total Lines | 74 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | (function($) { |
||
| 2 | $.fn.extend( |
||
| 3 | { |
||
| 4 | project_prospects_renderer: function(config) |
||
| 5 | { |
||
| 6 | var defaults = |
||
| 7 | { |
||
| 8 | base_url: '', |
||
| 9 | task_guid: false |
||
| 10 | }; |
||
| 11 | |||
| 12 | config = $.extend(defaults, config); |
||
| 13 | |||
| 14 | /* TODO: Make interval */ |
||
| 15 | get_prospect_list(); |
||
| 16 | |||
| 17 | function get_prospect_list() |
||
| 18 | { |
||
| 19 | var url = config.base_url + 'task/resourcing/prospects/' + config.task_guid + '/'; |
||
| 20 | /* Set the class which should give us a "loading" icon */ |
||
| 21 | $('#prospects_list').addClass('project_prospects_renderer_searching'); |
||
| 22 | $.ajax( |
||
| 23 | { |
||
| 24 | url: url, |
||
| 25 | success: ajax_success, |
||
| 26 | error: ajax_failure |
||
| 27 | }); |
||
| 28 | } |
||
| 29 | |||
| 30 | function ajax_success(data) |
||
| 31 | { |
||
| 32 | var label, prospect; |
||
| 33 | $('#prospects_list').removeClass('project_prospects_renderer_searching'); |
||
| 34 | $('#prospects_list').addClass('project_prospects_renderer_search_ok'); |
||
| 35 | /* Display lines in result */ |
||
| 36 | $('person', data).each(function() |
||
| 37 | { |
||
| 38 | prospect = $('prospect', this).text(); |
||
| 39 | label = $('label', this).text(); |
||
| 40 | add_result(prospect, label); |
||
| 41 | }); |
||
| 42 | } |
||
| 43 | |||
| 44 | function add_result(prospect, label) |
||
| 45 | { |
||
| 46 | var url = config.base_url + 'task/resourcing/prospect/' + prospect + '/'; |
||
| 47 | $('#prospects_list').append('<li id="prospect_' + prospect + '" class="project_prospects_renderer_searching">' + label + '</li>'); |
||
| 48 | /* new Insertion.Bottom(this.element, '<li id="prospect_' + prospect + '" class="project_prospects_renderer_searching" style="display: none;">' + label + '</li>'); */ |
||
| 49 | /* todo: use blinddown, etc to make the ui less jumpy */ |
||
| 50 | $('#prospect_' + prospect).load(url); |
||
| 51 | |||
| 52 | $('#prospect_' + prospect).removeClass('project_prospects_renderer_searching'); |
||
| 53 | $('#prospect_' + prospect).addClass('project_prospects_renderer_search_ok'); |
||
| 54 | } |
||
| 55 | |||
| 56 | function ajax_failure(obj, type) |
||
| 57 | { |
||
| 58 | /* This is called on xmlHttpRequest level failure, |
||
| 59 | MidCOM level errors are reported via the XML returned */ |
||
| 60 | $(this).removeClass('project_prospects_renderer_searching'); |
||
| 61 | $(this).addClass('project_prospects_renderer_search_fail'); |
||
| 62 | $.midcom_services_uimessage_add( |
||
| 63 | { |
||
| 64 | type: 'error', |
||
| 65 | title: 'Project prospects', |
||
| 66 | message: 'Ajax request level failure' |
||
| 67 | }); |
||
| 68 | /* TODO: Some kind of error handling ?? */ |
||
| 69 | return true; |
||
| 70 | } |
||
| 71 | |||
| 72 | } |
||
| 73 | }); |
||
| 74 | })(jQuery); |
||
| 75 | |||
| 102 |