SHARE
TWEET

TEST Add Resource

a guest Jul 22nd, 2019 91 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var taskID = fsi.getPageParameters('ET_Tasks');
  2. var reAssignButton = fsi.getById('button-reassign');
  3. var resourcesList = fsi.getById('listview-resources');
  4. var disciplineCombo = fsi.getById('combo-discipline');
  5. var teamSEQ = [];
  6. var resources = [];
  7. var disciplines = [];
  8. var filter = {};
  9. var myDiscipline = '';
  10. var selectedResources = [];
  11. var selectedResources2 = [];
  12. var taskSEQ;
  13. var timeRecordSEQ;
  14. var myResourceSEQ;
  15. var resourceSEQ;
  16. var counter = 0;
  17. var fsiGoUserId=fsi.getUserId();
  18. var resSEQ;
  19. var teamResource=[];
  20. var enableConfirmButton=false;
  21. var resourceName;
  22.  
  23.  
  24.  
  25. // Create a new record in ET_TaskAdditonalResource
  26. function createAssign(resourceSEQ, callBack, index) {
  27. index++;
  28. var newTask = {
  29. ResourceSEQ: resourceSEQ,
  30. TimeRecordSEQ: timeRecordSEQ,
  31. TaskSEQ: taskSEQ,
  32. Status: 'Pendingtest',
  33. FK_Task: taskID,
  34. AssignedFrom: myResourceSEQ,
  35. ResourceAddedDate: fsi.dateUTC(),
  36. ResourceName:resourceName
  37.  
  38. };
  39. fsi.dataObject.create('ET_TaskAdditonalResource', newTask, function() {
  40. callBack(index);
  41. });
  42. }
  43.  
  44.  
  45.  
  46. // Call createAssign or takes user to TaskActivities page
  47. function assignTask(i) {
  48. if (selectedResources.length > i) {
  49. createAssign(selectedResources[i], assignTask, i);
  50. } else {
  51. fsi.changePage('636783891803641815'); // Redirect on same page
  52. }
  53. }
  54.  
  55.  
  56.  
  57. // Show confirmation to user if they want to add the resource to task
  58. function reAssign() {
  59. if (fsi.$('#button-reassign').hasClass('buttonDisabled')) {
  60. fsi.alert("Please select the resource you would like to add.");
  61. } else {
  62. fsi.confirm("Are you sure you want to add this resource to this task?", function() {
  63. reAssignButton.disable();
  64. assignTask(0);
  65. }, function() {}, {
  66. confirm: 'Yes',
  67. cancel: 'No'
  68. });
  69. }
  70. }
  71.  
  72.  
  73.  
  74. // Remove resource
  75. function removeRes(resSEQ) {
  76. for (var i = 0; i < selectedResources.length; i++) {
  77. if (selectedResources[i] == resSEQ) {
  78. selectedResources.splice(i, 1);
  79. break;
  80. }
  81. }
  82. }
  83.  
  84.  
  85.  
  86. // Show list item selected when user select it and enable the ad resource button
  87. function selectResource(event) {
  88. var listElement = event.self;
  89. var item = fsi.$(listElement).closest('.list-item');
  90. var row = item.find('div[data-rowid]')[0];
  91. var resGuid = fsi.$(row).attr('data-rowid');
  92. resourceSEQ = item.find('.column-RES_SEQ').text();
  93. resourceName =item.find('.column-Name').text();
  94.  
  95.  
  96.  
  97. if (fsi.$(listElement).closest('.list-item').hasClass('selectedItem')) {
  98. fsi.$(listElement).closest('.list-item').removeClass('selectedItem');
  99. removeRes(resourceSEQ);
  100.  
  101. } else {
  102. if (resGuid) {
  103. fsi.$(listElement).closest('.list-item').addClass('selectedItem');
  104. selectedResources.push(resourceSEQ);
  105.  
  106.  
  107.  
  108. }
  109. }
  110.  
  111.  
  112.  
  113. if (selectedResources.length > 0) {
  114. fsi.$('#button-reassign').removeClass('buttonDisabled').addClass('buttonEnabled');
  115. } else {
  116. fsi.$('#button-reassign').removeClass('buttonEnabled').addClass('buttonDisabled');
  117. }
  118. }
  119.  
  120.  
  121.  
  122. // Add all the resources to list
  123. function updateListCount() {
  124. var count = 0;
  125. var listResources = [];
  126. fsi.$("#listview-resources .list-item").each(function() {
  127. var self = fsi.$(this);
  128. var goId = self.find(".column-GoID").text();
  129. var discipline = self.find(".column-ResourceDiscipline").text();
  130. if (listResources.indexOf(goId) === -1 && goId != fsi.getUserId().toString()) {
  131. listResources.push(goId);
  132. count++;
  133. }
  134. });
  135. fsi.$('#listview-resources .ui-li-count').text(count);
  136. }
  137.  
  138.  
  139.  
  140. // Add disiplines to combo
  141. function setDisciplines() {
  142. if (disciplines.length > 0) {
  143. fsi.$("#combo-discipline").empty();
  144. fsi.$("#combo-discipline").append(fsi.$("<option/>", {
  145. value: '',
  146. text: '- Please select a Discipline --'
  147. }));
  148. for (var i = 0; i < disciplines.length; ++i) {
  149. var disc = disciplines[i];
  150. fsi.$("#combo-discipline").append(fsi.$("<option/>", {
  151. value: disc,
  152. text: disc
  153. }));
  154. fsi.$("#combo-discipline").selectmenu("refresh");
  155. }
  156. }
  157. updateListCount();
  158. }
  159.  
  160.  
  161.  
  162. // Remove duplicate from disciples before adding to combo
  163. function removeDuplicates() {
  164. resources = [];
  165. disciplines = [];
  166. fsi.$("#listview-resources .list-item").each(function() {
  167. var self = fsi.$(this);
  168. var goId = self.find(".column-GOID").text();
  169. var discipline = self.find(".column-PrimaryDiscipline").text();
  170. if (goId == fsi.getUserId().toString()) {
  171. fsi.$(this).remove();
  172. counter = counter - 1;
  173. }
  174.  
  175.  
  176.  
  177. if (resources.indexOf(goId) === -1) {
  178. resources.push(goId);
  179. if (disciplines.indexOf(discipline) === -1 && goId != fsi.getUserId().toString()) {
  180. disciplines.push(discipline);
  181. }
  182. } else {
  183. fsi.$(this).remove();
  184. }
  185. });
  186.  
  187.  
  188.  
  189. setDisciplines();
  190. }
  191.  
  192.  
  193.  
  194. // Remove user which is logged into the device from list
  195. function removeUser() {
  196.     var resources = [];
  197. fsi.$("#listview-resources .list-item").each(function() {
  198. var self = fsi.$(this);
  199. var goId = self.find(".column-GOID").text();
  200. var discipline = self.find(".column-PrimaryDiscipline").text();
  201. if (goId == fsi.getUserId().toString()) {
  202. fsi.$(this).remove();
  203. }
  204.  
  205.  
  206.  
  207. if (resources.indexOf(goId) === -1) {
  208. resources.push(goId);
  209. } else {
  210. fsi.$(this).remove();
  211. }
  212.  
  213.  
  214.  
  215. });
  216. }
  217.  
  218.  
  219.  
  220. // Set discipline Filter
  221. function disciplineSelected() {
  222. myDiscipline = disciplineCombo.value();
  223. if (!myDiscipline) {
  224. filter.PrimaryDiscipline = disciplines;
  225. resourcesList.filter(filter, function() {
  226. removeUser();
  227.  
  228.  
  229.  
  230. });
  231. } else {
  232. filter.PrimaryDiscipline = [myDiscipline];
  233. resourcesList.filter(filter, function() {
  234. removeUser();
  235.  
  236. });
  237. }
  238. }
  239.  
  240.  
  241.  
  242. function buildlistview(){
  243. fsi.dataObject.read("ET_TeamResources",{GOID:fsiGoUserId},function(resource){
  244. if(resource.length>0){
  245. resSEQ= resource[0].RES_SEQ;
  246. fsi.dataObject.read("ET_ResourceTeamLink",{RES_SEQ:resSEQ},
  247. function(resource){
  248. fsi.pause();
  249. var team=[];
  250. for (var i=0;i<resource.length;i++){
  251. team.push(resource[i].TeamID);
  252. }
  253. fsi.dataObject.read("ET_ResourceTeamLink",
  254. {
  255. TeamID:team
  256. },
  257. function(resourceInTeam){
  258. if(resourceInTeam.length>0){
  259. for (var i=0;i<resourceInTeam.length;i++){
  260. teamResource.push(resourceInTeam[i].RES_SEQ);
  261. }
  262. teamResource=fsi._.uniq(teamResource);
  263. fsi.getById('listview-resources').filter({RES_SEQ: teamResource},function(){
  264. fsi.pause();
  265. fsi.$("#listview-resources .list-item").each(function () {
  266. fsi.pause();
  267. var self = fsi.$(this);
  268. var row = self.find('div[data-rowid]')[0];
  269. var guid = fsi.$(row).attr('data-rowid');
  270. var resSeq= self.find('.column-RES_SEQ')[0].innerHTML.trim();
  271. var onSiteVisitClass=' onSiteVisit';
  272. var percentageVisit=' percentageVisit';
  273. var teamSelctionAction= '<div class="teamSelectionAction">';
  274. teamSelctionAction=teamSelctionAction+'</div>';
  275. fsi.$(self).find('.listview-body').css({"width": "calc(100% - 100px)", "display": "inline-block"});
  276. fsi.$(self).append(teamSelctionAction);
  277. counter = counter + 1;
  278. });
  279.  
  280. removeDuplicates();
  281. fsi.$('#listview-resources .ui-li-count').text(counter);
  282.  
  283. if(enableConfirmButton){
  284. fsi.getById('button-ConfirmTeamSelection').enable();
  285. }
  286. fsi.getById('listview-resources').show();
  287. });
  288. }
  289. else{
  290. fsi.alert('Failed to load resource details, Please report to help desk');
  291. }
  292. },{});
  293. },{});
  294.  
  295.  
  296.  
  297. }});
  298. }
  299. // Sets header color and taskID. Disbales and enables buttons
  300. function onLoad() {
  301. // checkResources();
  302. buildlistview();
  303. fsi.$('#button-reassign').addClass('buttonDisabled');
  304. fsi.$('#button-cancel').addClass('rejectEnabled');
  305.  
  306.  
  307.  
  308. fsi.dataObject.read('ET_Tasks', {
  309. SystemID: taskID
  310. }, function(data) {
  311. if (data.length > 0) {
  312. taskSEQ = data[0].TaskSEQ;
  313. timeRecordSEQ = data[0].TimeRecordSEQ;
  314. fsi.taskID = data[0].TaskID;
  315. fsi.taskSEQ= data[0].TaskSEQ;
  316.             
  317.             if(fsi.taskIDSetting=='TaskSEQ'){
  318. fsi.$('[data-control-id=label-TaskID] h3').text('Task: ' + fsi.taskSEQ + '');
  319. }else{
  320. fsi.$('[data-control-id=label-TaskID] h3').text('Task: ' + fsi.taskID + '');
  321. }
  322. }
  323. }, function() {
  324. fsi.alert('Failed to read ET_Tasks');
  325. });
  326.  
  327.  
  328.  
  329. fsi.dataObject.read('ET_TeamResources', {
  330. GOID: fsi.getUserId()
  331. }, function(data) {
  332. if (data.length > 0) {
  333. myResourceSEQ = data[0].RES_SEQ;
  334. }
  335. });
  336.  
  337.  
  338.  
  339. // to make the top part of form blue
  340. var topColor = fsi.$('[data-control-id="label-ReAssignTask"]').offset().top;
  341. var newTopColor = Math.round(topColor);
  342. var style = "#1f497d " + newTopColor + "px";
  343. fsi.$('#form-636783891803641815').css('background', 'linear-gradient(' + style + ', #e0e2e5 0%)');
  344. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top