|
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
|
|
|
|
|
76
|
|
|
function project_prospects_slot_changed(id) |
|
77
|
|
|
{ |
|
78
|
|
|
var slot_cb = $(id + '_checkbox'); |
|
79
|
|
|
if (slot_cb.checked) |
|
80
|
|
|
{ |
|
81
|
|
|
project_prospects_choose_slot(id); |
|
82
|
|
|
} |
|
83
|
|
|
else |
|
84
|
|
|
{ |
|
85
|
|
|
project_prospects_unchoose_slot(id); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
function project_prospects_choose_slot(id) |
|
90
|
|
|
{ |
|
91
|
|
|
/* alert('project_prospects_choose_slot called:' + id); */ |
|
92
|
|
|
/* todo: do something more useful */ |
|
93
|
|
|
$("#" + id).addClass('selected'); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
function project_prospects_unchoose_slot(id) |
|
97
|
|
|
{ |
|
98
|
|
|
/* alert('project_prospects_unchoose_slot called:' + id); */ |
|
99
|
|
|
/* todo: do something more useful */ |
|
100
|
|
|
$("#" + id).removeClass('selected'); |
|
101
|
|
|
} |
|
102
|
|
|
|