-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyTasksNew.js
496 lines (437 loc) · 18.9 KB
/
MyTasksNew.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
/* Created By : Ravikishore */
/* Created Date :06/17/2013 */
var sourceTable = "";
var clickID;
var srcListName = "SourcingPlan";
var spendPoolListName = "SourcingPlanItems";
var arrayID = new Array();
var lstItemsId ;
var sourceTable = '<table id="tblSourcePlan" width="100%" class="tablesorter" border="0" cellSpacing="0" cellPadding="2" >';
//sourceTable += '<tr><td class="ms-vb2" colspan="4"> </td></tr>';
sourceTable += '<thead><tr Align="top"><th align="center" colspan="2">Sourcing Plan</th><th>Status</th><th>Approved Date</th></tr></thead>';
//sourceTable += "<tr><td class='ms-vb2' colspan='4'> </td></tr>";
var loginUser = $().SPServices.SPGetCurrentUser({
fieldName : "Title",
debug : false
});
$(document).ready(function () {
$('#tdWelcome').text('Welcome ' + loginUser);
var query = "<Query><Where><Eq><FieldRef Name='Buyer_SpendPoolOwner'/><Value Type='User'>" + loginUser + "</Value></Eq></Where></Query>";
$().SPServices({
operation : "GetListItems",
async : false,
listName : spendPoolListName,
CAMLQuery : query,
completefunc : function (xData, Status) {
$(xData.responseXML).SPFilterNode("z:row").each(function (i) {
var title = $(this).attr('ows_Title');
arrayID[i] = title;
});
}
});
var viewFields = '<ViewFields><FieldRef Name="ID" /><FieldRef Name="Title" /><FieldRef Name="Status" /><FieldRef Name="SourcingPlan" /><FieldRef Name="S_SiteBuyer1_UpManager_ClusterLe0" /></ViewFields>';
$().SPServices({
operation : "GetListItems",
async : false,
listName : "SourcingPlan",
CAMLViewFields : viewFields,
completefunc : function (xData, Status) {
var resXML = $(xData.responseXML);
appendSourcingPlans(resXML);
}
});
});
$(document).on('#srcingTimingID', function () {
var io = $(this).val().length ? 1 : 0;
$(this).next('.icon_clear').stop().fadeTo(300, io);
}).on('click', '.icon_clear', function () {
$(this).delay(300).fadeTo(300, 0).prev('input').val('');
});
function appendSourcingPlans(resXML) {
var strSourcePlan = "";
var temp = true;
// debugger
$(resXML).SPFilterNode("z:row").each(function () {
var splID = $(this).attr("ows_ID");
var ind = $.inArray(splID, arrayID);
if (ind > -1) {
temp = false;
var sourcePlan = $(this).attr("ows_SourcingPlan");
if (strSourcePlan.indexOf(sourcePlan) == -1) {
//var status = $(this).attr("ows_Status");
if ($(this).attr("ows_Title") != null) {
var status = $(this).attr("ows_Title");
var planStatus = status; //$(this).attr('ows_LinkTitle');
if (status == null || typeof status === 'undefined')
status = '';
} else {
var status = '';
var planStatus = '';
}
var estimatedCost = $(this).attr('ows_Total_Estimated_Cost');
var date = "";
if (estimatedCost < 5000000) {
date = $(this).attr('ows_S_SiteBuyer1_UpManager_ClusterLe0');
} else if (estimatedCost >= 5000000 && estimatedCost < 10000000) {
date = $(this).attr('ows_S_CapitalPurchasesPGM_Date');
} else {
date = $(this).attr('ows_S_CapitalPurchasesAD_Date');
}
if (date == null ||typeof date === 'undefined') {
date = '';
} else {
date = reformDate(date);
}
if (planStatus == "Pending" || planStatus == "") {
date = "";
//debugger
if (planStatus == "") {
planStatus = 'Not yet sent for approval';
}
}
strSourcePlan += sourcePlan + "~";
sourceTable += '<tr><td vAlign="top"><input type="radio" name="dynradio" id="btnRadio" onclick="javascript:getPools("' + splID + '")"; /></td><td>' + sourcePlan + '</td><td>' + planStatus + '</td><td>' + date + '</td>';
sourceTable += '</tr>';
}
}
});
if (temp) {
sourceTable += "<tr><td class='ms-vb2' colspan='4'>No tasks are assigned.</td></tr>";
}
sourceTable += '</table>';
$("#mySrcPlanID").html(sourceTable);
//sort source plan table
$("#tblSourcePlan").tablesorter();
}
function getPools(id) {
lstItemsId = id;
getData(id);
}
function getData(title) {
var poolTable = "";
var query = "<Query><Where><And><Eq><FieldRef Name='Title'/><Value Type='Text'>" + title + "</Value></Eq><Eq><FieldRef Name='Buyer_SpendPoolOwner'/><Value Type='User'>" + loginUser + "</Value></Eq></And></Where></Query>";
$().SPServices({
operation : "GetListItems",
async : false,
listName : spendPoolListName,
CAMLQuery : query,
completefunc : function (xDa, Status) {
var itemsCount = $(xDa.responseXML).SPFilterNode("rs:data").attr("ItemCount");
if (itemsCount > 0) {
$(xDa.responseXML).SPFilterNode("z:row").each(function (i) {
var spendingPool = $(this).attr("ows_SpendingPool");
if (spendingPool == "" || spendingPool == 'undefined' || spendingPool == null)
spendingPool = "";
var materialCode = $(this).attr("ows_MaterialCode");
if (materialCode == "" || materialCode == 'undefined' || materialCode == null)
materialCode = "";
var buyerSpendPoolOwner = $(this).attr("ows_Buyer_SpendPoolOwner");
if (buyerSpendPoolOwner == "" || buyerSpendPoolOwner == 'undefined' || buyerSpendPoolOwner == null)
buyerSpendPoolOwner = "";
else
buyerSpendPoolOwner = buyerSpendPoolOwner.split(";#")[1];
var estimatedSpend = "$" + $(this).attr("ows_EstimatedSpend").split(".")[0];
if (estimatedSpend == "" || estimatedSpend == 'undefined' || estimatedSpend == null)
estimatedSpend = "";
var status = $(this).attr("ows_Status");
if (status == "" || status == 'undefined' || status == null)
status = "";
var curID = $(this).attr("ows_ID");
var supplier = $(this).attr("ows_Supplier");
if (supplier == "" || supplier == 'undefined' || supplier == null)
supplier = "";
var purchasingProcess = $(this).attr("ows_PurchasingProcess");
if (purchasingProcess == "" || purchasingProcess == 'undefined' || purchasingProcess == null)
purchasingProcess = "";
var specAvailableDate = $(this).attr("ows_SpecificationAvailableDate");
if (specAvailableDate == "" || specAvailableDate == 'undefined' || specAvailableDate == null)
specAvailableDate = "";
else
specAvailableDate = reformDate(specAvailableDate);
var comments = $(this).attr("ows_Notes");
if (comments == "" || comments == 'undefined' || comments == null)
comments = "";
var sourceTime = $(this).attr("ows_SourcingTiming");
if (sourceTime == "" || sourceTime == 'undefined' || sourceTime == null)
sourceTime = "";
poolTable += '<tr>';
poolTable += '<td class="ms-vb2" id="lblSpPool"><label id="lblSpPool' + i + '">' + spendingPool + '</label></td>';
poolTable += '<td class="ms-vb2" id=""><label id="lblmaterialCode' + i + '">' + materialCode + '</label></td>';
poolTable += '<td class="ms-vb2"><label id="lblbspo' + i + '">' + buyerSpendPoolOwner + '</label></td>';
poolTable += '<td class="ms-vb2"><label id="lblestimated' + i + '">' + estimatedSpend + '</label></td>';
//poolTable += '<td class="ms-vb2"><label id="lblSourceTime' + i + '">' + reformDate(sourceTime) + '</label></td>';
poolTable += '<td class="ms-vb2"><input type="text" id="txtSourcingTime' + i + '" value="' + reformDate(sourceTime) + '" style="display:none"/><label id="lblSourceTime' + i + '">' + reformDate(sourceTime) + '</label></td>';
poolTable += '<td class="ms-vb2">';
poolTable += buildSelectBox(status, i);
poolTable += '<label id="lblStatus' + i + '">' + status + '</label></td>';
poolTable += '<td class="ms-vb2"><input type="text" id="txtSupplier' + i + '" value="' + supplier + '" style="display:none"><label id="lblSupplier' + i + '">' + supplier + '</label></td>';
poolTable += '<td class="ms-vb2">' + buildPurpose(purchasingProcess, i) + '<label id="lblPurProcess' + i + '">' + purchasingProcess + '</label></td>';
poolTable += '<td class="ms-vb2"><input type="text" id="txtSpecAvaDate' + i + '" value="' + specAvailableDate + '" style="display:none"/><label id="lblSpecAvaDate' + i + '">' + specAvailableDate + '</label></td>';
poolTable += '<td class="ms-vb2"><textarea rows=3 cols=10 id="txtComments' + i + '" style="display:none">' + comments + '</textarea><label id="lblComments' + i + '">' + comments + '</label></td>';
poolTable += '<td valign="top"><img alt="Edit" id="editID' + i + '" src="/_layouts/images/edititem.gif" border="0" onclick="goEdit(' + i + ');" alt="" /></td>';
poolTable += '<td valign="top"><img style="display:none;width:25px;" alt="Update" src="http://teamspace.pg.com/sites/sourcingplanmanager/capitalsrc/images/system-software-update.png" border="0" id="btnUpdate' + i + '" onclick="updateItem("' + curID + '",' + i + ')" value="Update"><img style="display:none;width:24px;" alt="Cancel" src="http://teamspace.pg.com/sites/sourcingplanmanager/capitalsrc/images/Cancel-icon.png" border="0" id="btnCancel' + i + '" onclick="goEdit(' + i + ');" value="Cancel"></td>';
poolTable += '<td class="ms-vb2" valign="top"><a href="http://teamspace.pg.com/sites/sourcingplanmanager/capitalsrc/Lists/SourcingPlanItems/EditSourcingPlanItems.aspx?ID=' + curID + '&Source=http://teamspace.pg.com/sites/sourcingplanmanager/capitalsrc/Site%20Pages/MyTasks.aspx">Edit</a></td></tr>'; // Added 6/18/13 by chinna
});
}
}
});
var cols = "";
cols += '<tr>';
cols += '<th>Spending Pool</th>';
cols += '<th>Material Code</th>';
cols += '<th>Buyer_SpendPoolOwner</th>';
cols += '<th>Estimated Spend</th>';
cols += '<th>Sourcing Timing</th>';
cols += '<th>Status</th>';
cols += '<th>Supplier</th>';
cols += '<th>Purchasing process</th>';
cols += '<th>Spec available date</th>';
cols += '<th>Comments</th>';
cols += '<th colspan="3"> </th>';
cols += '</tr>';
var filtercols = '<tr>';
filtercols += '<td> </td>';
filtercols += '<td> </td>';
filtercols += '<td> </td>';
filtercols += '<td> </td>';
filtercols += '<td><input type="text" id="srcingTimingID" onkeyup="clearSrcingFilter(event)" onchange="filterSrcingTime();" readonly/></td>';
filtercols += '<td><select id="filterStatusId" onchange="filterStatus();"><option>All</option><option>Create</option><option>In Process</option><option>Completed</option><option>Awarded<option>Cancelled</option></select></td>';
filtercols += '<td> </td>';
filtercols += '<td> </td>';
filtercols += '<td> </td>';
filtercols += '<td> </td>';
filtercols += '<td colspan="3"> </td>';
filtercols += '</tr>';
if (poolTable == "")
poolTable = "<tr><td>No records found.</td></tr>";
else
poolTable = filtercols+poolTable ;
poolTable = "<table id='tblSpendPool' width='100%' cellspacing='0' cellpadding='8' class='tablesorter'><thead>" + cols + "</thead>" + poolTable + "</table>";
$("#mySrcpoolID").html(poolTable);
$("#tblSpendPool").tablesorter();
if($("#srcingTimingID"))
$("#srcingTimingID").datepicker();
}
function buildSelectBox(status, num) {
var formOptions = "";
switch (status) {
case "Create":
formOptions += '<select id="selStatus' + num + '" style="display:none"><option selected="selected">Create</option><option>In Process</option><option>Completed</option><option>Awarded<option>Cancelled</option></select>';
break;
case "In Process":
formOptions += '<select id="selStatus' + num + '" style="display:none"><option>Create</option><option selected="selected">In Process</option><option>Completed</option><option>Awarded<option>Cancelled</option></select>';
break;
case "Completed":
formOptions += '<select id="selStatus' + num + '" style="display:none"><option>Create</option><option>In Process</option><option selected="selected">Completed</option><option>Awarded<option>Cancelled</option></select>';
break;
case "Awarded":
formOptions += '<select id="selStatus' + num + '" style="display:none"><option>Create</option><option>In Process</option><option>Completed</option><option selected="selected">Awarded</option><option>Cancelled</option></select>';
break;
case "Cancelled":
formOptions += '<select id="selStatus' + num + '" style="display:none"><option>Create</option><option>In Process</option><option>Completed</option><option>Awarded</option><option selected="selected">Cancelled</option></select>';
break;
}
return formOptions;
}
//for the process
function buildPurpose(strVal, num) {
var formOptions = "";
switch (strVal) {
case "Competitive Inquiry":
formOptions += '<select id="selPurProcess' + num + '" style="display:none"><option selected="selected">Competitive Inquiry</option><option>Negotiation</option><option>Price List</option></select>';
break;
case "Negotiation":
formOptions += '<select id="selPurProcess' + num + '" style="display:none"><option>Competitive Inquiry</option><option selected="selected">Negotiation</option><option>Price List</option></select>';
break;
case "Price List":
formOptions += '<select id="selPurProcess' + num + '" style="display:none"><option>Competitive Inquiry</option><option>Negotiation</option><option selected="selected">Price List</option></select>';
break;
}
return formOptions;
}
/// updating selected item
function updateItem(idOfItem,num) {
debugger
var status = $("#selStatus" + num + "").val(); //.val();
var supplier = $("#txtSupplier" + num + "").val();
var purProcess = $("#selPurProcess" + num + "").val();
var SpecAvaDate = $("#txtSpecAvaDate" + num + "").val();
var comments = $("#txtComments" + num + "").val();
var sourceTime = $("#txtSourcingTime" + num + "").val();
sourceTime = formDate(sourceTime);
SpecAvaDate = formDate(SpecAvaDate);
$().SPServices({
operation : "UpdateListItems",
listName : spendPoolListName,
ID : idOfItem,
valuepairs : [["Notes", comments], ["Status", status], ["Supplier", supplier], ["PurchasingProcess", purProcess], ["SpecificationAvailableDate", SpecAvaDate], ["SourcingTiming",sourceTime]],
completefunc : function (xData, Status) {
if (Status)
afterUpdate(idOfItem, num);
}
});
}
function afterUpdate(idOfItem, num) {
$().SPServices({
operation : "GetListItems", //Method name
async : false,
//webURL : webUrl,//pass webUrl dynamically
listName : spendPoolListName, // List Name
//CAMLQueryOptions : "<QueryOptions><IncludeAttachmentUrls>TRUE</IncludeAttachmentUrls></QueryOptions>",
//CAMLViewFields : "<ViewFields><FieldRef Name='Title' /></ViewFields>",
CAMLQuery : '<Query><Where><Eq><FieldRef Name="ID" /><Value Type="Counter">' + idOfItem + '</Value></Eq></Where></Query>',
//CAMLRowLimit : 1,
completefunc : function (xData, Status) {
//alert(xData.responseText);
if (xData.status == 200) {
$(xData.responseXML).SPFilterNode("z:row").each(function () {
// debugger;
if ($(this).attr("ows_Status") != null)
var SPstatus = $(this).attr("ows_Status");
else
var SPstatus = "";
if ($(this).attr("ows_Supplier") != null)
var supplier = $(this).attr("ows_Supplier");
else
var supplier = "";
if ($(this).attr("ows_PurchasingProcess") != null)
var purProcess = $(this).attr("ows_PurchasingProcess");
else
var purProcess = "";
if ($(this).attr("ows_SpecificationAvailableDate") != null) {
var SpecAvaDate = $(this).attr("ows_SpecificationAvailableDate");
SpecAvaDate = reformDate(SpecAvaDate);
} else
var SpecAvaDate = "";
if ($(this).attr("ows_Notes") != null)
var comments = $(this).attr("ows_Notes");
else
var comments = "";
if ($(this).attr("ows_SourcingTiming") != null){
var srcTime = $(this).attr("ows_SourcingTiming");
srcTime = reformDate(srcTime);
}
else
var srcTime = "";
updatelbls("selStatus", "lblStatus", SPstatus, num);
updatelbls("txtSourcingTime", "lblSourceTime", srcTime , num);
updatelbls("txtSupplier", "lblSupplier", supplier, num);
updatelbls("selPurProcess", "lblPurProcess", purProcess, num);
updatelbls("txtSpecAvaDate", "lblSpecAvaDate", SpecAvaDate, num);
updatelbls("txtComments", "lblComments", comments, num);
$('#editID' + num + '').show();
$('#btnUpdate' + num + '').hide();
$('#btnCancel' + num + '').hide();
});
}
//else {
// alert(xData.status);
//}
}
});
}
function updatelbls(id1, id2, val, num) {
//debugger;
$("#" + id1 + num + "").hide(function () {
$("#" + id2 + num + "").show(function () {
$(this).text(val);
});
});
}
function goEdit(num) {
//debugger;
$('#editID' + num + '').hide();
$('#btnUpdate' + num + '').show();
$('#btnCancel' + num + '').show(); //added on 18/6/13 by chinna
var spID = "txtSupplier" + num;
if ($("#" + spID + "").is(':visible')) {
$("#selStatus" + num + "").hide();
$("#txtSourcingTime" + num + "").hide();
$("#txtSupplier" + num + "").hide();
$("#selPurProcess" + num + "").hide();
$("#txtSpecAvaDate" + num + "").hide();
$("#txtComments" + num + "").hide();
$("#lblStatus" + num + "").show();
$("#lblSourceTime" + num + "").show();
$("#lblPurProcess" + num + "").show();
$("#lblSupplier" + num + "").show();
$("#lblComments" + num + "").show();
$("#lblSpecAvaDate" + num + "").show();
$("#btnUpdate" + num + "").attr('disabled', true);
$('#btnUpdate' + num + '').hide();
$('#btnCancel' + num + '').hide();
$('#editID' + num + '').show();
} else {
$('#btnUpdate' + num + '').show(); //added on 18/6/13 by chinna
$("#selStatus" + num + "").show();
$("#txtSupplier" + num + "").show();
$("#txtSourcingTime" + num + "").show();
$("#selPurProcess" + num + "").show();
$("#txtSpecAvaDate" + num + "").show();
$("#txtComments" + num + "").show();
$("#lblStatus" + num + "").hide();
$("#lblSourceTime" + num + "").hide();
$("#lblPurProcess" + num + "").hide();
$("#lblSupplier" + num + "").hide();
$("#lblComments" + num + "").hide();
$("#lblSpecAvaDate" + num + "").hide();
$("#btnUpdate" + num + "").attr('disabled', false);
}
$("#txtSpecAvaDate" + num + "").datepicker();
$("#txtSourcingTime" + num + "").datepicker();
}
function formDate(date) {
var dt = date.split("/");
var newDate = dt[2] + "-" + dt[0] + "-" + dt[1] + " T00:00:00Z";
return newDate;
}
function reformDate(date) {
if (date != "") {
var curdate = date.split(" ")[0];
curdate = curdate.split("-");
curdate = curdate[1] + "/" + curdate[2] + "/" + curdate[0];
return curdate
} else {
return date;
}
}
function filterSrcingTime()
{
var selSrcTime = $("#srcingTimingID").val();
searchTable("lblSourceTime",selSrcTime)
}
function filterStatus()
{
var selStatus = $("#filterStatusId").val();
if(selStatus == "All")
getPools(lstItemsId);
else
searchTable("lblStatus",selStatus)
}
function searchTable(id,inputVal)
{
var table = $('#tblSpendPool');
table.find('tr').each(function(index, row)
{
var allCells = $(row).find('td').find('label[id*='+id+']');
if(allCells.length > 0)
{
var found = false;
allCells.each(function(index, td)
{
var regExp = new RegExp(inputVal, 'i');
if(regExp.test($(this).text()))
{
found = true;
return false;
}
});
if(found == true)$(row).show();else $(row).hide();
}
});
}
function clearSrcingFilter(e) {
var key = e.keyCode || e.which;
if (key == 27)
getPools(lstItemsId);
}