diff --git a/gulliver/js/codemirror/addon/hint/php-hint.js b/gulliver/js/codemirror/addon/hint/php-hint.js index e0816709c..5d0f7582e 100644 --- a/gulliver/js/codemirror/addon/hint/php-hint.js +++ b/gulliver/js/codemirror/addon/hint/php-hint.js @@ -21,13 +21,19 @@ function scriptHint(editor, keywords, getToken, options) { // Find the token at the cursor var cur = editor.getCursor(), token = getToken(editor, cur), tprop = token; + var sToken = token.string.trim(); - if(token.string == "(") { + if ( sToken == "(") { token = tprop = getToken(editor, Pos(cur.line, tprop.start)); return {list: getCompletions(token.string, keywords, options), from: Pos(cur.line, token.start), to: Pos(cur.line, token.end + 1)}; } + if ( sToken == "=") { + return {list: getCompletions(token.string, keywords, options), + from: Pos(cur.line, token.start + 1), + to: Pos(cur.line, token.end)}; + } return {list: getCompletions(token.string, keywords, options), from: Pos(cur.line, token.start), to: Pos(cur.line, token.end)}; @@ -37,17 +43,60 @@ return scriptHint(editor, phpPMFunctions, function (e, cur) {return e.getTokenAt(cur);}, options); }; - var getCurrentTimeFunction = ("getCurrentTime($name,$time) getCurrentTime($name)").split(" "); - var PMFNewCaseImpersonateFunction = ("PMFNewCaseImpersonate($date)").split(" "); + var SPACE = " "; + + var formatDateFunction = ("formatDate($date,$format,$language) formatDate($date,$format)").split(SPACE); + var getCurrentDateFunction = ("getCurrentDate()").split(SPACE); + var getCurrentTimeFunction = ("getCurrentTime()").split(SPACE); + var literalDateFunction = ("literalDate($date,$Language) literalDate($date)").split(SPACE); + var capitalizeFunction = ("capitalize($textToConvert)").split(SPACE); + var lowerCaseFunction = ("lowerCase($textToConvert)").split(SPACE); + var upperCaseFunction = ("upperCase($textToConvert)").split(SPACE); + var userInfoFunction = ("userInfo($USER_ID)").split(SPACE); + var executeQueryFunction = ("executeQuery($sqlStatement,$DBConnectionUID) executeQuery($sqlStatement)").split(SPACE); + var orderGridFunction = ("orderGrid($gridName,$field,$criteria) orderGrid($gridName,$field)").split(SPACE); + var evaluateFunctionFunction = ("evaluateFunction($gridName,$Expression)").split(SPACE); + + var PMFTaskCaseFunction = ("PMFTaskCase($caseId)").split(SPACE); + var PMFTaskListFunction = ("PMFTaskList($userId)").split(SPACE); + var PMFUserListFunction = ("PMFUserList()").split(SPACE); + var PMFGroupListFunction = ("PMFGroupList()").split(SPACE); + var PMFRoleListFunction = ("PMFRoleList()").split(SPACE); + var PMFCaseListFunction = ("PMFCaseList($userId) PMFCaseList()").split(SPACE); + var PMFProcessListFunction = ("PMFProcessList()").split(SPACE); + var PMFSendVariablesFunction = ("PMFSendVariables($caseId,$variables)").split(SPACE); + var PMFDerivateCaseFunction = ("PMFDerivateCase($caseId,$delegation,$executeTriggersBeforeAssigment) PMFDerivateCase($caseId,$delegation)").split(SPACE); + var PMFNewCaseImpersonateFunction = ("PMFNewCaseImpersonate($processId,$userId,$variables)").split(SPACE); + var PMFNewCaseFunction = ("PMFNewCase($processId,$userId,$taskId,$variables)").split(SPACE); + var PMFPauseCaseFunction = ("PMFPauseCase($caseUid,$delIndex,$userUid,$unpauseDate) PMFPauseCase($caseUid,$delIndex,$userUid)").split(SPACE); + var PMFAssignUserToGroupFunction = ("PMFAssignUserToGroup($userId,$groupId)").split(SPACE); + var PMFCreateUserFunction = ("PMFCreateUser($userId,$password,$firstname,$lastname,$email,$role)").split(SPACE); + var PMFUpdateUserFunction = ("PMFUpdateUser($userUid,$userName,$firstName,$lastName,$email,$dueDate,$status,$role,$password)").split(SPACE); + var PMFInformationUserFunction = ("PMFInformationUser($userUid)").split(SPACE); + var generateCodeFunction = ("generateCode($size,$type)").split(SPACE); + var setCaseTrackerCodeFunction = ("setCaseTrackerCode($caseId,$code,$pin)").split(SPACE); + var jumpingFunction = ("jumping($caseId,$delegation)").split(SPACE); + var PMFRedirectToStepFunction = ("PMFRedirectToStep($caseId,$delegation,$stepType,$stepId)").split(SPACE); + var pauseCaseFunction = ("pauseCase($caseId,$delegation,$userId,$unpauseDate) pauseCase($caseId,$delegation,$userId)").split(SPACE); + var PMFSendMessageFunction = ("PMFSendMessage($caseId,$from,$to,$cc,$bcc,$subject,$template,$fields,$attachments) PMFSendMessage($caseId,$from,$to,$cc,$bcc,$subject,$template,$fields) PMFSendMessage($caseId,$from,$to,$cc,$bcc,$subject,$template)").split(SPACE); + var PMFgetLabelOptionFunction = ("PMFgetLabelOption($processId,$dynaformId,$fieldName,$optionId)").split(SPACE); + var PMFGenerateOutputDocumentFunction = ("PMFGenerateOutputDocument($outputID)").split(SPACE); + var PMFGetUserEmailAddressFunction = ("PMFGetUserEmailAddress($id,$APP_UID,$prefix) PMFGetUserEmailAddress($id,$APP_UID) PMFGetUserEmailAddress($id)").split(SPACE); + var PMFGetNextAssignedUserFunction = ("PMFGetNextAssignedUser($application,$task)").split(SPACE); + var PMFDeleteCaseFunction = ("PMFDeleteCase($caseId)").split(SPACE); + var PMFCancelCaseFunction = ("PMFCancelCase($caseUid,$delIndex,$userUid)").split(SPACE); + var PMFAddInputDocumentFunction = ("PMFAddInputDocument($inputDocumentUid,$appDocUid,$docVersion,$appDocType,$appDocComment,$inputDocumentAction,$caseUid,$delIndex,$taskUid,$userUid,$option,$file) PMFAddInputDocument($inputDocumentUid,$appDocUid,$docVersion,$appDocType,$appDocComment,$inputDocumentAction,$caseUid,$delIndex,$taskUid,$userUid,$option) PMFAddInputDocument($inputDocumentUid,$appDocUid,$docVersion,$appDocType,$appDocComment,$inputDocumentAction,$caseUid,$delIndex,$taskUid,$userUid)").split(SPACE); + var PMFAddCaseNoteFunction = ("PMFAddCaseNote($caseUid,$processUid,$taskUid,$userUid,$note,$sendMail)").split(SPACE); + var PMFGetCaseNotesFunction = ("PMFGetCaseNotes($applicationID,$type,$userUid) PMFGetCaseNotes($applicationID,$type) PMFGetCaseNotes($applicationID)").split(SPACE); var phpPMFunctions = ("formatDate getCurrentDate getCurrentTime literalDate capitalize lowerCase upperCase userInfo executeQuery orderGrid " + "evaluateFunction PMFTaskCase PMFTaskList PMFUserList PMFGroupList PMFRoleList PMFCaseList PMFProcessList PMFSendVariables PMFDerivateCase " + "PMFNewCaseImpersonate PMFNewCase PMFPauseCase PMFUnpauseCase PMFAssignUserToGroup PMFCreateUser PMFUpdateUser PMFInformationUser " + "generateCode setCaseTrackerCode jumping PMFRedirectToStep pauseCase PMFSendMessage PMFgetLabelOption PMFGenerateOutputDocument " + - "PMFGetUserEmailAddress PMFGetNextAssignedUser PMFDeleteCase PMFCancelCase PMFAddInputDocument PMFAddCaseNote PMFGetCaseNotes").split(" "); + "PMFGetUserEmailAddress PMFGetNextAssignedUser PMFDeleteCase PMFCancelCase PMFAddInputDocument PMFAddCaseNote PMFGetCaseNotes").split(SPACE); - var phpKeywords = ("break case catch continue debugger default delete do else false finally for function " + - "if in instanceof new null return switch throw true try typeof var void while with").split(" "); + var phpKeywords = ("break case catch continue default delete do else false for function " + + "if new return switch throw true try var void while").split(SPACE); function getCompletions(functionName, keywords, options) { @@ -65,14 +114,99 @@ } } - if (functionName == "getCurrentTime") { - forEach( getCurrentTimeFunction, yesAdd); + if (functionName == "formatDate") { + forEach( formatDateFunction, yesAdd); + } else if (functionName == "getCurrentDate") { + forEach( getCurrentDateFunction, yesAdd); + } else if (functionName == "getCurrentTime") { + forEach( getCurrentTimeFunction, yesAdd); + } else if (functionName == "literalDate") { + forEach( literalDateFunction, yesAdd); + } else if (functionName == "capitalize") { + forEach( capitalizeFunction, yesAdd); + } else if (functionName == "lowerCase") { + forEach( lowerCaseFunction, yesAdd); + } else if (functionName == "upperCase") { + forEach( upperCaseFunction, yesAdd); + } else if (functionName == "evaluateFunction") { + forEach( evaluateFunctionFunction, yesAdd); + } else if (functionName == "userInfo") { + forEach( userInfoFunction, yesAdd); + } else if (functionName == "executeQuery") { + forEach( executeQueryFunction, yesAdd); + } else if (functionName == "orderGrid") { + forEach( orderGridFunction, yesAdd); + } else if (functionName == "PMFTaskCase") { + forEach( PMFTaskCaseFunction, yesAdd); + } else if (functionName == "PMFTaskList") { + forEach( PMFTaskListFunction, yesAdd); + } else if (functionName == "PMFUserList") { + forEach( PMFUserListFunction, yesAdd); + } else if (functionName == "PMFGroupList") { + forEach( PMFGroupListFunction, yesAdd); + } else if (functionName == "PMFRoleList") { + forEach( PMFRoleListFunction, yesAdd); + } else if (functionName == "PMFCaseList") { + forEach( PMFCaseListFunction, yesAdd); + } else if (functionName == "PMFProcessList") { + forEach( PMFProcessListFunction, yesAdd); + } else if (functionName == "PMFSendVariables") { + forEach( PMFSendVariablesFunction, yesAdd); + } else if (functionName == "PMFNewCase") { + forEach( PMFNewCaseFunction, yesAdd); + } else if (functionName == "PMFPauseCase") { + forEach( PMFPauseCaseFunction, yesAdd); + } else if (functionName == "PMFUnpauseCase") { + forEach( PMFUnpauseCaseFunction, yesAdd); + } else if (functionName == "PMFAssignUserToGroup") { + forEach( PMFAssignUserToGroupFunction, yesAdd); + } else if (functionName == "PMFCreateUser") { + forEach( PMFCreateUserFunction, yesAdd); + } else if (functionName == "PMFUpdateUser") { + forEach( PMFUpdateUserFunction, yesAdd); + } else if (functionName == "PMFInformationUser") { + forEach( PMFInformationUserFunction, yesAdd); + } else if (functionName == "generateCode") { + forEach( generateCodeFunction, yesAdd); + } else if (functionName == "setCaseTrackerCode") { + forEach( setCaseTrackerCodeFunction, yesAdd); + } else if (functionName == "jumping") { + forEach( jumpingFunction, yesAdd); + } else if (functionName == "PMFRedirectToStep") { + forEach( PMFRedirectToStepFunction, yesAdd); + } else if (functionName == "pauseCase") { + forEach( pauseCaseFunction, yesAdd); + } else if (functionName == "PMFSendMessage") { + forEach( PMFSendMessageFunction, yesAdd); + } else if (functionName == "PMFgetLabelOption") { + forEach( PMFgetLabelOptionFunction, yesAdd); + } else if (functionName == "PMFGenerateOutputDocument") { + forEach( PMFGenerateOutputDocumentFunction, yesAdd); + } else if (functionName == "PMFGetUserEmailAddress") { + forEach( PMFGetUserEmailAddressFunction, yesAdd); + } else if (functionName == "PMFGetNextAssignedUser") { + forEach( PMFGetNextAssignedUserFunction, yesAdd); + } else if (functionName == "PMFDeleteCase") { + forEach( PMFDeleteCaseFunction, yesAdd); + } else if (functionName == "PMFCancelCase") { + forEach( PMFCancelCaseFunction, yesAdd); + } else if (functionName == "PMFAddInputDocument") { + forEach( PMFAddInputDocumentFunction, yesAdd); + } else if (functionName == "PMFAddCaseNote") { + forEach( PMFAddCaseNoteFunction, yesAdd); + } else if (functionName == "PMFGetCaseNotes") { + forEach( PMFGetCaseNotesFunction, yesAdd); } else if (functionName == "PMFNewCaseImpersonate") { - forEach( PMFNewCaseImpersonateFunction, yesAdd); + forEach( PMFNewCaseImpersonateFunction, yesAdd); + } else if (functionName.trim() == "") { + forEach (phpKeywords, yesAdd); + forEach (keywords, yesAdd); + } else if (functionName == "=") { + forEach (phpPMFunctions, yesAdd); } else { - for(i=0;i max) + max = list[i].length; + } + return max; + } + + function showHints(data) { + if (!data || !data.list.length) return; + var completions = data.list; + var maxWidth = getMaxAccordingList(data.list); + // When there is only one completion, use it directly. + if (!continued && options.completeSingle !== false && completions.length == 1) { + pickCompletion(cm, data, completions[0]); + return true; + } + + // Build the select widget + var hints = document.createElement("ul"), selectedHint = 0; + hints.className = "CodeMirror-hints"; + for (var i = 0; i < completions.length; ++i) { + var elt = hints.appendChild(document.createElement("li")), completion = completions[i]; + var className = "CodeMirror-hint" + (i ? "" : " CodeMirror-hint-active"); + if (completion.className != null) className = completion.className + " " + className; + elt.className = className; + if (completion.render) completion.render(elt, data, completion); + else elt.appendChild(document.createTextNode(getText(completion))); + elt.hintId = i; + } + var pos = cm.cursorCoords(options.alignWithWord !== false ? data.from : null); + var left = pos.left, top = pos.bottom, below = true; + hints.style.left = left + "px"; + hints.style.top = top + "px"; + hints.style.width = (maxWidth * 8) + "px"; + + document.body.appendChild(hints); + + // If we're at the edge of the screen, then we want the menu to appear on the left of the cursor. + var winW = window.innerWidth || Math.max(document.body.offsetWidth, document.documentElement.offsetWidth); + var winH = window.innerHeight || Math.max(document.body.offsetHeight, document.documentElement.offsetHeight); + var box = hints.getBoundingClientRect(); + var overlapX = box.right - winW, overlapY = box.bottom - winH; + if (overlapX > 0) { + if (box.right - box.left > winW) { + hints.style.width = (winW - 5) + "px"; + overlapX -= (box.right - box.left) - winW; + } + hints.style.left = (left = pos.left - overlapX) + "px"; + } + if (overlapY > 0) { + var height = box.bottom - box.top; + if (box.top - (pos.bottom - pos.top) - height > 0) { + overlapY = height + (pos.bottom - pos.top); + below = false; + } else if (height > winH) { + hints.style.height = (winH - 5) + "px"; + overlapY -= height - winH; + } + hints.style.top = (top = pos.bottom - overlapY) + "px"; + } + + function changeActive(i) { + i = Math.max(0, Math.min(i, completions.length - 1)); + if (selectedHint == i) return; + var node = hints.childNodes[selectedHint]; + node.className = node.className.replace(" CodeMirror-hint-active", ""); + node = hints.childNodes[selectedHint = i]; + node.className += " CodeMirror-hint-active"; + if (node.offsetTop < hints.scrollTop) + hints.scrollTop = node.offsetTop - 3; + else if (node.offsetTop + node.offsetHeight > hints.scrollTop + hints.clientHeight) + hints.scrollTop = node.offsetTop + node.offsetHeight - hints.clientHeight + 3; + } + + function screenAmount() { + return Math.floor(hints.clientHeight / hints.firstChild.offsetHeight) || 1; + } + + var ourMap = { + Up: function() {changeActive(selectedHint - 1);}, + Down: function() {changeActive(selectedHint + 1);}, + PageUp: function() {changeActive(selectedHint - screenAmount());}, + PageDown: function() {changeActive(selectedHint + screenAmount());}, + Home: function() {changeActive(0);}, + End: function() {changeActive(completions.length - 1);}, + Enter: pick, + Tab: pick, + Esc: close + }; + if (options.customKeys) for (var key in options.customKeys) if (options.customKeys.hasOwnProperty(key)) { + var val = options.customKeys[key]; + if (/^(Up|Down|Enter|Esc)$/.test(key)) val = ourMap[val]; + ourMap[key] = val; + } + + cm.addKeyMap(ourMap); + cm.on("cursorActivity", cursorActivity); + var closingOnBlur; + function onBlur(){ closingOnBlur = setTimeout(close, 100); }; + function onFocus(){ clearTimeout(closingOnBlur); }; + cm.on("blur", onBlur); + cm.on("focus", onFocus); + var startScroll = cm.getScrollInfo(); + function onScroll() { + var curScroll = cm.getScrollInfo(), editor = cm.getWrapperElement().getBoundingClientRect(); + var newTop = top + startScroll.top - curScroll.top, point = newTop; + if (!below) point += hints.offsetHeight; + if (point <= editor.top || point >= editor.bottom) return close(); + hints.style.top = newTop + "px"; + hints.style.left = (left + startScroll.left - curScroll.left) + "px"; + } + cm.on("scroll", onScroll); + CodeMirror.on(hints, "dblclick", function(e) { + var t = e.target || e.srcElement; + if (t.hintId != null) {selectedHint = t.hintId; pick();} + }); + CodeMirror.on(hints, "click", function(e) { + var t = e.target || e.srcElement; + if (t.hintId != null) changeActive(t.hintId); + }); + CodeMirror.on(hints, "mousedown", function() { + setTimeout(function(){cm.focus();}, 20); + }); + + var done = false, once; + function close() { + if (done) return; + done = true; + clearTimeout(once); + hints.parentNode.removeChild(hints); + cm.removeKeyMap(ourMap); + cm.off("cursorActivity", cursorActivity); + cm.off("blur", onBlur); + cm.off("focus", onFocus); + cm.off("scroll", onScroll); + } + function pick() { + pickCompletion(cm, data, completions[selectedHint]); + close(); + } + var once, lastPos = cm.getCursor(), lastLen = cm.getLine(lastPos.line).length; + function cursorActivity() { + clearTimeout(once); + + var pos = cm.getCursor(), line = cm.getLine(pos.line); + if (pos.line != lastPos.line || line.length - pos.ch != lastLen - lastPos.ch || + pos.ch < startCh || cm.somethingSelected() || + (pos.ch && closeOn.test(line.charAt(pos.ch - 1)))) + close(); + else + once = setTimeout(function(){close(); continued = true; startHinting();}, 70); + } + return true; + } + + return startHinting(); +};