Questions and discussion about using ProcessMaker: user interface, running cases & functionality
By azatrath
#796001
hi,

i want to ask something which i need to use .

there is task as like as gallery. we give a tablet to customer with task screen . they can see around 100 pictures and select what they want( there is multiple select). after that selected items will transfer to next task. i searched wikia but there is only one image that can used with only input .

is it possible with processmaker?
or can it be with plugin?
User avatar
By amosbatto
#796005
Upload all your images to the Public Files of a process.

Then create the following DynaForm:
SelectPicFormInDesigner.png
SelectPicFormInDesigner.png (43.48 KiB) Viewed 4631 times
This DynaForm has the following 6 fields:
    [*]The Image field with the ID "selectedImage" displays the image that user has selected. [*]The "Select Button" (ID: selectImageBtn) is used to display a panel of images where the user can select one. [*]The panel with the ID "imagesPanels", which is hidden by default, holds a table of images. [*]The hidden field with the ID "htmlTable" holds the contents of the table with images from the Public Files directory, which is set by a prior trigger. [*]A second hidden field with the ID "selectImageUrl" which holds the URL of the selected image. [*]A submit button.
When the user clicks on the "Select Images" button, the "imagesPanels" is displayed for the user. When the user clicks on image inside the panel, it will then close and the image will be displayed

Then, add the following JavaScript code to the Dynaform:
Code: Select all
//execute when DynaForm loads:
var tableHtml = $("#htmlTable").getValue();
if (tableHtml != '') {
  $("#imagesPanel").html(tableHtml);
}

$("#imagesPanel").hide();

if ($("selectedImageUrl").getValue() != '') {
  $("selectedImage").find("img").prop("src", $("selectedImageUrl").getValue() );
}

//execute when user clicks on "Select Image" button:
$("#selectImageBtn").find("button").click(function() {
  $("#imagesPanel").show();
  $("#imagesPanel").focus();
});

//execute when user clicks on image inside the "imagesPanel":
$("#imagesPanel img").click(function() {
  var imageUrl = $(this).prop("src");
  $("#selectedImage").find("img").prop("src", imageUrl);
  $("selectedImageUrl").setValue(imageUrl);
  $("#imagesPanel").hide();
}); 
Then, create the following trigger and set it execute before the DynaForm:
Code: Select all
//Set to the ID of process or @@PROCESS if the image files are  
//in the Public Files of the same process:
$processId = @@PROCESS;
$aAllowedExt = array('jpg', 'jpeg', 'png', 'gif');
$imgWidth = "250px"; //set to width of image
$columnsPerRow = 2;  //set to the number of images per row

$g = new G();
$url = ($g->is_https() ? 'https://' : 'http://') . $_SERVER['SERVER_NAME'].
    ($_SERVER['SERVER_PORT'] == 80 ? '' : ':'.$_SERVER['SERVER_PORT']). 
    '/sys'.@@SYS_SYS.'/'.@@SYS_LANG.'/'.@@SYS_SKIN.'/'.$processId.'/';
$path = PATH_DATA_PUBLIC . $processId . PATH_SEP;
$d = dir($path) or die("Bad path");
$aImageFiles = array();
    
while (false !== ($entry = $d->read())) {
    $ext = pathinfo($entry, PATHINFO_EXTENSION);
    if (!empty($ext) and in_array($ext, $aAllowedExt)) {
        $aImageFiles[] = "<img src=\"$url$entry\" width=\"$imgWidth\"><br />$entry";
    }
}
$d->close();

@@htmlTable = '<table><tbody><tr>';
 
for ($i = 0; $i < count($aImageFiles); $i++) {
    $cell = '<td>'.$aImageFiles[$i].'</td>';

    if ($i != 0 and $i % $columnsPerRow == 0) {
        $cell = '</tr><tr>' . $cell;
    }
    @@htmlTable .= $cell;
}

@@htmlTable .= "</tr></tbody></table>";
This code looks up all the image files in the Public Files directory. It creates an HTML table whose cells contain images of those files and places that table in the @@htmlTable variable which is passed to a hidden field in the DynaForm.

When a case is run, the user can select one of the images in the panel:
SelectPicForm.png
SelectPicForm.png (73.68 KiB) Viewed 4631 times
If this same DynaForm is displayed in a subsequent task, the selected image will be redisplayed in the form.

Here is the sample process which can be downloaded and imported:
(182.45 KiB) Downloaded 255 times
By azatrath
#796012
Ty for reply amos,

its really good but i need to select more than one. because customer generally want at least 3 product same time. is there any option for that?
User avatar
By amosbatto
#796024
Here is a sample process that allows multiple selection of images:
(184.23 KiB) Downloaded 248 times
The Dynaform uses two panels:
SelectImagesFormInDesigner.png
SelectImagesFormInDesigner.png (44.43 KiB) Viewed 4610 times
The JavaScript code is more complicated:
Code: Select all
//execute when DynaForm loads:
var tableHtml = $("#htmlTable").getValue();
if (tableHtml != '') {
  $("#imagesPanel").html(tableHtml);
}
$("#imagesPanel").hide();

//populate "selectedImagesPanel" from selectedImagesUrls hidden field:
function populateSelectedImages(imageUrlToAdd) {
  var urls, aUrls;
  
  if (imageUrlToAdd != '') {
    urls = $("#selectedImagesUrls").getValue();
    aUrls = urls.split(',');
  
    //check if imageUrl isn't already added to "selectedImagesPanel", before adding it:
    if (aUrls.indexOf(imageUrlToAdd) == -1) { 
      urls += (urls == '' ? '' : ',') + imageUrlToAdd; 
      $("#selectedImagesUrls").setValue(urls);
    }
  }  
    
  var selectedImgContent = "<b>Selected Images:</b><br>\n";
  urls = $("#selectedImagesUrls").getValue();
  
  var divNoSpace = '<div style="margin:0; padding:0;">';

  if (urls != '') {
    aUrls = urls.split(",");
    for (var i = 0; i < aUrls.length; i++) {
      selectedImgContent += divNoSpace + '<img style="max-width:250px;" src="' + aUrls[i] +
        '"><img src="/images/delete-icon.png" onclick="javascript:removeImage(this)"></div>\n';
    }
  }

  $("#selectedImagesPanel").html(selectedImgContent);
}

populateSelectedImages(""); //when DynaForm loads

//execute when user clicks on "Show Images to select" button:
function showOrHideImages() {
  if ($("#showImagesBtn").getValue() == "Show Images to select") {
	$("#imagesPanel").show();
  	$("#imagesPanel").focus();
    $("#showImagesBtn").setValue("Hide Images to select");
  } 
  else {
    $("#imagesPanel").hide();
    $("#showImagesBtn").setValue("Show Images to select");
  }
  
  //reassign click event handler because button gets reset with each click:
  $("#showImagesBtn").find("button").click(showOrHideImages);
}
$("#showImagesBtn").find("button").click(showOrHideImages);

//execute when user clicks on image inside the "imagesPanel":
$("#imagesPanel img").click(function() {
  var imageUrl = $(this).prop("src");
  populateSelectedImages(imageUrl);
});

//called when the delete icon is clicked next to a selected image
function removeImage(elem) {
  var removeUrl = $(elem).prev("img").prop("src");
  var aUrls = $("#selectedImagesUrls").getValue().split(',');
  var removeIndex = aUrls.indexOf(removeUrl);
  
  if (removeIndex != -1) {
        aUrls.splice(removeIndex, 1);
  }
  
  var urls = aUrls.join(',');
  $("#selectedImagesUrls").setValue(urls);
  populateSelectedImages(''); 
}
Here is what it looks when selecting images:
SelectedImagesInCase.png
SelectedImagesInCase.png (100.97 KiB) Viewed 4603 times
By azatrath
#812395
amosbatto wrote:Here is a sample process that allows multiple selection of images:
Select_Pics-1.pmx
The Dynaform uses two panels:
SelectImagesFormInDesigner.png
The JavaScript code is more complicated:
Code: Select all
//execute when DynaForm loads:
var tableHtml = $("#htmlTable").getValue();
if (tableHtml != '') {
  $("#imagesPanel").html(tableHtml);
}
$("#imagesPanel").hide();

//populate "selectedImagesPanel" from selectedImagesUrls hidden field:
function populateSelectedImages(imageUrlToAdd) {
  var urls, aUrls;
  
  if (imageUrlToAdd != '') {
    urls = $("#selectedImagesUrls").getValue();
    aUrls = urls.split(',');
  
    //check if imageUrl isn't already added to "selectedImagesPanel", before adding it:
    if (aUrls.indexOf(imageUrlToAdd) == -1) { 
      urls += (urls == '' ? '' : ',') + imageUrlToAdd; 
      $("#selectedImagesUrls").setValue(urls);
    }
  }  
    
  var selectedImgContent = "<b>Selected Images:</b><br>\n";
  urls = $("#selectedImagesUrls").getValue();
  
  var divNoSpace = '<div style="margin:0; padding:0;">';

  if (urls != '') {
    aUrls = urls.split(",");
    for (var i = 0; i < aUrls.length; i++) {
      selectedImgContent += divNoSpace + '<img style="max-width:250px;" src="' + aUrls[i] +
        '"><img src="/images/delete-icon.png" onclick="javascript:removeImage(this)"></div>\n';
    }
  }

  $("#selectedImagesPanel").html(selectedImgContent);
}

populateSelectedImages(""); //when DynaForm loads

//execute when user clicks on "Show Images to select" button:
function showOrHideImages() {
  if ($("#showImagesBtn").getValue() == "Show Images to select") {
	$("#imagesPanel").show();
  	$("#imagesPanel").focus();
    $("#showImagesBtn").setValue("Hide Images to select");
  } 
  else {
    $("#imagesPanel").hide();
    $("#showImagesBtn").setValue("Show Images to select");
  }
  
  //reassign click event handler because button gets reset with each click:
  $("#showImagesBtn").find("button").click(showOrHideImages);
}
$("#showImagesBtn").find("button").click(showOrHideImages);

//execute when user clicks on image inside the "imagesPanel":
$("#imagesPanel img").click(function() {
  var imageUrl = $(this).prop("src");
  populateSelectedImages(imageUrl);
});

//called when the delete icon is clicked next to a selected image
function removeImage(elem) {
  var removeUrl = $(elem).prev("img").prop("src");
  var aUrls = $("#selectedImagesUrls").getValue().split(',');
  var removeIndex = aUrls.indexOf(removeUrl);
  
  if (removeIndex != -1) {
        aUrls.splice(removeIndex, 1);
  }
  
  var urls = aUrls.join(',');
  $("#selectedImagesUrls").setValue(urls);
  populateSelectedImages(''); 
}
Here is what it looks when selecting images:
SelectedImagesInCase.png

hi amos,

sory for interrupting again. with this i am trying something else but i cannot achieve. i want to ask is it possible?

can i split this image panel more than one. think about 4-5 panel for different quality images. each panels show different images. its too much to handle it by myself :/

i added new panel and add images with HTML url like this.
"<b>http://192.168.2.220/syskozacarpet/en/n ... <tbody><tr>" now i am trying to select all images different panels to selected one but you can imagine that i am stuck with java fuction. i need to collect each image
to selectedimages fromm around 10 panels :(
User avatar
By amosbatto
#812415
You need to add this code for each panel where you have images:
$("#panel-id img").click(function() {
var imageUrl = $(this).prop("src");
populateSelectedImages(imageUrl);
});

For example, if the ID of the panel is "largeImagesPanel", then:
Code: Select all
//execute when user clicks on image inside the "largeImagesPanel":
$("#largeImagesPanel img").click(function() {
  var imageUrl = $(this).prop("src");
  populateSelectedImages(imageUrl);
});
By azatrath
#812649
amosbatto wrote:You need to add this code for each panel where you have images:
$("#panel-id img").click(function() {
var imageUrl = $(this).prop("src");
populateSelectedImages(imageUrl);
});

For example, if the ID of the panel is "largeImagesPanel", then:
Code: Select all
//execute when user clicks on image inside the "largeImagesPanel":
$("#largeImagesPanel img").click(function() {
  var imageUrl = $(this).prop("src");
  populateSelectedImages(imageUrl);
});
hi amos your effort is helping to improve myself. i am glad. but still there is problem i cant pass.
i changed trigger which is fired before dynaform like that
Code: Select all
"$result = executeQuery("SELECT IMG FROM PMT_QUALITY WHERE QUALITY = '1' AND Q_STATUS = '1' ");

@@MH01 = '<b>Click on image(s) to select them:</b><br><table><tbody><tr>';
 
for ($i = 1; $i <= count($result); $i++) {

	$cell = '<td>'.$result[$i]['IMG'].'</td>';

	if ($i != 0 and $i % 3 == 1) {
		$cell = '</tr><tr>' . $cell;
	}
	@@MH01 .= $cell;
}

@@MH01 .= "</tr></tbody></table>"; 
because i have 20 panels and some of images i need to show and some of them i have to hide. i got solution ( with not enough information about coding :( ) using PM table . i transfer img urls to database like that
Code: Select all
<img src="http://192.168.2.220/syskozacarpet/en/neoclassic/3240661625a0931164cd870074908571/45159A_DK6_37.jpg"  width="250" />
everthing is good till now. my manager told me. while i am using this process, i want a button (or checkbox) will close all selected images. i added a column to PM table about status. i know how to change status but i cant get selected images properly selected panel is like that "
Code: Select all
"http://192.168.2.220/syskozacarpet/en/neoclass
ic/3240661625a0931164cd870074908571/4514
1A_DKY_37.jpg,http://192.168.2.220/syskozac
arpet/en/neoclassic/3240661625a0931164cd870
074908571/45159A_DK6_37.jpg,http://192.168
.2.220/syskozacarpet/en/neoclassic/3240661625
a0931164cd870074908571/45142A_DK5_34.jp
g,http://192.168.2.220/syskozacarpet/en/neoclas
sic/3240661625a0931164cd870074908571/451
41A_DK6_38.jpg"
i am stuck again, i added my process to attachments.can you help me ?
Attachments
(4.8 MiB) Downloaded 239 times

Hello. For rental housing, there are software solu[…]

Experience heightened pleasure with Cenforce 100 M[…]

Get an instant solution to move emails to MBOX for[…]

Most Demanding OST to PST Converter

The most demanding OST to PST Converter is TrijaT[…]