Wexus2 0.20
wexus2.src/wexus/Form.h
00001 
00002 /*
00003  * Copyright (c) 2011 Aleksander B. Demko
00004  * This source code is distributed under the MIT license.
00005  * See the accompanying file LICENSE.MIT.txt for details.
00006  */
00007 
00008 #ifndef __INCLUDED_WEXUS_FORM_H__
00009 #define __INCLUDED_WEXUS_FORM_H__
00010 
00011 #include <wexus/Widgets.h>
00012 #include <wexus/ValidationExpr.h>
00013 #include <wexus/Context.h>
00014 #include <wexus/ActiveRecord.h>
00015 
00016 namespace wexus
00017 {
00018   /**
00019    * An HTML form.
00020    * This emits a complete form via the output() stream.
00021    *
00022    * @author Aleksander Demko
00023    */ 
00024   class Form;
00025 }
00026 
00027 /**
00028  * A general HTML form.
00029  *
00030  * @author Aleksander Demko
00031  */ 
00032 class wexus::Form
00033 {
00034   public:
00035     enum {
00036       Method_Post,
00037       Method_Get,
00038       Method_Upload,
00039     };
00040 
00041   public:
00042     /**
00043      * Constructor.
00044      *
00045      * @author Aleksander Demko
00046      */ 
00047     Form(const QString &formname, const QString &rawurl = pathTo(), int method = Method_Post);
00048     /**
00049      * Constructor that uses the given ActiveRecord for default
00050      * values.
00051      *
00052      * @author Aleksander Demko
00053      */ 
00054     Form(ActiveRecord &rec, const QString &rawurl = pathTo(), int method = Method_Post);
00055     /// destructor
00056     ~Form();
00057 
00058     /**
00059      * A basicl text field.
00060      *
00061      * @author Aleksander Demko
00062      */
00063     wexus::HTMLString textField(const QString &fieldName, const QVariant &defaultVal = QVariant(), int sz = 30, int maxlen = 60, const ValidationExpr &valExpr = ValidationExpr()) const;
00064 
00065     /**
00066      * The submit button. fieldName is optional and not often used.
00067      *
00068      * @author Aleksander Demko
00069      */ 
00070     wexus::HTMLString submitButton(const QString &desc, const QString &fieldName = QString()) const;
00071 
00072   public:
00073     static void testFlashValidators(const QVariantMap &params,
00074         const QVariantMap &flash, Context::Errors &errors);
00075 
00076   protected:
00077     /**
00078      * Emits the form field to output
00079      *
00080      * @author Aleksander Demko
00081      */
00082     wexus::HTMLString fullFieldName(const QString &fieldName) const;
00083 
00084     /**
00085      * Returns the current value from the form. If there isn't
00086      * one, then this returns the current value of fieldName
00087      * in the active record. If there is no activerecord
00088      * for this form, then this returns QVariant (an inValid
00089      * QVariant)
00090      *
00091      * @author Aleksander Demko
00092      */ 
00093     QVariant formValue(const QString &fieldName) const;
00094 
00095   private:
00096     void outputHeader(const QString &rawurl, int method);
00097 
00098   protected:
00099     QString dm_formname;
00100     ActiveRecord *dm_rec; // might be null if one wasn't supplied
00101 };
00102 
00103 #endif
00104 
 All Classes Namespaces Functions Variables Enumerations Enumerator