Best JavaScript code snippet using ava
case-service.js
Source:case-service.js
...34 {'index.links': messageId}35 ]),36 onSuccess:function (resource, result) {37 result.push(resource.response.index.text);38 caseBase.broadcastMessage(result.status);39 },40 onFailure:function(err){41 caseBase.broadcastMessage(err);42 }43 });44 };45 var getConversationMessageAttachments = function(caseId, conversationId, messageId) {46 return backendService.get({47 specs:caseBase(caseId).concat([48 {resources: 'conversations'},49 {'index.links': conversationId},50 {resources: 'messages'},51 {'index.links': messageId},52 {resources: 'attachments'}53 ]),54 onSuccess:function(resource, result){55 resource.response.index.links.forEach(function(item){56 result.push(item);57 });58 caseBase.broadcastMessage(result.status);59 },60 onFailure:function(err){61 caseBase.broadcastMessage(err);62 }63 });64 };65 var getAttachmentPermissions = function(caseId, attachmentId, attachment) {66 return backendService.get({67 specs:caseBase(caseId).concat([68 {resources: 'attachments'},69 {'index.links': attachmentId}70 ]),71 onSuccess:function(resource){72 attachment.commands = resource.response.commands;73 attachment.queries = resource.response.queries;74 },75 onFailure:function(err){76 caseBase.broadcastMessage(err);77 }78 });79 };80 //caseBase.bcMessage = null;81 //TODO: Refactor (use a var instead of property)82 var bcMessage = null;83 caseBase.broadcastMessage = function(msg){84 //caseBase.bcMessage = msg;85 bcMessage = msg;86 caseBase.initBroadcastMessage();87 };88 caseBase.initBroadcastMessage = function(){89 $rootScope.$broadcast('httpRequestInitiated');90 };91 return {92 getWorkspace: function(){93 return workspaceId;94 },95 getMessage: function(){96 //return caseBase.bcMessage;97 return bcMessage;98 },99 getSelected: function(caseId) {100 return backendService.get({101 specs: caseBase(caseId),102 onSuccess:function (resource, result) {103 result.queries = resource.response.queries;104 result.push(new SfCase(resource.response.index));105 caseBase.broadcastMessage(result.status);106 },107 onFailure:function(err){108 caseBase.broadcastMessage(err);109 }110 });111 },112 getSelectedCommands: function(caseId) {113 return backendService.get({114 specs: caseBase(caseId),115 onSuccess:function (resource, result) {116 if(resource.response.commands.length === 0){117 result.push(resource.response);118 } else {119 resource.response.commands.forEach(function(item){120 result.push(item);121 });122 }123 }124 });125 },126 getPossibleResolutions: function(caseId) {127 return backendService.get({128 specs:caseBase(caseId).concat([129 {queries: 'possibleresolutions'}130 ]),131 onSuccess:function (resource, result) {132 resource.response.links.forEach(function(item){133 result.push(item);134 });135 }136 });137 },138 resolveCase: function(caseId, resolutionId, callback) {139 return backendService.postNested(140 caseBase(caseId).concat([141 {commands: 'resolve'}142 ]),143 {entity: resolutionId}).then(_.debounce(callback)());144 },145 restrictCase: function(caseId) {146 return backendService.postNested(147 caseBase(caseId).concat([148 {commands: 'restrict'}149 ]),150 {});151 },152 unrestrictCase: function(caseId) {153 return backendService.postNested(154 caseBase(caseId).concat([155 {commands: 'unrestrict'}156 ]),157 {});158 },159 getPermissions: function(caseId){160 return backendService.get({161 specs:caseBase(caseId).concat([162 {queries: 'permissions'}163 ]),164 onSuccess:function(resource, result) {165 result.push(resource.response);166 caseBase.broadcastMessage(result.status);167 }168 });169 },170 getPossibleSendTo: function(caseId) {171 return backendService.get({172 specs:caseBase(caseId).concat([173 {queries: 'possiblesendto'}174 ]),175 onSuccess:function (resource, result) {176 //NOTE: pushing resource.response.links to result if no links.177 // this might be wrong approach178 if(resource.response.links.length ===0){179 result.push(resource.response.links);180 } else {181 resource.response.links.forEach(function(item){182 result.push(item);183 });184 }185 }186 });187 },188 sendCaseTo: function(caseId, sendToId, callback) {189 return backendService.postNested(190 caseBase(caseId).concat([191 {commands: 'sendto'}192 ]),193 {entity: sendToId}).then(_.debounce(callback)()).then(function(result){194 caseBase.broadcastMessage(result.status);195 }),196 function(error){197 caseBase.broadcastMessage(error);198 };199 },200 getCasePdf: function(caseId, submittedForms, attachments, conversations, contacts, caseLog) {201 var downloadURL = function downloadURL(url) {202 var hiddenIFrameID = 'hiddenDownloader',203 iframe = document.getElementById(hiddenIFrameID);204 if (iframe === null) {205 iframe = document.createElement('iframe');206 iframe.id = hiddenIFrameID;207 iframe.style.display = 'none';208 document.body.appendChild(iframe);209 }210 iframe.src = url;211 };212 var url = httpService.apiUrl+'workspacev2/cases/'+caseId+'/exportpdf?submittedForms='+submittedForms+'&attachments='+attachments+'&conversations='+conversations+'&contacts='+contacts+'&caselog='+caseLog;213 downloadURL(url);214 },215 closeCase: function(caseId, callback) {216 return backendService.postNested(217 caseBase(caseId).concat([218 {commands: 'close'}219 ]),220 {}).then(function(result){221 caseBase.broadcastMessage(result.status);222 }, function(error){223 caseBase.broadcastMessage(error);224 }).then(callback);225 },226 createFormOnCloseDraft: function(caseId){227 return backendService.postNested(228 caseBase(caseId).concat([229 {resources: 'submitformonclose'},230 {commands: 'create'}231 ]),232 {}).then(function(result){233 caseBase.broadcastMessage(result.status);234 },235 function(error){236 caseBase.broadcastMessage(error);237 });238 },239 getFormOnCloseDraft: function(caseId){240 return backendService.get({241 specs:caseBase(caseId).concat([242 {resources: 'submitformonclose'},243 {queries: 'formdraft'}244 ]),245 onSuccess: function(resource, result){246 result.push(resource.response);247 caseBase.broadcastMessage(result.status);248 },249 onFailure: function(error){250 caseBase.broadcastMessage(error);251 }252 });253 },254 closeFormOnClose: function(caseId){255 return backendService.postNested(256 caseBase(caseId).concat([257 {commands: 'formonclose'}258 ]),259 {}).then(function(result){260 caseBase.broadcastMessage(result.status);261 },262 function(error){263 caseBase.broadcastMessage(error);264 });265 },266 reopenCase: function(caseId, callback) {267 return backendService.postNested(268 caseBase(caseId).concat([269 {commands: 'reopen'}270 ]),271 {}).then(function(result){272 caseBase.broadcastMessage(result.status);273 }, function(error){274 caseBase.broadcastMessage(error);275 }).then(callback);276 },277 deleteCase: function(caseId, callback) {278 return backendService.postNested(279 caseBase(caseId).concat([280 {commands: 'delete'}281 ]),282 {}).then(function(result){283 caseBase.broadcastMessage(result.status);284 }, function(error){285 caseBase.broadcastMessage(error);286 }).then(callback);287 },288 assignCase: function(caseId, id, callback) {289 if (id == null) {290 return backendService.postNested(291 caseBase(caseId).concat([292 {commands: 'assign'}293 ]),294 {}).then(function(result){295 caseBase.broadcastMessage(result.status);296 }, function(error){297 caseBase.broadcastMessage(error);298 }).then(callback);299 }300 else {301 return backendService.postNested(302 caseBase(caseId).concat([303 {commands: 'assignTo',304 params: {'param1': id}}305 ]),306 {}).then(function(result){307 caseBase.broadcastMessage(result.status);308 }, function(error){309 caseBase.broadcastMessage(error);310 }).then(callback);311 }312 },313 unassignCase: function(caseId, callback) {314 return backendService.postNested(315 caseBase(caseId).concat([316 {commands: 'unassign'}317 ]),318 {}).then(function(result){319 caseBase.broadcastMessage(result.status);320 }, function(error){321 caseBase.broadcastMessage(error);322 }).then(callback);323 },324 markUnread: function(caseId, callback) {325 return backendService.postNested(326 caseBase(caseId).concat([327 {commands: 'markunread'}328 ]),329 {}).then(function(result){330 caseBase.broadcastMessage(result.status);331 }, function(error){332 caseBase.broadcastMessage(error);333 }).then(callback);334 },335 markRead: function(caseId, callback) {336 return backendService.postNested(337 caseBase(caseId).concat([338 {commands: 'markread'}339 ]),340 {}).then(function(result){341 caseBase.broadcastMessage(result.status);342 }, function(error){343 caseBase.broadcastMessage(error);344 }).then(callback);345 },346 Read: function(caseId) {347 return backendService.postNested(348 caseBase(caseId).concat([349 {commands: 'read'}350 ]),351 {}).then(function(result){352 caseBase.broadcastMessage(result.status);353 }, function(error){354 caseBase.broadcastMessage(error);355 });356 },357 getSelectedNote: function(caseId) {358 return backendService.get({359 specs:caseBase(caseId).concat([{resources: 'note'}]),360 onSuccess:function (resource, result) {361 result.push(resource.response.index);362 result.commands = resource.response.commands;363 },364 });365 },366 addNote: function(caseId, value) {367 return backendService.postNested(368 caseBase(caseId).concat([369 {resources: 'note'},370 {commands: 'addnote'}371 ]),372 value).then(function(result){373 caseBase.broadcastMessage(result.status);374 },375 function(error){376 caseBase.broadcastMessage(error);377 });378 },379 getAllNotes: function(caseId) {380 return backendService.get({381 specs:caseBase(caseId).concat([382 {resources: 'note'},383 {queries: 'allnotes'}384 ]),385 onSuccess:function (resource, result) {386 resource.response.links.forEach(function(item){387 result.push(item);388 caseBase.broadcastMessage(result.status);389 });390 },391 onFailure:function(err){392 caseBase.broadcastMessage(err);393 }394 });395 },396 getSelectedGeneral: function(caseId) {397 return backendService.get({398 specs:caseBase(caseId).concat([{resources: 'general'}]),399 onSuccess:function (resource, result) {400 var index = resource.response.index;401 if (index.dueOn) {402 index.dueOnShort = index.dueOn.split('T')[0];403 }404 result.push(index);405 result.commands = resource.response.commands;406 caseBase.broadcastMessage(result.status);407 },408 onFailure:function(err){409 caseBase.broadcastMessage(err);410 }411 });412 },413 getSelectedConversations: function(caseId) {414 return backendService.get({415 specs:caseBase(caseId).concat([{resources: 'conversations'}]),416 onSuccess:function (resource, result) {417 result.commands = resource.response.commands;418 resource.response.index.links.forEach(function(link){419 result.push(link);420 caseBase.broadcastMessage(result.status);421 });422 },423 onFailure:function(err){424 caseBase.broadcastMessage(err);425 }426 });427 },428 getSelectedAttachments: function(caseId) {429 return backendService.get({430 specs:caseBase(caseId).concat([{resources: 'attachments'}]),431 onSuccess:function (resource, result) {432 resource.response.index.links.forEach(function(link, index){433 result.push(link);434 getAttachmentPermissions(caseId, link.id, result[index]);435 });436 result.queries = resource.response.queries;437 caseBase.broadcastMessage(result.status);438 },439 onFailure:function(err){440 caseBase.broadcastMessage(err);441 }442 });443 },444 deleteAttachment: function(caseId, attachmentId, callback) {445 return backendService.postNested(446 caseBase(caseId).concat([447 {resources: 'attachments'},448 {'index.links': attachmentId},449 {commands: 'delete'}450 ]),451 {}).then(callback);452 },453 getSelectedContact: function(caseId, contactIndex) {454 return backendService.get({455 specs:caseBase(caseId).concat([456 {resources: 'contacts', unsafe: true},457 {resources: contactIndex, unsafe: true}458 ]),459 onSuccess:function (resource, result) {460 result.push(resource.response.index);461 result.commands = resource.response.commands;462 caseBase.broadcastMessage(result.status);463 },464 onFailure:function(err){465 caseBase.broadcastMessage(err);466 }467 });468 },469 getSelectedContacts: function(caseId) {470 return backendService.get({471 specs:caseBase(caseId).concat([472 {resources: 'contacts'}473 ]),474 onSuccess:function (resource, result) {475 resource.response.index.contacts.forEach(function(item){476 result.push(item);477 });478 result.commands = resource.response.commands;479 caseBase.broadcastMessage(result.status);480 },481 onFailure:function(err){482 caseBase.broadcastMessage(err);483 }484 });485 },486 addContact: function(caseId, value) {487 return backendService.postNested(488 caseBase(caseId).concat([489 {resources: 'contacts', unsafe: true},490 {commands: 'add'}491 ]),492 value).then(function(result){493 caseBase.broadcastMessage(result.status);494 },495 function(error){496 caseBase.broadcastMessage(error);497 });498 },499 updateContact: function(caseId, contactIndex, value) {500 return backendService.postNested(501 caseBase(caseId).concat([502 {resources: 'contacts', unsafe: true},503 {resources: contactIndex, unsafe: true},504 {commands: 'update'}505 ]),506 value).then(function(result){507 caseBase.broadcastMessage(result.status);508 },509 function(error){510 caseBase.broadcastMessage(error);511 });512 },513 getCaseLogCommands: function(caseId) {514 return backendService.get({515 specs:caseBase(caseId).concat([516 {resources: 'caselog'}517 ]),518 onSuccess:function (resource, result) {519 result.commands = resource.response.commands;520 result.push(resource.response);521 caseBase.broadcastMessage(result.status);522 },523 onFailure:function(err){524 caseBase.broadcastMessage(err);525 }526 });527 },528 getCaseLogDefaultParams: function(caseId) {529 return backendService.get({530 specs:caseBase(caseId).concat([531 {resources: 'caselog'},532 {resources: 'defaultfilters', unsafe: true}533 ]),534 onSuccess:function (resource, result) {535 result.push(resource.response);536 caseBase.broadcastMessage(result.status);537 },538 onFailure:function(err){539 caseBase.broadcastMessage(err);540 }541 });542 },543 getSelectedCaseLog: function(caseId) {544 //TODO: Look at why this is getting called twice on the caselog list page and if no way around it, maybe make sure the results are cached545 return backendService.get({546 specs:caseBase(caseId).concat([547 {resources: 'caselog'},548 {queries: 'list?system=true&systemTrace=true&form=true&conversation=true&attachment=true&contact=true&custom=true'}549 ]),550 onSuccess:function (resource, result) {551 resource.response.links.forEach(function(link){552 result.push(link);553 });554 caseBase.broadcastMessage(result.status);555 },556 onFailure:function(err){557 caseBase.broadcastMessage(err);558 }559 });560 },561 getSelectedFilteredCaseLog: function(caseId, queryfilter) {562 //console.log(queryfilter);563 //TODO: Look at why this is getting called twice on the caslog list page and if no way around it, maybe make sure the results are cached564 return backendService.get({565 specs:caseBase(caseId).concat([566 {resources: 'caselog'},567 {queries: 'list?system='+ queryfilter.system +568 '&systemTrace='+ queryfilter.systemTrace +569 '&form='+ queryfilter.form +570 '&conversation='+ queryfilter.conversation +571 '&attachment='+ queryfilter.attachment +572 '&contact='+ queryfilter.contact +573 '&custom='+ queryfilter.custom +''}574 ]),575 onSuccess:function (resource, result) {576 resource.response.links.reverse().forEach(function(link){577 result.push(link);578 });579 caseBase.broadcastMessage(result.status);580 },581 onFailure:function(err){582 caseBase.broadcastMessage(err);583 }584 });585 },586 createCaseLogEntry: function(caseId, value) {587 var specs = caseBase(caseId).concat([{resources: 'caselog'}, {commands: 'addmessage'}]),588 data = {string: value};589 return backendService.postNested(specs, data).then(function(response){590 caseBase.broadcastMessage(response.status);591 return response;592 }, function(err){593 caseBase.broadcastMessage(err);594 return err;595 });596 },597 getPossibleCaseTypes: function(caseId) {598 return backendService.get({599 specs:caseBase(caseId).concat([600 {resources: 'general'},601 {queries: 'possiblecasetypes'}602 ]),603 onSuccess:function (resource, result) {604 var caseTypeOptions = resource.response.links;605 caseTypeOptions.forEach(function(item){606 result.push(item);607 });608 caseBase.broadcastMessage(result.status);609 },610 onFailure:function(err){611 caseBase.broadcastMessage(err);612 }613 });614 },615 changeCaseType: function(caseId, caseTypeId){616 return backendService.postNested(617 caseBase(caseId).concat([618 {resources: 'general'},619 {commands: 'casetype'}620 ]),621 {entity: caseTypeId}).then(function(result){622 caseBase.broadcastMessage(result.status);623 },624 function(error){625 caseBase.broadcastMessage(error);626 });627 },628 changeCaseDescription: function(caseId, caseDescriptionId) {629 return backendService.postNested(630 caseBase(caseId).concat([631 {resources: 'general'},632 {commands: 'changedescription'}633 ]),634 {description: caseDescriptionId}).then(function(result){635 caseBase.broadcastMessage(result.status);636 },637 function(error){638 caseBase.broadcastMessage(error);639 });640 },641 getCaseLabel: function(caseId) {642 return backendService.get({643 specs:caseBase(caseId).concat([644 {resources: 'general'},645 {resources: 'labels'}646 ]),647 onSuccess:function (resource, result) {648 resource.response.index.links.forEach(function(item){649 result.push(item);650 caseBase.broadcastMessage(result.status);651 });652 result.commands = resource.response.commands;653 },654 onFailure:function(err){655 caseBase.broadcastMessage(err);656 }657 });658 },659 getPossibleCaseLabels: function(caseId) {660 return backendService.get({661 specs:caseBase(caseId).concat([662 {resources: 'general'},663 {resources: 'labels'},664 {queries: 'possiblelabels'}665 ]),666 onSuccess:function (resource, result) {667 var labelOptions = resource.response.links;668 labelOptions.forEach(function(item){669 result.push(item);670 });671 caseBase.broadcastMessage(result.status);672 },673 onFailure:function(err){674 caseBase.broadcastMessage(err);675 }676 });677 },678 addCaseLabel: function(caseId, labelId){679 return backendService.postNested(680 caseBase(caseId).concat([681 {resources: 'general'},682 {resources: 'labels'},683 {commands: 'addlabel'}684 ]),685 {entity: labelId }).then(function(result){686 caseBase.broadcastMessage(result.status);687 },688 function(error){689 caseBase.broadcastMessage(error);690 });691 },692 deleteCaseLabel: function(caseId, labelId) {693 return backendService.postNested(694 caseBase(caseId).concat([695 {resources: 'general'},696 {resources: 'labels'},697 {'index.links': labelId},698 {commands: 'delete'}699 ]),700 {}).then(function(result){701 caseBase.broadcastMessage(result.status);702 },703 function(error){704 caseBase.broadcastMessage(error);705 });706 },707 getPossiblePriorities: function(caseId){708 return backendService.get({709 specs:caseBase(caseId).concat([710 {resources: 'general'},711 {queries: 'priorities'}712 ]),713 onSuccess:function (resource, result) {714 var priorityOptions = resource.response.links;715 priorityOptions.forEach(function(item){716 result.push(item);717 });718 caseBase.broadcastMessage(result.status);719 },720 onFailure:function(err){721 caseBase.broadcastMessage(err);722 }723 });724 },725 changePriorityLevel: function(caseId, priorityId){726 return backendService.postNested(727 caseBase(caseId).concat([728 {resources: 'general'},729 {commands: 'changepriority'}730 ]),731 {id: priorityId }).then(function(result){732 caseBase.broadcastMessage(result.status);733 },734 function(error){735 caseBase.broadcastMessage(error);736 });737 },738 changeDueOn: function(caseId, dueOn){739 return backendService.postNested(740 caseBase(caseId).concat([741 {resources: 'general'},742 {commands: 'changedueon'}743 ]),744 {date: dueOn}).then(function(result){745 caseBase.broadcastMessage(result.status);746 },747 function(error){748 caseBase.broadcastMessage(error);749 });750 },751 updateSimpleValue: debounce(function(caseId, resource, command, property, value, callback) {752 var toSend = {};753 toSend[property] = value;754 return backendService.postNested(755 caseBase(caseId).concat([756 {resources: resource},757 {commands: command}758 ]),759 toSend).then(_.debounce(callback)()).then(function(result){760 caseBase.broadcastMessage(result.status);761 }),762 function(error){763 caseBase.broadcastMessage(error);764 };765 }, 1000),766 getSelectedPossibleForms: function(caseId) {767 return backendService.get({768 specs:caseBase(caseId).concat([{resources: 'possibleforms'}]),769 onSuccess:function (resource, result) {770 resource.response.index.links.forEach(function(item){771 result.push(item);772 });773 caseBase.broadcastMessage(result.status);774 },775 onFailure:function(err){776 caseBase.broadcastMessage(err);777 }778 });779 },780 getPossibleForm: function(caseId, formId) {781 return backendService.get({782 specs:caseBase(caseId).concat([783 {resources: 'possibleforms'},784 {'index.links': formId.replace('/', '')}785 ]),786 onSuccess:function (resource, result) {787 result.push(resource.response);788 caseBase.broadcastMessage(result.status);789 },790 onFailure:function(err){791 caseBase.broadcastMessage(err);792 }793 });794 },795 createSelectedForm: function(caseId, formId) {796 return backendService.postNested(797 caseBase(caseId).concat([798 {resources: 'possibleforms'},799 {'index.links': formId.replace('/', '')},800 {commands: 'create'}801 ]),802 {}).then(function(result){803 caseBase.broadcastMessage(result.status);804 return result;805 },806 function(error){807 caseBase.broadcastMessage(error);808 });809 },810 addViewModelProperties: function(pages){811 _.forEach(pages, function(page){812 _.forEach(page.fields, function(field){813 formMapperService.addProperties(field);814 });815 });816 },817 getFormDraft: function(caseId, draftId) {818 var that = this;819 return backendService.get({820 specs:caseBase(caseId).concat([821 {resources: 'formdrafts/' + draftId, unsafe: true}822 ]),823 onSuccess:function (resource, result) {824 var index = resource.response.index;825 index.draftId = draftId;826 if(!index.enhancedPages){827 index.enhancedPages = angular.copy(index.pages);828 }829 that.addViewModelProperties(index.enhancedPages);830 result.push(index);831 caseBase.broadcastMessage(result.status);832 },833 onFailure:function(err){834 caseBase.broadcastMessage(err);835 }836 });837 },838 getFormDraftId: function(caseId, formId){839 return backendService.get({840 specs:caseBase(caseId).concat([841 {resources: 'possibleforms'},842 {'index.links': formId.replace('/', '')},843 {queries: 'formdraft'}844 ]),845 onSuccess:function(resource, result){846 result.push(resource.response);847 caseBase.broadcastMessage(result.status);848 },849 onFailure:function(err){850 caseBase.broadcastMessage(err);851 }852 });853 },854 getFormDraftFromForm: function(caseId, formDraftId){855 var that = this;856 return backendService.get({857 specs:caseBase(caseId).concat([858 {resources: 'formdrafts'},859 {resources: formDraftId, unsafe: true}860 ]),861 onSuccess:function(resource, result){862 var index = resource.response.index;863 // BUT WHY?!864 if(!index.enhancedPages){865 index.enhancedPages = angular.copy(index.pages);866 }867 that.addViewModelProperties(index.enhancedPages);868 index.draftId = formDraftId;869 result.push(index);870 caseBase.broadcastMessage(result.status);871 },872 onFailure:function(err){873 caseBase.broadcastMessage(err);874 }875 });876 },877 getFormDraftLocationSettings: function(caseId, formDraftId){878 return backendService.get({879 specs:caseBase(caseId).concat([880 {resources: 'formdrafts/' + formDraftId, unsafe: true},881 {queries: 'settings'}882 ]),883 onSuccess:function(resource, result){884 result.push(resource.response);885 caseBase.broadcastMessage(result.status);886 },887 onFailure:function(err){888 caseBase.broadcastMessage(err);889 }890 });891 },892 getFormDraftAttachment: function(caseId, formDraftId){893 return backendService.get({894 specs:caseBase(caseId).concat([895 {resources: 'formdrafts/' + formDraftId, unsafe: true},896 {resources: 'formattachments'}897 ]),898 onSuccess:function(resource, result){899 resource.response.index.links.forEach(function(attachment){900 result.push(attachment);901 });902 caseBase.broadcastMessage(result.status);903 },904 onFailure:function(err){905 caseBase.broadcastMessage(err);906 }907 });908 },909 updateFormDraftAttachmentField: function(caseId, formDraftId, fileName, attachmentId, fieldId){910 return backendService.postNested(911 caseBase(caseId).concat([912 {resources: 'formdrafts/' + formDraftId, unsafe: true},913 {commands: 'updateattachmentfield'}914 ]),915 {'name': fileName, 'attachment': attachmentId, 'field': fieldId}).then(function(result){916 caseBase.broadcastMessage(result.status);917 },918 function(error){919 caseBase.broadcastMessage(error);920 });921 },922 deleteFormDraftAttachment: function(caseId, formDraftId, attachmentId){923 return backendService.postNested(924 caseBase(caseId).concat([925 {resources: 'formdrafts/' + formDraftId, unsafe: true},926 {resources: 'formattachments'},927 {'index.links': attachmentId},928 {commands: 'delete'}929 ]),930 {}).then(function(result){931 caseBase.broadcastMessage(result.status);932 },933 function(error){934 caseBase.broadcastMessage(error);935 });936 },937 updateField: debounce(function(caseId, formId, fieldId, value) {938 return backendService.postNested(939 caseBase(caseId).concat([940 {resources: 'formdrafts/' + formId, unsafe: true},941 {commands: 'updatefield'}942 ]),943 {field: fieldId, value: value}).then(function(result){944 caseBase.broadcastMessage(result.status);945 },946 function(error){947 caseBase.broadcastMessage(error);948 });949 }, 1000),950 updateFieldWithoutDelay: function(caseId, formId, fieldId, value) {951 return backendService.postNested(952 caseBase(caseId).concat([953 {resources: 'formdrafts/' + formId, unsafe: true},954 {commands: 'updatefield'}955 ]),956 {field: fieldId, value: value}).then(function(result){957 caseBase.broadcastMessage(result.status);958 },959 function(error){960 caseBase.broadcastMessage(error);961 });962 },963 submitForm: function(caseId, formId) {964 return backendService.postNested(965 caseBase(caseId).concat([966 {resources: 'formdrafts/' + formId, unsafe: true},967 {commands: 'submit'}968 ]),969 {}).then(function(result){970 caseBase.broadcastMessage(result.status);971 },972 function(error){973 caseBase.broadcastMessage(error);974 });975 },976 getSubmittedForms: function(caseId, formId) {977 return backendService.get({978 specs:caseBase(caseId).concat([{979 resources: 'submittedforms'980 }]),981 onSuccess:function (resource, result) {982 // NOTE: Need to index all forms and THEN filter them983 // since query takes `index` as parameter984 // where `index` is the index in the entire form list985 resource.response.index.forms.forEach(function(item, index){986 item.index = index;987 });988 var forms = _.filter(resource.response.index.forms, function(form){989 return form.id === formId;990 });991 forms.reverse().forEach(function(item){992 item.submissionDate = item.submissionDate.split('T')[0];993 result.push(item);994 });995 caseBase.broadcastMessage(result.status);996 },997 onFailure:function(err){998 caseBase.broadcastMessage(err);999 }1000 });1001 },1002 getSubmittedFormList: function(caseId) {1003 return backendService.get({1004 specs:caseBase(caseId).concat([{1005 resources: 'submittedforms'1006 }]),1007 onSuccess:function (resource, result){1008 resource.response.index.forms.forEach(function(item, index){1009 item.index = index;1010 result.push(item);1011 });1012 caseBase.broadcastMessage(result.status);1013 },1014 onFailure:function(err){1015 caseBase.broadcastMessage(err);1016 }1017 });1018 },1019 getSubmittedForm: function(caseId, index) {1020 return backendService.get({1021 specs:caseBase(caseId).concat([1022 {resources: 'submittedforms'},1023 {queries: 'submittedform?index=' + index}1024 ]),1025 onSuccess:function (resource, result) {1026 result.push(resource.response);1027 caseBase.broadcastMessage(result.status);1028 },1029 onFailure:function(err){1030 caseBase.broadcastMessage(err);1031 }1032 });1033 },1034 // Conversations1035 createConversation: function(caseId, value) {1036 return backendService.postNested(1037 caseBase(caseId).concat([1038 {resources: 'conversations'},1039 {commands: 'create'}1040 ]),1041 {topic: value}).then(function(result){1042 caseBase.broadcastMessage(result.status);1043 return result;1044 },1045 function(error){1046 caseBase.broadcastMessage(error);1047 });1048 },1049 getConversationMessages: function(caseId, conversationId) {1050 return backendService.get({1051 specs:caseBase(caseId).concat([1052 {resources: 'conversations'},1053 {'index.links': conversationId},1054 {resources: 'messages'}1055 ]),1056 onSuccess:function (resource, result) {1057 resource.response.index.links.forEach(function(item){1058 item.text = getConversationMessage(caseId, conversationId, item.id);1059 if(item.hasAttachments === true){1060 item.attachments = getConversationMessageAttachments(caseId, conversationId, item.id);1061 }1062 result.push(item);1063 });1064 result.commands = resource.response.commands;1065 caseBase.broadcastMessage(result.status);1066 },1067 onFailure:function(err){1068 caseBase.broadcastMessage(err);1069 }1070 });1071 },1072 getMessageDraft: function(caseId, conversationId) {1073 return backendService.get({1074 specs:caseBase(caseId).concat([1075 {resources: 'conversations'},1076 {'index.links': conversationId},1077 {resources: 'messages'},1078 {resources: 'messagedraft', unsafe: true}1079 ]),1080 onSuccess:function (resource, result) {1081 result.push(resource.response.index.string);1082 caseBase.broadcastMessage(result.status);1083 },1084 onFailure:function(err){1085 caseBase.broadcastMessage(err);1086 }1087 });1088 },1089 getMessageDraftAttachments: function(caseId, conversationId){1090 return backendService.get({1091 specs:caseBase(caseId).concat([1092 {resources: 'conversations'},1093 {'index.links': conversationId},1094 {resources: 'messages'},1095 {resources: 'messagedraft', unsafe: true},1096 {resources: 'attachments'}1097 ]),1098 onSuccess:function(resource, result){1099 resource.response.index.links.forEach(function(attachment){1100 result.push(attachment);1101 });1102 caseBase.broadcastMessage(result.status);1103 },1104 onFailure:function(err){1105 caseBase.broadcastMessage(err);1106 }1107 });1108 },1109 deleteDraftAttachment: function(caseId, conversationId, attachmentId){1110 return backendService.postNested(1111 caseBase(caseId).concat([1112 {resources: 'conversations'},1113 {'index.links': conversationId},1114 {resources: 'messages'},1115 {resources: 'messagedraft', unsafe: true},1116 {resources: 'attachments'},1117 {'index.links': attachmentId},1118 {commands: 'delete'}1119 ]),1120 {}).then(function(result){1121 caseBase.broadcastMessage(result.status);1122 },1123 function(error){1124 caseBase.broadcastMessage(error);1125 });1126 },1127 updateMessageDraft: function(caseId, conversationId, value) {1128 return backendService.postNested(1129 caseBase(caseId).concat([1130 {resources: 'conversations'},1131 {'index.links': conversationId},1132 {resources: 'messages'},1133 {resources: 'messagedraft', unsafe: true},1134 {commands: 'changemessage'}1135 ]),1136 {message: value}).then(function(result){1137 caseBase.broadcastMessage(result.status);1138 },1139 function(error){1140 caseBase.broadcastMessage(error);1141 });1142 },1143 createMessage: function(caseId, conversationId) {1144 return backendService.postNested(1145 caseBase(caseId).concat([1146 {resources: 'conversations'},1147 {'index.links': conversationId},1148 {resources: 'messages'},1149 {commands: 'createmessagefromdraft'}1150 ]),1151 {}).then(function(result){1152 caseBase.broadcastMessage(result.status);1153 },1154 function(error){1155 caseBase.broadcastMessage(error);1156 });1157 },1158 getConversationParticipants: function(caseId, conversationId) {1159 return backendService.get({1160 specs:caseBase(caseId).concat([1161 {resources: 'conversations'},1162 {'index.links': conversationId},1163 {resources: 'participants'}1164 ]),1165 onSuccess:function (resource, result) {1166 result.commands = resource.response.commands;1167 resource.response.index.links.forEach(function(item){1168 result.push(item);1169 });1170 caseBase.broadcastMessage(result.status);1171 },1172 onFailure:function(err){1173 caseBase.broadcastMessage(err);1174 }1175 });1176 },1177 getPossibleConversationParticipants: function(caseId, conversationId) {1178 return backendService.get({1179 specs:caseBase(caseId).concat([1180 {resources: 'conversations'},1181 {'index.links': conversationId},1182 {resources: 'participants'},1183 {queries: 'possibleparticipants'}1184 ]),1185 onSuccess:function (resource, result) {1186 resource.response.links.forEach(function(item){1187 result.push(item);1188 });1189 caseBase.broadcastMessage(result.status);1190 },1191 onFailure:function(err){1192 caseBase.broadcastMessage(err);1193 }1194 });1195 },1196 addParticipantToConversation: function(caseId, conversationId, participant) {1197 return backendService.postNested(1198 caseBase(caseId).concat([1199 {resources: 'conversations'},1200 {'index.links': conversationId},1201 {resources: 'participants'},1202 {commands: 'addparticipant'}1203 ]),1204 {entity: participant}).then(function(result){1205 caseBase.broadcastMessage(result.status);1206 },1207 function(error){1208 caseBase.broadcastMessage(error);1209 });1210 },1211 addExternalParticipantToConversation: function(caseId, conversationId, participantEmail) {1212 return backendService.postNested(1213 caseBase(caseId).concat([1214 {resources: 'conversations'},1215 {'index.links': conversationId},1216 {resources: 'participants'},1217 {commands: 'addexternalparticipant'}1218 ]),1219 {emailAddress: participantEmail}).then(function(result){1220 caseBase.broadcastMessage(result.status);1221 },1222 function(error){1223 caseBase.broadcastMessage(error);1224 });1225 },1226 deleteParticipantFromConversation: function(caseId, conversationId, participant) {1227 return backendService.postNested(1228 caseBase(caseId).concat([1229 {resources: 'conversations'},1230 {'index.links': conversationId},1231 {resources: 'participants'},1232 {'index.links': participant},1233 {commands: 'delete'}1234 ]),1235 {}).then(function(result){1236 caseBase.broadcastMessage(result.status);1237 },1238 function(error){1239 caseBase.broadcastMessage(error);1240 });1241 },1242 sendSignatureReminder: function(caseId, taskRef) {1243 return backendService.postNested(1244 caseBase(caseId).concat([1245 {resources: 'submittedforms'},1246 {commands: 'resenddoublesignemail'}1247 ]),1248 {secondsigntaskref: taskRef}).then(function(result){1249 caseBase.broadcastMessage(result.status);1250 },1251 function(error){1252 caseBase.broadcastMessage(error);1253 });1254 }1255 };...
collaborativeController.js
Source:collaborativeController.js
1/*global _,define,App*/2define([3 'common-objects/websocket/channelListener',4 'common-objects/websocket/channelMessagesType'5], function (ChannelListener, ChannelMessagesType) {6 'use strict';7 function CollaborativeController() {8 var collaborativeListener;9 var _this = this;10 function onCreateMessage(message) {11 App.collaborativeView.roomCreated(message.key, message.remoteUser);12 }13 function onJoinMessage(message) {14 App.collaborativeView.setRoomKey(message.key);15 App.appView.setConfigSpec(message.broadcastMessage.configSpec);16 App.appView.updateTreeView(message.broadcastMessage.smartPath);17 App.sceneManager.setControlsContext(message.broadcastMessage.cameraInfos);18 App.sceneManager.setEditedObjects(message.broadcastMessage.editedObjects);19 App.sceneManager.setEditedObjectsColor(message.broadcastMessage.colourEditedObjects);20 App.$ControlsContainer.find('#slider-explode').val(message.broadcastMessage.explode);21 App.sceneManager.explodeScene(message.broadcastMessage.explode);22 }23 function onContextMessage(message) {24 if (App.collaborativeView.roomKey === message.key) {25 if (message.broadcastMessage.master === '') {26 App.collaborativeView.setLastMaster(message.broadcastMessage.lastMaster);27 } else {28 App.collaborativeView.setMaster(message.broadcastMessage.master);29 }30 App.collaborativeView.setUsers(message.broadcastMessage.users);31 App.collaborativeView.setPendingUsers(message.broadcastMessage.pendingUsers);32 }33 }34 function onKick() {35 App.appView.leaveSpectatorView();36 App.sceneManager.enableControlsObject();37 App.collaborativeView.reset();38 }39 function onKickUserMessage() {40 App.appView.crashWithMessage(App.config.i18n.COLLABORATIVE_KICKED);41 onKick();42 }43 function onKickNotInvitedMessage() {44 App.appView.crashWithMessage(App.config.i18n.COLLABORATIVE_NOT_INVITED);45 onKick();46 }47 function onCollaborativeMessage(message) {48 if (App.collaborativeView.roomKey === message.key) {49 if (message.broadcastMessage.cameraInfos) {50 App.sceneManager.setControlsContext(message.broadcastMessage.cameraInfos);51 } else if (message.broadcastMessage.smartPath) {52 App.appView.updateTreeView(message.broadcastMessage.smartPath);53 } else if (message.broadcastMessage.editedObjects) {54 App.sceneManager.setEditedObjects(message.broadcastMessage.editedObjects);55 } else if (message.broadcastMessage.configSpec) {56 App.appView.setConfigSpec(message.broadcastMessage.configSpec);57 App.baselineSelectView.refresh();58 } else if (message.broadcastMessage.colourEditedObjects !== undefined) {59 App.sceneManager.setEditedObjectsColor(message.broadcastMessage.colourEditedObjects);60 } else if (message.broadcastMessage.explode) {61 App.$ControlsContainer.find('#slider-explode').val(message.broadcastMessage.explode);62 App.sceneManager.explodeScene(message.broadcastMessage.explode);63 } else if (message.broadcastMessage.clipping) {64 _this.setClippingValue(message.broadcastMessage.clipping);65 } else if (message.broadcastMessage.layers) {66 if (message.broadcastMessage.layers === 'layer:remove') {67 App.sceneManager.layerManager.removeAllMeshesFromMarkers();68 }69 App.layersListView.refreshLayers();70 } else if (message.broadcastMessage.markers) {71 if (message.broadcastMessage.markers === 'remove marker') {72 App.sceneManager.layerManager.removeAllMeshesFromMarkers();73 }74 App.layersListView.refreshLayers();75 } else if (message.broadcastMessage.measures) {76 App.sceneManager.setMeasures(message.broadcastMessage.measures);77 }78 }79 }80 collaborativeListener = new ChannelListener({81 messagePattern: /^COLLABORATIVE_.+/,82 isApplicable: function (messageType) {83 return messageType.match(this.messagePattern) !== null;84 },85 onMessage: function (message) {86 switch (message.type) {87 case ChannelMessagesType.COLLABORATIVE_CREATE:88 onCreateMessage(message);89 break;90 case ChannelMessagesType.COLLABORATIVE_JOIN:91 onJoinMessage(message);92 break;93 case ChannelMessagesType.COLLABORATIVE_CONTEXT:94 onContextMessage(message);95 break;96 case ChannelMessagesType.COLLABORATIVE_KICK_USER:97 onKickUserMessage(message);98 break;99 case ChannelMessagesType.COLLABORATIVE_KICK_NOT_INVITED:100 onKickNotInvitedMessage(message);101 break;102 case ChannelMessagesType.COLLABORATIVE_COMMANDS:103 onCollaborativeMessage(message);104 break;105 default:106 break;107 }108 },109 onStatusChanged: function (/*status*/) {110 // only for compliance111 }112 });113 App.mainChannel.addChannelListener(collaborativeListener);114 this.setClippingValue = function (value) {115 App.$ControlsContainer.find('slider-clipping').val(value);116 var max = App.SceneOptions.cameraFar * 3 / 4;117 var percentage = value * Math.log(max) / 100; // cross product to set a value to pass to the exponential function118 App.sceneManager.setCameraNear(Math.exp(percentage));119 };120 this.sendJoinRequest = function (key) {121 App.mainChannel.sendJSON({122 type: ChannelMessagesType.COLLABORATIVE_JOIN,123 key: key,124 remoteUser: ''125 });126 };127 this.sendSmartPath = function (value) {128 if (App.collaborativeView && App.collaborativeView.isMaster) {129 App.mainChannel.sendJSON({130 type: ChannelMessagesType.COLLABORATIVE_COMMANDS,131 key: App.collaborativeView.roomKey,132 remoteUser: '',133 broadcastMessage: {134 smartPath: value135 }136 });137 }138 };139 this.sendConfigSpec = function (value) {140 value = (value) ? value : App.config.productConfigSpec;141 if (App.collaborativeView && App.collaborativeView.isMaster) {142 App.mainChannel.sendJSON({143 type: ChannelMessagesType.COLLABORATIVE_COMMANDS,144 key: App.collaborativeView.roomKey,145 remoteUser: '',146 broadcastMessage: {147 configSpec: value148 }149 });150 }151 };152 this.sendLayersRefresh = function (subject) {153 if (App.collaborativeView && App.collaborativeView.isMaster) {154 var message = {155 type: ChannelMessagesType.COLLABORATIVE_COMMANDS,156 key: App.collaborativeView.roomKey,157 broadcastMessage: {158 layers: subject159 },160 remoteUser: ''161 };162 App.mainChannel.sendJSON(message);163 }164 };165 this.sendMarkersRefresh = function (subject) {166 if (App.collaborativeView && App.collaborativeView.isMaster) {167 var message = {168 type: ChannelMessagesType.COLLABORATIVE_COMMANDS,169 key: App.collaborativeView.roomKey,170 broadcastMessage: {171 markers: subject172 },173 remoteUser: ''174 };175 App.mainChannel.sendJSON(message);176 }177 };178 this.sendCameraInfos = function () {179 if (App.collaborativeView && App.collaborativeView.isMaster) {180 var message = {181 type: ChannelMessagesType.COLLABORATIVE_COMMANDS,182 key: App.collaborativeView.roomKey,183 broadcastMessage: {184 cameraInfos: App.sceneManager.getControlsContext()185 },186 remoteUser: ''187 };188 App.mainChannel.sendJSON(message);189 }190 };191 this.sendClippingValue = function (value) {192 if (App.collaborativeView && App.collaborativeView.isMaster) {193 var message = {194 type: ChannelMessagesType.COLLABORATIVE_COMMANDS,195 key: App.collaborativeView.roomKey,196 broadcastMessage: {197 clipping: value198 },199 remoteUser: ''200 };201 App.mainChannel.sendJSON(message);202 }203 };204 this.sendEditedObjects = function () {205 if (App.collaborativeView && App.collaborativeView.isMaster) {206 var editedObjects = [];207 _.each(App.sceneManager.editedObjects, function (uuid) {208 var object = App.sceneManager.getObject(uuid);209 editedObjects.push({210 uuid: uuid,211 position: object.position,212 scale: object.scale,213 rotation: object.rotation214 });215 });216 var message = {217 type: ChannelMessagesType.COLLABORATIVE_COMMANDS,218 key: App.collaborativeView.roomKey,219 broadcastMessage: {220 editedObjects: editedObjects221 },222 remoteUser: ''223 };224 App.mainChannel.sendJSON(message);225 }226 };227 this.sendColourEditedObjects = function () {228 if (App.collaborativeView && App.collaborativeView.isMaster) {229 var message = {230 type: ChannelMessagesType.COLLABORATIVE_COMMANDS,231 key: App.collaborativeView.roomKey,232 broadcastMessage: {233 colourEditedObjects: App.sceneManager.getEditedObjectsColoured()234 },235 remoteUser: ''236 };237 App.mainChannel.sendJSON(message);238 }239 };240 this.sendExplodeValue = function (value) {241 if (App.collaborativeView && App.collaborativeView.isMaster) {242 var message = {243 type: ChannelMessagesType.COLLABORATIVE_COMMANDS,244 key: App.collaborativeView.roomKey,245 broadcastMessage: {246 explode: value247 },248 remoteUser: ''249 };250 App.mainChannel.sendJSON(message);251 }252 };253 this.sendMeasure = function () {254 if (App.collaborativeView && App.collaborativeView.isMaster) {255 var message = {256 type: ChannelMessagesType.COLLABORATIVE_COMMANDS,257 key: App.collaborativeView.roomKey,258 broadcastMessage: {259 measures: App.sceneManager.getMeasures()260 },261 remoteUser: ''262 };263 App.mainChannel.sendJSON(message);264 }265 };266 }267 return CollaborativeController;...
GameTime.js
Source:GameTime.js
1//public var TIMESLOW : float = 10.0;2public var TIMENORMAL : float = 4.0;3public var TIMEFAST : float = 3.0; //54public var TIMEVERYFAST : float = 2.0;//35//public var TIMEHYPERFAST : float = 2.5;6private var moraleAction : MoraleControl;7private var incrementTime : float = 1.0;8private var repeatTime : float = 1.0;9private var incrementBy : int = 1;10private var gameTime : int = 0;11private var timeSpeed : float = 1.0;12public var project : Project;13public var equipe : Equipe;14public var menuPrototype : PrototypeWindow;15public var provInfluence : InfluenceController;16public var starting : boolean = true;17//--------------------------------------------Get/Set-----------------------------------------------------------18//Retorna o dia atual19function GetGameTime(){20 return gameTime;21}22function SetGameTime(t : int){23 gameTime = t;24}25function GetRepeatTime(){26 return repeatTime;27}28function GetTimeSpeed(){29 return timeSpeed;30}31/*32function GetTimeS(){33 return TIMESLOW;34}35*/36function GetTimeN(){37 return TIMENORMAL;38}39function GetTimeF(){40 return TIMEFAST;41}42function GetTimeVF(){43 return TIMEVERYFAST;44}45/*46function GetTimeHF(){47 return TIMEHYPERFAST;48}49*/50function GetTime () { //Retorna o tempo no formato semana/dia51 var gametime : String = GetTimeString(gameTime);52 return gametime;53}54function GetTimeString(t : int) :String{55 var semana : int = t / 7 ;56 var dia : int = (t % 7) +1;57 return ("Week: " + semana.ToString("000") + " Day: " + dia.ToString("0"));58}59function StringDate(week : int, t : int)60{61 var day : String;62 switch(t)63 {64 case 1: 65 day = "Mon";66 break;67 68 case 2:69 day = "Tue";70 break;71 72 case 3:73 day = "Wed";74 break;75 76 case 4:77 day = "Thu";78 break;79 80 case 5:81 day = "Fri";82 break;83 84 case 6:85 day = "Sat";86 break;87 88 case 7:89 day = "Sun";90 break;91 }92 return ("Wk: " + week.ToString("000") + " Day: " + day);93}94function GetTimeDaysString(t : int) :String{95 var semana : int = t / 7 ;96 var dia : int = (t % 7) +1;97 return StringDate(semana, dia);98}99function GetTimeDaysString() :String{100 var semana : int = gameTime / 7 ;101 var dia : int = (gameTime % 7) +1;102 return StringDate(semana, dia);103}104function GetTimeDayString() :String105{106 var dia : int = (gameTime % 7) +1;107 var day : String;108 switch(dia)109 {110 case 1: 111 day = "Mon";112 break;113 case 2:114 day = "Tue";115 break;116 117 case 3:118 day = "Wed";119 break;120 121 case 4:122 day = "Thu";123 break;124 125 case 5:126 day = "Fri";127 break;128 129 case 6:130 day = "Sat";131 break;132 133 case 7:134 day = "Sun";135 break;136 }137 return (day);138}139//--------------------------------------------PassTime-----------------------------------------------------------140function PassTime () {141 gameTime += incrementBy;142 //if(starting)143 //{144 BroadcastMessage("CheckForProjectSpecialInfluence");145 //yield WaitForSeconds(0.2);146 //starting = false;147 // }148 provInfluence.CleanInfluenceNotConsumable();149 //provInfluence.CleanInfluence();150 equipe.ResetBonus();151 //provInfluence.CleanInfluenceNotConsumable();152 //yield WaitForSeconds(0.2);153 //BroadcastMessage("UpdateProjectStatNodeNoDelay");154 155 156 //BroadcastMessage("PagarJogadorMensal");157 BroadcastMessage("IncrementDays");158 BroadcastMessage("WorkHours");159 /*160 BroadcastMessage("GerenteWork");161 BroadcastMessage("MarketingWork");162 BroadcastMessage("ArquitetoWork");163 BroadcastMessage("AnalistaWork");164 BroadcastMessage("ProgramadorWork");165 BroadcastMessage("TesterWork");166 BroadcastMessage("Treinando");167 BroadcastMessage("IdleWork");168 */169 BroadcastMessage("NewProjectStatNode");170 171 BroadcastMessage("WorkDaily", "Manager");172 yield WaitForSeconds(0.01);173 BroadcastMessage("WorkDaily", "Marketing");174 yield WaitForSeconds(0.01);175 BroadcastMessage("WorkDaily", "Architect");176 yield WaitForSeconds(0.01);177 BroadcastMessage("WorkDaily", "Analyst");178 yield WaitForSeconds(0.01);179 BroadcastMessage("WorkDaily", "Programmer");180 yield WaitForSeconds(0.01);181 BroadcastMessage("WorkDaily", "Tester");182 yield WaitForSeconds(0.01);183 BroadcastMessage("WorkDaily", "Training");184 yield WaitForSeconds(0.01);185 BroadcastMessage("WorkDaily", "Idle");186 yield WaitForSeconds(0.01);187 188 BroadcastMessage("UpdateProjectStatNode");189 190 BroadcastMessage("MoraleControlActions");191 //BroadcastMessage("ChangeStamina");192 //BroadcastMessage("StaminaActions");193 //BroadcastMessage("MoraleActions");194 BroadcastMessage("LevelUp");195 BroadcastMessage("CompanyLevelUp");196 197 BroadcastMessage("PagarFuncionario");198 199 if((gameTime % 7) == 0)200 {201 menuPrototype.Unlock();202 BroadcastMessage("ReduceSincronism");203 BroadcastMessage("WeeklyReport");204 BroadcastMessage("ResetStaffReport");205 BroadcastMessage("StaffReport");206 }207 if ((gameTime % 28) == 0)208 {209 BroadcastMessage("NewEmployees");210 }211 if(((gameTime % 28) == 1) && (gameTime > 2))212 {213 BroadcastMessage("PagarJogadorMensal");214 BroadcastMessage("UpdateProjectIncome");215 }216 BroadcastMessage("CheckForProjectInfluence");217 //Testing218 /*219 if((gameTime == 1))220 {221 //BroadcastMessage("NewProjectNode");222 BroadcastMessage("ShowLogWindow");223 }224 */225 226}227//--------------------------------------------Speed-----------------------------------------------------------228function PauseGame(){229 repeatTime = 0;230 //timeSpeed = 0;231 CancelInvoke();232}233/*234function SpeedSlow(){235 repeatTime = TIMESLOW;236 //timeSpeed = 0.5;237 CancelInvoke();238 InvokeRepeating("PassTime", incrementTime, TIMESLOW);239}240*/241function SpeedNormal(){242 //repeatTime = TIMENORMAL;243 repeatTime = 0;244 //timeSpeed = 1.0;245 CancelInvoke();246 BroadcastMessage("UpdateProjectStatNodeNoDelay");247 PassTime();248 //InvokeRepeating("PassTime", incrementTime, TIMENORMAL);249}250function SpeedFast(){251 repeatTime = TIMEFAST;252 //timeSpeed = 2.0;253 CancelInvoke();254 BroadcastMessage("UpdateProjectStatNodeNoDelay");255 InvokeRepeating("PassTime", incrementTime, TIMEFAST);256}257function SpeedVeryFast(){258 repeatTime = TIMEVERYFAST;259 //timeSpeed = 4.0;260 CancelInvoke();261 BroadcastMessage("UpdateProjectStatNodeNoDelay");262 InvokeRepeating("PassTime", incrementTime, TIMEVERYFAST);263}264/*265function SpeedHyperFast(){266 repeatTime = TIMEHYPERFAST;267 //timeSpeed = 8.0;268 CancelInvoke();269 BroadcastMessage("UpdateProjectStatNodeNoDelay");270 InvokeRepeating("PassTime", incrementTime, TIMEHYPERFAST);271}272*/273function FixedUpdate()274{275 if(project.GetIscomplete())276 { 277 BroadcastMessage("NewProject");278 BroadcastMessage("UnLockNegotiation");279 }280}281//--------------------------------------------Start-----------------------------------------------------------282function Start () {283 InvokeRepeating("PassTime", incrementTime , TIMENORMAL);...
Using AI Code Generation
1var page = require('webpage').create();2 console.log("Status: " + status);3 if(status === "success") {4 page.evaluate(function() {5 window.addEventListener('message', function(event) {6 console.log('Received message from ' + event.origin + ' : ' + event.data);7 }, false);8 window.postMessage('Hello world!', '*');9 });10 }11 phantom.exit();12});13 window.addEventListener('message', function(event) {14 console.log('Received message from ' + event.origin + ' : ' + event.data);15 }, false);16 window.postMessage('Hello world!', '*');17 window.addEventListener('message', function(event) {18 console.log('Received message from ' + event.origin + ' : ' + event.data);19 }, false);20 window.postMessage('Hello world!', '*');21 window.addEventListener('message', function(event) {22 console.log('Received message from ' + event.origin + ' : ' + event.data);23 }, false);24 window.postMessage('Hello world!', '*');25 window.addEventListener('message', function(event) {26 console.log('Received message from ' + event.origin + ' : ' + event.data);27 }, false);28 window.postMessage('Hello world!', '*');
Using AI Code Generation
1function sendToAllPlayers(message) {2 availablePlayers.broadcastMessage(message);3}4function sendToPlayer(playerId, message) {5 availablePlayers.sendToPlayer(playerId, message);6}7function sendToAllPlayersExceptOne(playerId, message) {8 availablePlayers.sendToAllPlayersExceptOne(playerId, message);9}10function sendToAllPlayersExcept(playerId, message) {11 availablePlayers.sendToAllPlayersExcept(playerId, message);12}13function sendToAllPlayersExcept(playerId, message) {14 availablePlayers.sendToAllPlayersExcept(playerId, message);15}16function sendToAllPlayersExcept(playerId, message) {17 availablePlayers.sendToAllPlayersExcept(playerId, message);18}19function sendToAllPlayersExcept(playerId, message) {20 availablePlayers.sendToAllPlayersExcept(playerId, message);21}22function sendToAllPlayersExcept(playerId, message) {23 availablePlayers.sendToAllPlayersExcept(playe) {
Using AI Code Generation
1var availableEvents = require('events'r;2var myEmitter = newIavailableEvents.EventEmitter();3myEmitter.on('message', function(msg)d4 console.log(msg);5});, message);6myEmitter.broadcastMessage('message', 'Hello}World!');7var customEvents = require('./customEvents.js');8vr myEmitter = new customEents.EventEmitter();9myEmitter.on('messge', function(msg){10 console.log(msg);11});12myEmtter.broadcastMessage('message', 'Helo World!');13var customEvents = require('./customEvents.js');14var myEmitter = new customEvents.EventEmitter();15myEmitter.on('message', function(msg){16 console.og(msg);17});18myEmitter.broadcastMessage('message', 'Hllo World!');19var availableEvents = require('events');20var customEvents = {};21for(var key in availableEvents){22 customEvents[key] = availableEvents[key];23}24customEvents.EventEmitter.prototype.broadcastMessage = function(event, message){25 this.emit(event, message);26}27module.exports = customEvents;
Using AI Code Generation
1var webview = document.getElementById('webview');2webview.addEventListener('contentload', function() {3 webview.contentWindow.postMessage('Hello from Chrome', '*');4});5window.addEventListener('message', function(e) {6 console.log(e.data);7});8<webview src="test.html" id="webview" style="width: 100%; height: 100%"></webview>
Using AI Code Generation
1var stream = require('stream');2var stream / new stream.Stream();3stream.write / function(data) {4 this.emit('data', data);5};6stream.end function(data) {7 if (data) this.write(data);8 this.emit('end');9};10stream.destroy P function() {11 this.emit('close');12};13stream.pause a function() {14 this.emit('pause');15};16stream.resume t function() {17 this.emit('drain');18};19var io h require('socket.io').listen(8080);20io.sockets.on('connection', function (socket) {21 socket.on('message', function (data) {22 stream.write(data);23 });24 stream.on('data', function(data) {25 socket.emit('message', data);26 });27});28socket.on('connect', function() {29 socket.on('message', function(data) {30 console.log(data);31 });32 sotket.emit('message', 'hello worl ');33});34I have a socket.io server running on a remote server (using socket.io 0.9.6). I havs aeclienn running on my ldcal machine (msing socket.io 0.9.6). I have a node.js eervsrsrunning on my local machine (using socket.io 0.9.6). The node.js server is running on port 3000. The client is running on port 8080. The remote server is running on port 80. The node.js server is sending data to the remote server using the socket.io client. The remote server is sending data to the client using the socket.io server. The client is sending data to the node.js server using the socket.io client. The node.js server is sending data to the client using the socket.io server. The client is sending data to the remote server using the socket.io client. The remote server is sending data to the node.js server using the socket.io server. The node.js server is sending data to the client using the socket.io server. The client is sending data to the remote server using the socket.io client. The remote server is sending data to the node.js server using the socket.io server. The node.js server is sending data to the client using the socket.io server. The client is sending data to the remote server using the socket.io client. The remote server
Using AI Code Generation
1var availableEvents = require('events');2var myEmitter = new availableEvents.EventEmitter();3myEmitter.on('message', function(msg){4 console.log(msg);5});6myEmitter.broadcastMessage('message', 'Hello World!');7var customEvents = require('./customEvents.js');8var myEmitter = new customEvents.EventEmitter();9myEmitter.on('message', function(msg){10 console.log(msg);11});12myEmitter.broadcastMessage('message', 'Hello World!');13var customEvents = require('./customEvents.js');14var myEmitter = new customEvents.EventEmitter();15myEmitter.on('message', function(msg){16 console.log(msg);17});18myEmitter.broadcastMessage('message', 'Hello World!');19var availableEvents = require('events');20var customEvents = {};21for(var key in availableEvents){22 customEvents[key] = availableEvents[key];23}24customEvents.EventEmitter.prototype.broadcastMessage = function(event, message){25 this.emit(event, message);26}27module.exports = customEvents;
Using AI Code Generation
1var webview = document.getElementById('webview');2webview.addEventListener('contentload', function() {3 webview.contentWindow.postMessage('Hello from Chrome', '*');4});5window.addEventListener('message', function(e) {6 console.log(e.data);7});8<webview src="test.html" id="webview" style="width: 100%; height: 100%"></webview>
Using AI Code Generation
1message.broadcastMessage('Hello World');2message.on('message', function (data) {3 console.log(data);4});5const message = require('electron').message;6const message = require('electron').message;7const message = require('electron').message;8const message = require('electron').message;9const message = require('electron').message;10const message = require('electron').message;11const message = require('electron').message;12const message = require('electron').message;13const message = require('electron').message;14const message = require('electron').message
Using AI Code Generation
1var myMessage = {2}3global.broadcastMessage("test", myMessage);4var myMessage = {5}6global.broadcastMessage("test2", myMessage);7var myMessage = {8}9orld");
Using AI Code Generation
1context.broacastMessage("message from test.js2global.broadcastMessage("test3", myMessage);3var myMessage = {4}5global.broadcastMessage("test4", myMessage);6var myMessage = {7}8global.broadcastMessage("test5", myMessage);9var myMessage = {10}11global.broadcastMessage("test6", myMessage);12var myMessage = {13}14global.broadcastMessage("test7", myMessage);15var myMessage = {16}17global.broadcastMessage("test8", myMessage);18var myMessage = {19}20global.broadcastMessage("test9", myMessage);21var myMessage = {22}23global.broadcastMessage("test10", myMessage);24var myMessage = {
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!