Skip to content

Commit 18ce90b

Browse files
committed
peb.startScript() function
1 parent dab0634 commit 18ce90b

File tree

6 files changed

+60
-61
lines changed

6 files changed

+60
-61
lines changed

README.md

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ These are the basic steps for building your first PEB-based application:
4848

4949
* **4.** Connect your Perl scripts using a link to ``name-of-script-configuration-object.settings``.
5050

51-
PEB is created to work from any folder without installation and all your local HTML files and Perl scripts should be located inside the ``{PEB_binary_directory}/resources/app`` directory.
51+
PEB is created to work from any folder without installation and all your local HTML files and Perl scripts should be located in the ``{PEB_binary_directory}/resources/app`` directory.
5252

5353
## Design Objectives
5454
* **1. Fast, easy and beautiful graphical user interface for Perl 5 desktop applications**
@@ -137,11 +137,7 @@ Sometimes it is important to minimize the size of the relocatable (or portable)
137137
## Perl Scripts API
138138
Every Perl script run by PEB is called by clicking a link or submitting a form to a pseudo filename composed from the name of the JavaScript object with the settings of the Perl script and a ``.settings`` extension.
139139

140-
A minimal example of a Perl script settings object and a starting link:
141-
142-
```html
143-
<a href="perl_test.settings">Start Perl script</a>
144-
```
140+
A minimal example of a Perl script settings object:
145141

146142
```javascript
147143
var perl_test = {};
@@ -152,6 +148,23 @@ perl_test.stdoutFunction = function (stdout) {
152148
}
153149
```
154150

151+
Three methods to start a local Perl script:
152+
153+
```html
154+
<a href="perl_test.settings">Start Perl script</a>
155+
```
156+
157+
```html
158+
<form action="perl_test.settings">
159+
<input type="text" name="input" id="test-script-input">
160+
<input type="submit" value="Start Perl script">
161+
</form>
162+
```
163+
164+
```javascript
165+
peb.startScript('perl_test.settings');
166+
```
167+
155168
* ``scriptFullPath``
156169
This is the path of the Perl script that is going to be executed.
157170
The keyword ``{app}`` will be replaced by the the full path of the application directory.

resources/app/index.html

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88

99
<script>
1010
// PEB page settings:
11-
// 'pebSettings' object name is hard-coded.
12-
var pebSettings = {};
11+
var pebSettings = {}; // 'pebSettings' object name is hard-coded.
1312
pebSettings.autoStartScripts = ['interactive_one', 'interactive_two'];
1413
pebSettings.cutLabel = '- Cut -';
1514
pebSettings.copyLabel = '- Copy -';
@@ -54,6 +53,20 @@
5453
interactive_two.scriptExitCommand = '_close_';
5554
interactive_two.scriptExitConfirmation = '_closed_';
5655

56+
var open_files = {};
57+
open_files.scriptFullPath = '{app}/perl/open-files.pl';
58+
open_files.requestMethod = 'POST';
59+
open_files.stdoutFunction = function (stdout) {
60+
displayTestResult(stdout);
61+
}
62+
63+
var open_directory = {};
64+
open_directory.scriptFullPath = '{app}/perl/open-directory.pl';
65+
open_directory.requestMethod = 'POST';
66+
open_directory.stdoutFunction = function (stdout) {
67+
displayTestResult(stdout);
68+
}
69+
5770
var get_test = {};
5871
get_test.scriptFullPath = '{app}/perl/get-post-test.pl';
5972
get_test.stdoutFunction = function (stdout) {
@@ -82,42 +95,35 @@
8295
displayTestResult(stdout);
8396
}
8497

85-
// Filesystem dilog boxes configuration objects:
98+
// Settings objects for the filesystem dialogs:
8699
var select_file = {};
87100
select_file.type = 'single-file';
88101
select_file.receiverFunction = function (fileName) {
89-
clearTargetElement();
90-
var pre = document.createElement("pre");
91-
pre.innerHTML = 'Selected existing file: ' + fileName;
92-
document.getElementById('tests').appendChild(pre);
102+
open_files.inputData = fileName;
103+
peb.startScript('open_files.settings');
93104
}
94105

95106
var new_file_name = {};
96107
new_file_name.type = 'new-file-name';
97108
new_file_name.receiverFunction = function (fileName) {
98109
clearTargetElement();
99110
var pre = document.createElement("pre");
100-
pre.innerHTML = 'Selected new file name: ' + fileName;
111+
pre.innerHTML = 'New file name: ' + fileName;
101112
document.getElementById('tests').appendChild(pre);
102113
}
103114

104115
var select_files = {};
105116
select_files.type = 'multiple-files';
106117
select_files.receiverFunction = function (fileNames) {
107-
clearTargetElement();
108-
var pre = document.createElement("pre");
109-
fileNames = fileNames.replace(/;/g, "<br>");
110-
pre.innerHTML = 'Selected files:<br>' + fileNames;
111-
document.getElementById('tests').appendChild(pre);
118+
open_files.inputData = fileNames;
119+
peb.startScript('open_files.settings');
112120
}
113121

114122
var select_directory = {};
115123
select_directory.type = 'directory';
116124
select_directory.receiverFunction = function (directoryName) {
117-
clearTargetElement();
118-
var pre = document.createElement("pre");
119-
pre.innerHTML = 'Selected directory: ' + directoryName;
120-
document.getElementById('tests').appendChild(pre);
125+
open_directory.inputData = directoryName;
126+
peb.startScript('open_directory.settings');
121127
}
122128

123129
function clearTargetElement() {
@@ -180,37 +186,28 @@
180186
<div class="navbar navbar-inverse">
181187
<ul class="nav navbar-nav">
182188
<li>
183-
<a id="filesystem-menu" role="button" data-toggle="dropdown" data-target="#">
184-
Dialogs
189+
<a id="local-tests" role="button" data-toggle="dropdown" data-target="#">
190+
Local Tests
185191
<span class="caret"></span>
186192
</a>
187193

188194
<ul class="dropdown-menu" role="menu">
189195
<li>
190-
<a href="select_file.dialog">Select Existing File</a>
196+
<a href="select_file.dialog">Open Existing File</a>
191197
</li>
192198

193199
<li>
194-
<a href="new_file_name.dialog">New File Name</a>
200+
<a href="new_file_name.dialog">Enter New File Name</a>
195201
</li>
196202

197203
<li>
198-
<a href="select_files.dialog">Select Multiple Files</a>
204+
<a href="select_files.dialog">Open Multiple Files</a>
199205
</li>
200206

201207
<li>
202-
<a href="select_directory.dialog">Select Directory</a>
208+
<a href="select_directory.dialog">Open Directory</a>
203209
</li>
204-
</ul>
205-
</li>
206210

207-
<li>
208-
<a id="local-tests" role="button" data-toggle="dropdown" data-target="#">
209-
Local Tests
210-
<span class="caret"></span>
211-
</a>
212-
213-
<ul class="dropdown-menu" role="menu">
214211
<li>
215212
<a href="get_test.settings">GET Test</a>
216213
</li>
@@ -220,7 +217,7 @@
220217
</li>
221218

222219
<li>
223-
<a href="perl_info.settings">Perl Basic information</a>
220+
<a href="perl_info.settings">Perl Basic Information</a>
224221
</li>
225222

226223
<li>

resources/app/perl/open-directory.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
traverse ($directory_name);
2020

21-
print "Listing all files in the $directory_name directory:<br>";
21+
print "Listing all files in $directory_name:<br>";
2222
foreach my $file (@files) {
2323
print "$file<br>";
2424
}

resources/app/perl/open-file.pl

Lines changed: 0 additions & 15 deletions
This file was deleted.

resources/app/perl/open-files.pl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
my $number_of_lines;
1111

12-
print "Opening multiple files:<br>";
13-
1412
foreach my $file (@files) {
1513
open my $filehandle, '<', $file or die "Unable to open file: $!";
1614
my @file_contents = <$filehandle>;

src/resources/peb.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ peb.getPageSettings = function() {
77
}
88
}
99

10+
peb.getDialogSettings = function(dialogObject) {
11+
if (window[dialogObject] !== null) {
12+
return JSON.stringify(dialogObject);
13+
}
14+
}
15+
1016
peb.getScriptSettings = function(scriptObject) {
1117
if (window[scriptObject] !== null) {
1218
if (typeof scriptObject.inputDataHarvester === 'function') {
@@ -16,10 +22,10 @@ peb.getScriptSettings = function(scriptObject) {
1622
}
1723
}
1824

19-
peb.getDialogSettings = function(dialogObject) {
20-
if (window[dialogObject] !== null) {
21-
return JSON.stringify(dialogObject);
22-
}
25+
peb.startScript = function(scriptObjectName) {
26+
var form = document.createElement('form');
27+
form.setAttribute('action', scriptObjectName);
28+
form.submit();
2329
}
2430

2531
peb.checkUserInputBeforeClose = function() {

0 commit comments

Comments
 (0)