Merged in jonathanquispe/processmaker (pull request #1459)

web entry - update last observations, and add post in submit
This commit is contained in:
Julio Cesar Laura Avendaño
2015-02-18 17:03:44 -04:00
7 changed files with 242 additions and 57 deletions

View File

@@ -192,7 +192,7 @@ def buildPmdynaform(homeDir, targetDir, mode)
template += s
end
htmlTemplates=["cases_Step_Pmdynaform.html","cases_Step_Pmdynaform_Preview.html","cases_Step_Pmdynaform_View.html"]
htmlTemplates=["cases_Step_Pmdynaform.html","cases_Step_Pmdynaform_Preview.html","cases_Step_Pmdynaform_View.html","WebEntry_Pmdynaform.html"]
htmlTemplates.each do |htmlTemplate|
FileUtils.cp("#{Dir.pwd}/workflow/engine/templates/cases/#{htmlTemplate}", "#{pmdynaformDir}/build/#{htmlTemplate}")

View File

@@ -17,8 +17,9 @@ class pmDynaform
public $items = array();
public $data = array();
public $variables = array();
public $arrayFieldRequired = array();
public function __construct($dyn_uid, $app_data)
public function __construct($dyn_uid, $app_data = array())
{
$this->dyn_uid = $dyn_uid;
$this->app_data = $app_data;
@@ -28,8 +29,15 @@ class pmDynaform
$dynContent = G::json_decode($this->record["DYN_CONTENT"]);
if (isset($dynContent->items)) {
$this->items = $dynContent->items[0]->items;
for($i=0; $i<count($this->items); $i++){
for($j=0; $j<count($this->items[$i]); $j++){
if($this->items[$i][$j]->required == 1){
array_push($this->arrayFieldRequired, $this->items[$i][$j]->name);
}
}
}
}
if(!empty($app_data)){
//data
$cases = new \ProcessMaker\BusinessModel\Cases();
$this->data = $cases->getCaseVariables($app_data["APPLICATION"]);
@@ -61,7 +69,7 @@ class pmDynaform
while ($ds->next()) {
$row = $ds->getRow();
//options
$rows2 = json_decode($row["VAR_ACCEPTED_VALUES"]);
$rows2 = G::json_decode($row["VAR_ACCEPTED_VALUES"]);
$n = count($rows2);
for ($i = 0; $i < $n; $i++) {
$rows2[$i] = array($rows2[$i]->keyValue, $rows2[$i]->value);
@@ -80,6 +88,8 @@ class pmDynaform
}
}
}
public function getDynaform()
{
if ($this->record != null) {
@@ -238,7 +248,34 @@ class pmDynaform
$file = str_replace("{PRJ_UID}", $this->app_data["PROCESS"], $file);
$file = str_replace("{STEP_MODE}", $step_mode, $file);
$file = str_replace("{WORKSPACE}", $this->app_data["SYS_SYS"], $file);
$file = str_replace("{credentials}", json_encode($clientToken), $file);
$file = str_replace("{PORT}", $_SERVER["SERVER_PORT"] , $file);
$file = str_replace("{credentials}", G::json_encode($clientToken), $file);
echo $file;
exit();
}
public function printWebEntry($filename)
{
ob_clean();
$a = $this->clientToken();
$clientToken = array(
"accessToken" => $a["access_token"],
"expiresIn" => $a["expires_in"],
"tokenType" => $a["token_type"],
"scope" => $a["scope"],
"refreshToken" => $a["refresh_token"],
"clientId" => $a["client_id"],
"clientSecret" => $a["client_secret"]
);
$file = file_get_contents(PATH_HOME . 'public_html/lib/pmdynaform/build/WebEntry_Pmdynaform.html');
$file = str_replace("{JSON_DATA}", $this->record["DYN_CONTENT"], $file);
$file = str_replace("{DYN_UID}", $this->dyn_uid, $file);
$file = str_replace("{PRJ_UID}",$this->record["PRO_UID"], $file);
$file = str_replace("{WORKSPACE}", SYS_SYS, $file);
$file = str_replace("{FILEPOST}", $filename, $file);
$file = str_replace("{PORT}", $_SERVER["SERVER_PORT"] , $file);
$file = str_replace("{credentials}", G::json_encode($clientToken), $file);
$file = str_replace("{FIELDSREQUIRED}", G::json_encode($this->arrayFieldRequired), $file);
echo $file;
exit();
}

View File

@@ -49,7 +49,7 @@ $(window).load(function () {
submitRest: false
});
new PMDynaform.core.Proxy({
url: "http://" + window.project.keys.server + "/" + window.project.keys.apiName + "/" + window.project.keys.apiVersion + "/" + window.project.keys.workspace + "/cases/" + app_uid + "/variables",
url: "http://" + window.project.keys.server + ":"+port +"/" + window.project.keys.apiName + "/" + window.project.keys.apiVersion + "/" + window.project.keys.workspace + "/cases/" + app_uid + "/variables",
method: 'GET',
data: {},
keys: window.project.token,

View File

@@ -0,0 +1,86 @@
function dynaFormChanged(frm) {
for (var i1 = 0; i1 <= frm.elements.length - 1; i1++) {
if ((frm.elements[i1].type === "radio" || frm.elements[i1].type === "checkbox") && (frm.elements[i1].checked !== frm.elements[i1].defaultChecked)) {
return true;
}
if ((frm.elements[i1].type === "textarea" || frm.elements[i1].type === "text" || frm.elements[i1].type === "file") && (frm.elements[i1].value !== frm.elements[i1].defaultValue)) {
return true;
}
if (frm.elements[i1].tagName.toLowerCase() === "select") {
var selectDefaultValue = frm.elements[i1].value;
for (var i2 = 0; i2 <= frm.elements[i1].options.length - 1; i2++) {
if (frm.elements[i1].options[i2].defaultSelected) {
selectDefaultValue = frm.elements[i1].options[i2].value;
break;
}
}
if (frm.elements[i1].value !== selectDefaultValue) {
return true;
}
}
}
return false;
}
$(window).load(function () {
if ((navigator.userAgent.indexOf("MSIE") !== -1) || (navigator.userAgent.indexOf("Trident") !== -1)) {
document.body.innerHTML = "<div style='margin:15px'>Responsive Dynaforms are not supported in this browser.</div>";
return;
}
var data = jsondata;
window.project = new PMDynaform.core.Project({
data: data,
keys: {
server: location.host,
projectId: prj_uid,
workspace: workspace
},
token: credentials,
submitRest: false
});
var type = document.createElement("input");
type.type = "hidden";
type.name = "TYPE";
type.value = "ASSIGN_TASK";
var uid = document.createElement("input");
uid.type = "hidden";
uid.name = "UID";
uid.value = dyn_uid;
var position = document.createElement("input");
position.type = "hidden";
position.name = "POSITION";
position.value = "10000";
var action = document.createElement("input");
action.type = "hidden";
action.name = "ACTION";
action.value = "ASSIGN";
var dynaformname = document.createElement("input");
dynaformname.type = "hidden";
dynaformname.name = "__DynaformName__";
//dynaformname.value = __DynaformName__;
var appuid = document.createElement("input");
appuid.type = "hidden";
appuid.name = "APP_UID";
var arrayRequired = document.createElement("input");
arrayRequired.type = "hidden";
arrayRequired.name = "DynaformRequiredFields";
arrayRequired.value = fieldsRequired;
//appuid.value = app_uid;
var form = document.getElementsByTagName("form")[0];
form.action = filePost;
form.method = "post";
form.appendChild(type);
form.appendChild(uid);
form.appendChild(position);
form.appendChild(action);
form.appendChild(dynaformname);
form.appendChild(appuid);
form.appendChild(arrayRequired);
var dyn_forward = document.getElementById("dyn_forward");
dyn_forward.onclick = function () {
form.submit();
return false;
};
});

View File

@@ -395,8 +395,16 @@ class WebEntry
$fileContent .= "\$_SESSION[\"PROCESS\"] = \"" . $processUid . "\";\n";
$fileContent .= "\$_SESSION[\"CURRENT_DYN_UID\"] = \"" . $dynaFormUid . "\";\n";
$fileContent .= "\$G_PUBLISH = new Publisher();\n";
$fileContent .= "G::LoadClass('pmDynaform');\n";
$fileContent .= "\$a = new pmDynaform('".$arrayWebEntryData["DYN_UID"]."', array());\n";
$fileContent .= "if(\$a->isResponsive()){";
$fileContent .= "\$a->printWebEntry('".$fileName."Post.php');";
$fileContent .= "}else {";
$fileContent .= "\$G_PUBLISH->AddContent(\"dynaform\", \"xmlform\", \"" . $processUid . "/" . $dynaFormUid . "\", \"\", array(), \"" . $fileName . "Post.php\");\n";
$fileContent .= "G::RenderPage(\"publish\", \"blank\");";
$fileContent .= "}";
file_put_contents($pathDataPublicProcess . PATH_SEP . $fileName . ".php", $fileContent);

View File

@@ -0,0 +1,53 @@
<!DOCTYPE html>
<html>
<head>
<title>PMDynaform</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<link rel="stylesheet" href="/lib/pmdynaform/libs/bootstrap-3.1.1/css/bootstrap.min.css">
<link rel="stylesheet" href="/lib/pmdynaform/build/css/PMDynaform.css">
<script type="text/javascript" src="/lib/pmdynaform/libs/jquery/jquery-1.11.js"></script>
<script type="text/javascript" src="/lib/pmdynaform/libs/bootstrap-3.1.1/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/lib/pmdynaform/libs/underscore/underscore-1.6.js"></script>
<script type="text/javascript" src="/lib/pmdynaform/libs/backbone/backbone-min.js"></script>
<script type="text/javascript" src="/lib/pmdynaform/libs/restclient/restclient.js"></script>
</head>
<body>
<div id="container"></div>
###TEMPLATES###
<script type="text/javascript" src="/lib/pmdynaform/build/js/PMDynaform.js"></script>
<script type="text/javascript">
var jsondata = {JSON_DATA};
//var pm_run_outside_main_app = '{PM_RUN_OUTSIDE_MAIN_APP}';
var dyn_uid = '{DYN_UID}';
//var __DynaformName__ = '{DYNAFORMNAME}';
//var app_uid = '{APP_UID}';
var prj_uid = '{PRJ_UID}';
//var step_mode = '{STEP_MODE}';
var workspace = '{WORKSPACE}';
var credentials = {credentials};
var filePost = '{FILEPOST}';
var port = '{PORT}';
var fieldsRequired = {FIELDSREQUIRED};
</script>
<script type="text/javascript" src="/jscore/cases/core/cases_Step.js"></script>
<script type="text/javascript" src="/jscore/cases/core/webentry_pmdynaform.js"></script>
<table width="100%" align="center">
<tr class="userGroupTitle">
<!--td width="100%" align="center">{CASE} #: {APP_NUMBER}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{TITLE}: {APP_TITLE}</td-->
</tr>
</table>
<div style="width:100%;padding: 0px 10px 0px 10px">
<img src="/images/bulletButtonLeft.gif" style="float:left;">&nbsp;
<a id="dyn_backward" href="" style="float:left;">
</a>
<img src="/images/bulletButton.gif" style="float:right;">&nbsp;
<a id="dyn_forward" href="" style="float:right;font-size:12px;line-height:1;margin:0px 5px 1px 0px;">
Next Step
</a>
</div>
</body>
</html>

View File

@@ -27,6 +27,7 @@
var prj_uid = '{PRJ_UID}';
var step_mode = '{STEP_MODE}';
var workspace = '{WORKSPACE}';
var port = '{PORT}';
var credentials = {credentials};
</script>
<script type="text/javascript" src="/jscore/cases/core/cases_Step.js"></script>