Browse Source

Add roaster capacity checks to new batch window on profile load

Neal Wilson 8 years ago
parent
commit
4f7d058947
3 changed files with 765 additions and 691 deletions
  1. 21
    2
      config/Windows/newbatch.xml
  2. 707
    689
      config/Windows/productionroaster.xml
  3. 37
    0
      src/typica.w

+ 21
- 2
config/Windows/newbatch.xml View File

@@ -41,7 +41,7 @@
41 41
             </layout>
42 42
             <layout type="horizontal">
43 43
                 <label>Roasted Weight:</label>
44
-                <line id="roast" validator="numeric" />
44
+                <line id="roast" validator="numeric">0.0</line>
45 45
                 <label>Weight Loss:</label>
46 46
                 <line id="wloss" writable="false" />
47 47
                 <button type="check" id="approval" name="Approved" />
@@ -381,7 +381,26 @@
381 381
                 roastestimate.text = "";
382 382
                 query = query.invalidate();
383 383
             });
384
+            var validateCapacity = function() {
385
+                if(checkCapacity == "true") {
386
+                    if(convertToPounds(parseFloat(green.text), unitBox.currentText) > poundsCapacity) {
387
+                        return false;
388
+                    }
389
+                }
390
+                return true;
391
+            }
384 392
             profilebutton.clicked.connect(function() {
393
+                var proceed = false;
394
+                if(validateCapacity()) {
395
+                    proceed = true;
396
+                } else {
397
+                    proceed = displayWarning("Suspicious Input", "Entered green coffee weight exceeds maximum batch size. Continue?");
398
+                }
399
+                if(proceed) {
400
+                    doLoadProfile();
401
+                }
402
+            });
403
+            var doLoadProfile = function() {
385 404
                 batch.windowModified = true;
386 405
                 currentBatchInfo = batch;
387 406
                 query = new QSqlQuery();
@@ -450,7 +469,7 @@
450 469
                 log.updatesEnabled = true;
451 470
                 graph.updatesEnabled = true;
452 471
                 log.newAnnotation("End", 1, lc);
453
-            });
472
+            }
454 473
             var noprofilebutton = findChildObject(this, 'noprofile');
455 474
             noprofilebutton.clicked.connect(function() {
456 475
                 batch.windowModified = true;

+ 707
- 689
config/Windows/productionroaster.xml
File diff suppressed because it is too large
View File


+ 37
- 0
src/typica.w View File

@@ -922,6 +922,43 @@ QScriptValue QWidget_activateWindow(QScriptContext *context,
922 922
     return QScriptValue();
923 923
 }
924 924
 
925
+@* Scripting QMessageBox.
926
+
927
+\noindent Some features require that \pn{} pauses an operation until further
928
+information can be obtained. An example of this is discretionary validation
929
+where input is checked and if it seems unlikely but not impossible to be
930
+correct a dialog should come up asking if that input is correct. If it is not,
931
+the operation should be cancelled and the person using \pn{} should be allowed
932
+to correct the information and try again.
933
+
934
+For this use case, it is not necessary to fully expose the |QMessageBox| class.
935
+Instead, it is enough to provide a function that will raise an appropriate
936
+message and return the selected action.
937
+
938
+@<Function prototypes for scripting@>=
939
+QScriptValue displayWarning(QScriptContext *context, QScriptEngine *engine);
940
+
941
+@ This function is exposed to the host environment.
942
+
943
+@<Set up the scripting engine@>=
944
+constructor = engine->newFunction(displayWarning);
945
+engine->globalObject().setProperty("displayWarning", constructor);
946
+
947
+@ The function takes some arguments.
948
+
949
+@<Functions for scripting@>=
950
+QScriptValue displayWarning(QScriptContext *context, QScriptEngine *)
951
+{
952
+    QMessageBox::StandardButton selection = QMessageBox::warning(NULL,
953
+        argument<QString>(0, context),
954
+        argument<QString>(1, context),
955
+        QMessageBox::Ok | QMessageBox::Cancel);
956
+    if(selection == QMessageBox::Ok) {
957
+        return QScriptValue(true);
958
+    }
959
+    return QScriptValue(false);
960
+}
961
+
925 962
 @* Scripting QMainWindow.
926 963
 
927 964
 \noindent Rather than directly exposing |QMainWindow| to the scripting engine,

Loading…
Cancel
Save