rsence-pre 2.1.0.1.pre
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.yardopts +10 -0
- data/INSTALL.rdoc +330 -0
- data/LICENSE.txt +622 -0
- data/README.rdoc +98 -0
- data/VERSION +1 -0
- data/bin/rsence +25 -0
- data/bin/rsence-pre +25 -0
- data/conf/default_conf.yaml +346 -0
- data/conf/default_strings.yaml +76 -0
- data/conf/rsence_command_strings.yaml +444 -0
- data/docs/ExampleGuiPlugin.rdoc +193 -0
- data/docs/JavascriptBundles.rdoc +0 -0
- data/docs/PluginBundleInfo.rdoc +173 -0
- data/docs/PluginBundles.rdoc +96 -0
- data/docs/Values.rdoc +163 -0
- data/js/comm/autosync/autosync.js +17 -0
- data/js/comm/autosync/js.inc +0 -0
- data/js/comm/comm.js +203 -0
- data/js/comm/js.inc +0 -0
- data/js/comm/jsloader/js.inc +0 -0
- data/js/comm/jsloader/jsloader.js +112 -0
- data/js/comm/queue/js.inc +0 -0
- data/js/comm/queue/queue.js +184 -0
- data/js/comm/session/js.inc +0 -0
- data/js/comm/session/session.js +52 -0
- data/js/comm/sessionwatcher/js.inc +0 -0
- data/js/comm/sessionwatcher/sessionwatcher.js +44 -0
- data/js/comm/transporter/js.inc +0 -0
- data/js/comm/transporter/transporter.js +261 -0
- data/js/comm/urlresponder/js.inc +0 -0
- data/js/comm/urlresponder/urlresponder.js +149 -0
- data/js/comm/values/js.inc +0 -0
- data/js/comm/values/values.js +433 -0
- data/js/controls/button/button.js +72 -0
- data/js/controls/button/js.inc +0 -0
- data/js/controls/button/themes/bright/button.css +89 -0
- data/js/controls/button/themes/bright/button.html +7 -0
- data/js/controls/button/themes/bright/button_parts1-ie6.gif +0 -0
- data/js/controls/button/themes/bright/button_parts1.png +0 -0
- data/js/controls/button/themes/default/button.css +89 -0
- data/js/controls/button/themes/default/button.html +7 -0
- data/js/controls/button/themes/default/button_parts1-ie6.gif +0 -0
- data/js/controls/button/themes/default/button_parts1.png +0 -0
- data/js/controls/checkbox/checkbox.js +49 -0
- data/js/controls/checkbox/js.inc +0 -0
- data/js/controls/checkbox/themes/default/checkbox.css +69 -0
- data/js/controls/checkbox/themes/default/checkbox.html +5 -0
- data/js/controls/checkbox/themes/default/checkbox_parts1-ie6.gif +0 -0
- data/js/controls/checkbox/themes/default/checkbox_parts1.png +0 -0
- data/js/controls/dialogs/alert_sheet/alert_sheet.js +63 -0
- data/js/controls/dialogs/alert_sheet/js.inc +0 -0
- data/js/controls/dialogs/confirm_sheet/confirm_sheet.js +37 -0
- data/js/controls/dialogs/confirm_sheet/js.inc +0 -0
- data/js/controls/dialogs/sheet/js.inc +0 -0
- data/js/controls/dialogs/sheet/sheet.js +84 -0
- data/js/controls/dialogs/sheet/themes/default/sheet.css +64 -0
- data/js/controls/dialogs/sheet/themes/default/sheet.html +14 -0
- data/js/controls/dialogs/sheet/themes/default/sheet_bg-ie6.gif +0 -0
- data/js/controls/dialogs/sheet/themes/default/sheet_bg.png +0 -0
- data/js/controls/dialogs/sheet/themes/default/sheet_dim-ie6.gif +0 -0
- data/js/controls/dialogs/sheet/themes/default/sheet_dim.png +0 -0
- data/js/controls/dialogs/sheet/themes/default/sheet_parts1-ie6.gif +0 -0
- data/js/controls/dialogs/sheet/themes/default/sheet_parts1.png +0 -0
- data/js/controls/dialogs/sheet/themes/default/sheet_parts2-ie6.gif +0 -0
- data/js/controls/dialogs/sheet/themes/default/sheet_parts2.png +0 -0
- data/js/controls/dialogs/sheet/themes/default/sheet_warning-ie6.gif +0 -0
- data/js/controls/dialogs/sheet/themes/default/sheet_warning.png +0 -0
- data/js/controls/imageview/imageview.js +109 -0
- data/js/controls/imageview/js.inc +0 -0
- data/js/controls/imageview/themes/default/blank.gif +0 -0
- data/js/controls/passwordcontrol/js.inc +0 -0
- data/js/controls/passwordcontrol/passwordcontrol.js +23 -0
- data/js/controls/passwordcontrol/themes/default/passwordcontrol.css +0 -0
- data/js/controls/passwordcontrol/themes/default/passwordcontrol.html +18 -0
- data/js/controls/progress/progressbar/js.inc +0 -0
- data/js/controls/progress/progressbar/progressbar.js +40 -0
- data/js/controls/progress/progressbar/themes/default/progressbar.css +16 -0
- data/js/controls/progress/progressbar/themes/default/progressbar.html +2 -0
- data/js/controls/progress/progressindicator/js.inc +0 -0
- data/js/controls/progress/progressindicator/progressindicator.js +44 -0
- data/js/controls/radiobutton/js.inc +0 -0
- data/js/controls/radiobutton/radiobutton.js +43 -0
- data/js/controls/radiobutton/themes/default/radiobutton.css +69 -0
- data/js/controls/radiobutton/themes/default/radiobutton.html +5 -0
- data/js/controls/radiobutton/themes/default/radiobutton_parts1-ie6.gif +0 -0
- data/js/controls/radiobutton/themes/default/radiobutton_parts1.png +0 -0
- data/js/controls/sliders/slider/js.inc +0 -0
- data/js/controls/sliders/slider/slider.js +357 -0
- data/js/controls/sliders/slider/themes/default/hslider_tracks-ie6.gif +0 -0
- data/js/controls/sliders/slider/themes/default/hslider_tracks.png +0 -0
- data/js/controls/sliders/slider/themes/default/slider.css +108 -0
- data/js/controls/sliders/slider/themes/default/slider.html +5 -0
- data/js/controls/sliders/slider/themes/default/slider_thumbs-ie6.gif +0 -0
- data/js/controls/sliders/slider/themes/default/slider_thumbs.png +0 -0
- data/js/controls/sliders/vslider/js.inc +0 -0
- data/js/controls/sliders/vslider/themes/default/vslider.css +52 -0
- data/js/controls/sliders/vslider/themes/default/vslider.html +5 -0
- data/js/controls/sliders/vslider/themes/default/vslider_tracks-ie6.gif +0 -0
- data/js/controls/sliders/vslider/themes/default/vslider_tracks.png +0 -0
- data/js/controls/sliders/vslider/vslider.js +41 -0
- data/js/controls/stepper/js.inc +0 -0
- data/js/controls/stepper/stepper.js +213 -0
- data/js/controls/stepper/themes/default/stepper-ie6.gif +0 -0
- data/js/controls/stepper/themes/default/stepper.css +14 -0
- data/js/controls/stepper/themes/default/stepper.html +2 -0
- data/js/controls/stepper/themes/default/stepper.png +0 -0
- data/js/controls/stringview/js.inc +0 -0
- data/js/controls/stringview/stringview.js +49 -0
- data/js/controls/stringview/themes/default/stringview.css +8 -0
- data/js/controls/stringview/themes/default/stringview.html +1 -0
- data/js/controls/tab/js.inc +0 -0
- data/js/controls/tab/tab.js +280 -0
- data/js/controls/tab/themes/bright/tab.css +76 -0
- data/js/controls/tab/themes/bright/tab.html +6 -0
- data/js/controls/tab/themes/bright/tab_bg_color-ie6.gif +0 -0
- data/js/controls/tab/themes/bright/tab_bg_color.png +0 -0
- data/js/controls/tab/themes/bright/tab_border_pattern-ie6.gif +0 -0
- data/js/controls/tab/themes/bright/tab_border_pattern.png +0 -0
- data/js/controls/tab/themes/bright/tab_parts1-ie6.gif +0 -0
- data/js/controls/tab/themes/bright/tab_parts1.png +0 -0
- data/js/controls/tab/themes/default/tab.css +77 -0
- data/js/controls/tab/themes/default/tab.html +6 -0
- data/js/controls/tab/themes/default/tab_bg_color-ie6.gif +0 -0
- data/js/controls/tab/themes/default/tab_bg_color.png +0 -0
- data/js/controls/tab/themes/default/tab_border_pattern-ie6.gif +0 -0
- data/js/controls/tab/themes/default/tab_border_pattern.png +0 -0
- data/js/controls/tab/themes/default/tab_parts1-ie6.gif +0 -0
- data/js/controls/tab/themes/default/tab_parts1.png +0 -0
- data/js/controls/textarea/js.inc +0 -0
- data/js/controls/textarea/textarea.js +24 -0
- data/js/controls/textarea/themes/default/textarea.css +21 -0
- data/js/controls/textarea/themes/default/textarea.html +18 -0
- data/js/controls/textcontrol/js.inc +0 -0
- data/js/controls/textcontrol/textcontrol.js +374 -0
- data/js/controls/textcontrol/themes/default/textcontrol.css +107 -0
- data/js/controls/textcontrol/themes/default/textcontrol.html +18 -0
- data/js/controls/textcontrol/themes/default/textcontrol_parts1-ie6.gif +0 -0
- data/js/controls/textcontrol/themes/default/textcontrol_parts1.png +0 -0
- data/js/controls/textcontrol/themes/default/textcontrol_parts2-ie6.gif +0 -0
- data/js/controls/textcontrol/themes/default/textcontrol_parts2.png +0 -0
- data/js/controls/textcontrol/themes/default/textcontrol_parts3-ie6.gif +0 -0
- data/js/controls/textcontrol/themes/default/textcontrol_parts3.png +0 -0
- data/js/controls/uploader/js.inc +0 -0
- data/js/controls/uploader/themes/default/upload_progress.gif +0 -0
- data/js/controls/uploader/themes/default/uploader.css +108 -0
- data/js/controls/uploader/themes/default/uploader.html +27 -0
- data/js/controls/uploader/uploader.js +154 -0
- data/js/controls/validatorview/js.inc +0 -0
- data/js/controls/validatorview/themes/default/validator-ie6.gif +0 -0
- data/js/controls/validatorview/themes/default/validator.png +0 -0
- data/js/controls/validatorview/themes/default/validatorview.css +0 -0
- data/js/controls/validatorview/themes/default/validatorview.html +0 -0
- data/js/controls/validatorview/validatorview.js +62 -0
- data/js/controls/window/js.inc +0 -0
- data/js/controls/window/themes/default/window.css +219 -0
- data/js/controls/window/themes/default/window.html +17 -0
- data/js/controls/window/themes/default/window_bg_active-ie6.gif +0 -0
- data/js/controls/window/themes/default/window_bg_active.png +0 -0
- data/js/controls/window/themes/default/window_bg_inactive-ie6.gif +0 -0
- data/js/controls/window/themes/default/window_bg_inactive.png +0 -0
- data/js/controls/window/themes/default/window_buttons-ie6.gif +0 -0
- data/js/controls/window/themes/default/window_buttons.png +0 -0
- data/js/controls/window/themes/default/window_parts1-ie6.gif +0 -0
- data/js/controls/window/themes/default/window_parts1.png +0 -0
- data/js/controls/window/themes/default/window_parts2-ie6.gif +0 -0
- data/js/controls/window/themes/default/window_parts2.png +0 -0
- data/js/controls/window/window.js +286 -0
- data/js/core/class/class.js +318 -0
- data/js/core/class/js.inc +0 -0
- data/js/core/elem/elem.js +1383 -0
- data/js/core/elem/js.inc +0 -0
- data/js/core/event/event.js +153 -0
- data/js/core/event/js.inc +0 -0
- data/js/core/iefix/ie_css_element.htc +5 -0
- data/js/core/iefix/ie_css_style.htc +5 -0
- data/js/core/iefix/iefix.js +359 -0
- data/js/core/iefix/js.inc +0 -0
- data/js/core/rsence_ns/js.inc +0 -0
- data/js/core/rsence_ns/rsence_ns.js +21 -0
- data/js/datetime/calendar/calendar.js +198 -0
- data/js/datetime/calendar/js.inc +0 -0
- data/js/datetime/calendar/themes/default/calendar.css +108 -0
- data/js/datetime/calendar/themes/default/calendar.html +9 -0
- data/js/datetime/calendar/themes/default/calendar_arrows-ie6.gif +0 -0
- data/js/datetime/calendar/themes/default/calendar_arrows.png +0 -0
- data/js/datetime/datetimevalue/datetimevalue.js +247 -0
- data/js/datetime/datetimevalue/js.inc +0 -0
- data/js/datetime/timesheet/js.inc +0 -0
- data/js/datetime/timesheet/themes/default/timesheet.css +30 -0
- data/js/datetime/timesheet/themes/default/timesheet.html +2 -0
- data/js/datetime/timesheet/timesheet.js +183 -0
- data/js/datetime/timesheet_item/js.inc +0 -0
- data/js/datetime/timesheet_item/themes/default/timesheet_item.css +42 -0
- data/js/datetime/timesheet_item/themes/default/timesheet_item.html +8 -0
- data/js/datetime/timesheet_item/timesheet_item.js +248 -0
- data/js/datetime/timesheet_item_edit/js.inc +0 -0
- data/js/datetime/timesheet_item_edit/timesheet_item_edit.js +274 -0
- data/js/foundation/application/application.js +208 -0
- data/js/foundation/application/js.inc +0 -0
- data/js/foundation/control/control.js +339 -0
- data/js/foundation/control/controldefaults/controldefaults.js +56 -0
- data/js/foundation/control/controldefaults/js.inc +0 -0
- data/js/foundation/control/dummyvalue/dummyvalue.js +51 -0
- data/js/foundation/control/dummyvalue/js.inc +0 -0
- data/js/foundation/control/dyncontrol/dyncontrol.js +500 -0
- data/js/foundation/control/dyncontrol/js.inc +0 -0
- data/js/foundation/control/dyncontrol/themes/default/dyncontrol.css +0 -0
- data/js/foundation/control/dyncontrol/themes/default/dyncontrol.html +0 -0
- data/js/foundation/control/eventresponder/eventresponder.js +750 -0
- data/js/foundation/control/eventresponder/js.inc +0 -0
- data/js/foundation/control/js.inc +0 -0
- data/js/foundation/control/valuematrix/js.inc +0 -0
- data/js/foundation/control/valuematrix/valuematrix.js +135 -0
- data/js/foundation/control/valueresponder/js.inc +0 -0
- data/js/foundation/control/valueresponder/valueresponder.js +79 -0
- data/js/foundation/eventmanager/eventmanager.js +991 -0
- data/js/foundation/eventmanager/js.inc +0 -0
- data/js/foundation/geom/point/js.inc +0 -0
- data/js/foundation/geom/point/point.js +202 -0
- data/js/foundation/geom/rect/js.inc +0 -0
- data/js/foundation/geom/rect/rect.js +651 -0
- data/js/foundation/json_renderer/js.inc +0 -0
- data/js/foundation/json_renderer/json_renderer.js +246 -0
- data/js/foundation/system/js.inc +0 -0
- data/js/foundation/system/system.js +381 -0
- data/js/foundation/thememanager/js.inc +0 -0
- data/js/foundation/thememanager/thememanager.js +393 -0
- data/js/foundation/value/js.inc +0 -0
- data/js/foundation/value/value.js +183 -0
- data/js/foundation/view/js.inc +0 -0
- data/js/foundation/view/markupview/js.inc +0 -0
- data/js/foundation/view/markupview/markupview.js +114 -0
- data/js/foundation/view/morphanimation/js.inc +0 -0
- data/js/foundation/view/morphanimation/morphanimation.js +237 -0
- data/js/foundation/view/view.js +1812 -0
- data/js/foundation/view/viewdefaults/js.inc +0 -0
- data/js/foundation/view/viewdefaults/viewdefaults.js +26 -0
- data/js/lists/checkboxlist/checkboxlist.js +171 -0
- data/js/lists/checkboxlist/js.inc +0 -0
- data/js/lists/listitems/js.inc +0 -0
- data/js/lists/listitems/listitems.js +88 -0
- data/js/lists/propertylist/js.inc +0 -0
- data/js/lists/propertylist/propertylist.js +326 -0
- data/js/lists/radiobuttonlist/js.inc +0 -0
- data/js/lists/radiobuttonlist/radiobuttonlist.js +116 -0
- data/js/util/reloadapp/js.inc +0 -0
- data/js/util/reloadapp/reloadapp.js +152 -0
- data/js/util/reloadapp/themes/default/reloadapp_warning-ie6.gif +0 -0
- data/js/util/reloadapp/themes/default/reloadapp_warning.png +0 -0
- data/js/util/sha/js.inc +0 -0
- data/js/util/sha/sha.js +426 -0
- data/js/views/centerview/centerview.js +75 -0
- data/js/views/centerview/js.inc +0 -0
- data/js/views/inlineview/inlineview.js +15 -0
- data/js/views/inlineview/js.inc +0 -0
- data/js/views/scrollview/js.inc +0 -0
- data/js/views/scrollview/scrollview.js +40 -0
- data/lib/conf/argv.rb +850 -0
- data/lib/conf/default.rb +219 -0
- data/lib/daemon/daemon.rb +387 -0
- data/lib/daemon/sigcomm.rb +64 -0
- data/lib/http/broker.rb +150 -0
- data/lib/http/rackup.rb +91 -0
- data/lib/http/request.rb +66 -0
- data/lib/http/response.rb +65 -0
- data/lib/plugins/dependencies.rb +285 -0
- data/lib/plugins/gui_plugin.rb +160 -0
- data/lib/plugins/guiparser.rb +123 -0
- data/lib/plugins/plugin.rb +438 -0
- data/lib/plugins/plugin_base.rb +162 -0
- data/lib/plugins/plugin_plugins.rb +81 -0
- data/lib/plugins/plugin_sqlite_db.rb +98 -0
- data/lib/plugins/pluginmanager.rb +635 -0
- data/lib/plugins/plugins.rb +169 -0
- data/lib/plugins/servlet.rb +108 -0
- data/lib/rsence.rb +32 -0
- data/lib/session/msg.rb +327 -0
- data/lib/session/sessionmanager.rb +522 -0
- data/lib/session/sessionstorage.rb +340 -0
- data/lib/transporter/transporter.rb +263 -0
- data/lib/util/gzstring.rb +9 -0
- data/lib/util/ruby19_fixes.rb +18 -0
- data/lib/values/hvalue.rb +378 -0
- data/lib/values/valuemanager.rb +172 -0
- data/plugins/client_pkg/client_pkg.rb +157 -0
- data/plugins/client_pkg/info.yaml +25 -0
- data/plugins/client_pkg/lib/client_pkg_build.rb +561 -0
- data/plugins/client_pkg/lib/client_pkg_cache.rb +50 -0
- data/plugins/client_pkg/lib/client_pkg_serve.rb +218 -0
- data/plugins/index_html/img/loading.gif +0 -0
- data/plugins/index_html/img/riassence.gif +0 -0
- data/plugins/index_html/index_html.rb +120 -0
- data/plugins/index_html/info.yaml +18 -0
- data/plugins/index_html/tmpl/index.html +15 -0
- data/plugins/main/info.yaml +18 -0
- data/plugins/main/js/main.js +84 -0
- data/plugins/main/main.rb +255 -0
- data/plugins/main/values.yaml +8 -0
- data/plugins/ticket/info.yaml +21 -0
- data/plugins/ticket/lib/common.rb +392 -0
- data/plugins/ticket/lib/favicon.rb +39 -0
- data/plugins/ticket/lib/file.rb +58 -0
- data/plugins/ticket/lib/img.rb +50 -0
- data/plugins/ticket/lib/objblob.rb +66 -0
- data/plugins/ticket/lib/rsrc.rb +34 -0
- data/plugins/ticket/lib/upload.rb +236 -0
- data/plugins/ticket/ticket.rb +333 -0
- data/setup/welcome/gui/welcome.yaml +92 -0
- data/setup/welcome/info.yaml +13 -0
- data/setup/welcome/text/welcome.html +9 -0
- data/setup/welcome/values.yaml +9 -0
- data/setup/welcome/welcome.rb +54 -0
- metadata +407 -0
@@ -0,0 +1,173 @@
|
|
1
|
+
= Overview
|
2
|
+
|
3
|
+
Each {file:PluginBundles plugin bundle} should contain an +info.yaml+ file.
|
4
|
+
|
5
|
+
The main purpose of the +info.yaml+ file is to provide meta-information to the {RSence::PluginManager PluginManager} about the bundle.
|
6
|
+
|
7
|
+
Using ruby notation, the defaults look like this:
|
8
|
+
@info = {
|
9
|
+
# The human-readable product name of the package
|
10
|
+
:title => bundle_name.to_s.capitalize,
|
11
|
+
|
12
|
+
# The human-readable version of the package
|
13
|
+
:version => '0.0.0',
|
14
|
+
|
15
|
+
# A brief description of the package (rdoc formatting supported)
|
16
|
+
:description => 'No Description',
|
17
|
+
|
18
|
+
# A flag (when false) prevents the plugin from automatically reload when changed.
|
19
|
+
:reloadable => true,
|
20
|
+
|
21
|
+
# Dependency, by default the system category (built-in plugins).
|
22
|
+
# A nil ( "~" in yaml ) value means no dependencies.
|
23
|
+
:depends_on => :system,
|
24
|
+
|
25
|
+
# Optional, name of category. The built-in plugins are :system
|
26
|
+
:category => nil
|
27
|
+
}
|
28
|
+
|
29
|
+
|
30
|
+
Using YAML notation, the same data would looks like this, if the name of the bundle in this example is "example_plugin":
|
31
|
+
!!!yaml
|
32
|
+
:title: Example_plugin
|
33
|
+
:version: 0.0.0
|
34
|
+
:description: 'No Description'
|
35
|
+
:reloadable: true
|
36
|
+
:depends_on: :system
|
37
|
+
:category: nil
|
38
|
+
|
39
|
+
When defining your own, not all of the key-value pairs need to be entered, just the ones that are different from the defaults. In this example the +:version+, +:description+ and +:title+ are defined:
|
40
|
+
!!!yaml
|
41
|
+
:title: Example Plugin
|
42
|
+
:version: 1.0.0
|
43
|
+
:description: |
|
44
|
+
This plugin is an example showing how to define the info.yaml file.
|
45
|
+
Besides that, no functionality is defined.
|
46
|
+
|
47
|
+
|
48
|
+
== Example 1: A set of plugins with dependency relationship
|
49
|
+
|
50
|
+
In this example, we have an user interface bundle named 'myapp' that uses a an user database wrapper 'myapp_users' for a database connection provided by another plugin called 'myapp_db', which defines the category +:myapp_support+, which is a practical way of defining groups of dependencies. One could then add other supporting plugins to do specific tasks, when the requirements of the application grows.
|
51
|
+
|
52
|
+
=== Files and directories of the example
|
53
|
+
|
54
|
+
The "plugins" directory of a RSence environment containing only the three plugins of this example would look like:
|
55
|
+
|
56
|
+
!!!text
|
57
|
+
plugins/
|
58
|
+
|-- myapp
|
59
|
+
| |-- gui
|
60
|
+
| | `-- main.yaml
|
61
|
+
| |-- info.yaml
|
62
|
+
| `-- main.rb
|
63
|
+
|-- myapp_db
|
64
|
+
| |-- info.yaml
|
65
|
+
| `-- main.rb
|
66
|
+
`-- myapp_users
|
67
|
+
|-- info.yaml
|
68
|
+
`-- main.rb
|
69
|
+
|
70
|
+
=== A plugin bundle named 'myapp_db'
|
71
|
+
|
72
|
+
The +info.yaml+ can also used to store settings. In this example, database connection parameters:
|
73
|
+
!!!yaml
|
74
|
+
:title: MyApp DB
|
75
|
+
:version: 0.1.3
|
76
|
+
:description: This plugin provides connectivity to the FooBase database server.
|
77
|
+
:category: :myapp_support
|
78
|
+
:settings:
|
79
|
+
:host: '10.0.0.172'
|
80
|
+
:port: 12345
|
81
|
+
:database: example_database
|
82
|
+
:username: foobert
|
83
|
+
:password: n0ts0s3cr3t
|
84
|
+
:db_keys:
|
85
|
+
- abc123
|
86
|
+
- foobar
|
87
|
+
- 123456
|
88
|
+
|
89
|
+
This information could then be read inside a plugin code like this:
|
90
|
+
|
91
|
+
require 'foo_orm'
|
92
|
+
|
93
|
+
# Provides connectivity to the FooBase user database using the FooBasePlugin
|
94
|
+
class FooBasePlugin < Plugin
|
95
|
+
|
96
|
+
# Opens database connection after plugin is loaded
|
97
|
+
def open
|
98
|
+
@db = FooORM.new( database_connection_string )
|
99
|
+
super
|
100
|
+
end
|
101
|
+
|
102
|
+
# Closes database connection before plugin is unloaded
|
103
|
+
def close
|
104
|
+
@db.disconnect
|
105
|
+
super
|
106
|
+
end
|
107
|
+
|
108
|
+
# Returns database connection with very basic data access restriction
|
109
|
+
def db( db_key )
|
110
|
+
return nil unless @info[:settings][:db_keys].include?( db_key )
|
111
|
+
return @db
|
112
|
+
end
|
113
|
+
|
114
|
+
private
|
115
|
+
|
116
|
+
# Returns database connection string according to the settings.
|
117
|
+
# @return [String] FooBase connection string.
|
118
|
+
def database_connection_string
|
119
|
+
s = @info[:settings]
|
120
|
+
# Returns "foobase://foobert:n0ts0s3cr3t@10.0.0.172:12345/example_database" when using the default settings
|
121
|
+
"foobase://#{s[:username]}:#{s[:password]}@#{s[:host]}:#{s[:port]}/#{s[:database]}"
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
125
|
+
|
126
|
+
=== A plugin bundle named 'myapp_users'
|
127
|
+
|
128
|
+
Here, the +info.yaml+ document depends on the +:myapp_db+ plugin defined above.
|
129
|
+
!!!yaml
|
130
|
+
:title: MyApp Users
|
131
|
+
:version: 0.0.1
|
132
|
+
:description: This plugin provides an interface to access user information using FooBasePlugin
|
133
|
+
:depends_on: :myapp_db
|
134
|
+
:category: :myapp_support
|
135
|
+
:settings:
|
136
|
+
:db_key: foobar
|
137
|
+
|
138
|
+
Code example:
|
139
|
+
|
140
|
+
# Provides the user_name method to MyApp
|
141
|
+
class MyAppUsersPlugin < Plugin
|
142
|
+
|
143
|
+
# Returns the user name that has the id provided by selecting it from the users table.
|
144
|
+
def user_name( user_id )
|
145
|
+
db_key = @info[:settings][:db_key]
|
146
|
+
db = @plugins.myapp_db.db( db_key )
|
147
|
+
unless db
|
148
|
+
warn "Invalid database key: #{db_key.inspect}"
|
149
|
+
return "[Database Error]"
|
150
|
+
end
|
151
|
+
user_info = db[:users].filter(:id => user_id).first
|
152
|
+
return "[Unknown User]" unless user_info
|
153
|
+
return user_info[:user_name]
|
154
|
+
end
|
155
|
+
|
156
|
+
end
|
157
|
+
|
158
|
+
=== A plugin bundle named 'myapp'
|
159
|
+
Another plugin depending on the two plugins above may set it as a dependency if its +info.yaml+ is defined like this:
|
160
|
+
!!!yaml
|
161
|
+
:title: MyApp
|
162
|
+
:version: 0.2.0
|
163
|
+
:description: This application does fancy stuff using FooBasePlugin.
|
164
|
+
:depends_on: :myapp_support
|
165
|
+
|
166
|
+
Defining the dependency like above ensures the 'foobase' plugin will be available when this code is run:
|
167
|
+
class MyAppPlugin < GUIPlugin
|
168
|
+
def gui_params( msg )
|
169
|
+
params = super
|
170
|
+
params[:greeting] = 'Welcome, ' + @plugins.myapp_users.user_name( msg.user_id )
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
@@ -0,0 +1,96 @@
|
|
1
|
+
|
2
|
+
= Overview
|
3
|
+
Plugin bundles are the "building blocks" of RSence applications.
|
4
|
+
A bundle is a directory that groups together the software code
|
5
|
+
and its related resources.
|
6
|
+
|
7
|
+
Plugin bundles are constructed of at least a directory and a ruby
|
8
|
+
source file either named "main.rb" or the same name as the
|
9
|
+
directory plus + ".rb".
|
10
|
+
|
11
|
+
The main ruby file has to contain at least one class extended from one
|
12
|
+
of the three types of plugins:
|
13
|
+
- {RSence::Plugins::Plugin__ Plugin}, which is the simplest main logic plugin model.
|
14
|
+
- {RSence::Plugins::GUIPlugin__ GUIPlugin}, which is an extended model of plugin with built-in user interface support.
|
15
|
+
- {RSence::Plugins::Servlet__ Servlet}, which is a "traditional" request/response handler for GET/POST url's.
|
16
|
+
|
17
|
+
== Example 1: A very simple plugin bundle structure
|
18
|
+
!!!plain
|
19
|
+
simple_plugin/
|
20
|
+
`-- main.rb
|
21
|
+
|
22
|
+
=== Simplest possible contents of the "main.rb" as above
|
23
|
+
class SimplePlugin < Plugin
|
24
|
+
end
|
25
|
+
|
26
|
+
A plugin like this just gets registered as a plugin named :simple_plugin when RSence finds it in one of its "plugins" directories. By default, one "plugins" directory is distributed as a part of RSence and contains some core services common to most applications. The other is the "plugins" directory inside your RSence project environment directory.
|
27
|
+
|
28
|
+
To make the plugin do something useful, extend its model. To know more about that, just read the documentation about the model classes: {RSence::Plugins::Plugin__ Plugin}, {RSence::Plugins::GUIPlugin__ GUIPlugin}, {RSence::Plugins::Servlet__ Servlet}.
|
29
|
+
|
30
|
+
=== Extending the simple plugin to say "Hello" to your web browser's javascript console.
|
31
|
+
class SimplePlugin < Plugin
|
32
|
+
def init_ui( msg )
|
33
|
+
msg.console( "Hello" )
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
== Example 2: {file:ExampleGuiPlugin The "welcome" GUIPlugin bundle}
|
38
|
+
This example is rather lengthy, so read it {file:ExampleGuiPlugin here}.
|
39
|
+
|
40
|
+
|
41
|
+
= Plugin meta-information files
|
42
|
+
|
43
|
+
These files are optional parts of a bundle, but are supported by the system. Most bundles will contain several other files as well, as defined by each bundle's software code.
|
44
|
+
|
45
|
+
=== Supported by all bundle types, including {RSence::Plugins::Servlet__ Servlet}:
|
46
|
+
- An {file:PluginBundleInfo info.yaml file}
|
47
|
+
- Defines the meta-information about the bundle, like its name, description, version, system requirements, dependencies etc.
|
48
|
+
- Each bundle *should* include an +info.yaml+ file.
|
49
|
+
- Any extra information, like default settings of the plugin itself can be stored here
|
50
|
+
|
51
|
+
=== Supported by {RSence::Plugins::Plugin__ Plugin} and {RSence::Plugins::GUIPlugin__ GUIPlugin} bundles:
|
52
|
+
- A {file:Values values.yaml file}
|
53
|
+
- Defines the default client-server {RSence::HValue HValue} objects to create for each user session.
|
54
|
+
- Contains what the default data is for each value.
|
55
|
+
- Defines if the data should be reset when the page is reloaded.
|
56
|
+
- Defines if the data should be the return-value of a plugin method.
|
57
|
+
- Binds the values to responder methods.
|
58
|
+
- Defines which plugins to bind
|
59
|
+
- The plugin defaults to the plugin bundle which defined the method
|
60
|
+
- Defines which methods to bind
|
61
|
+
- When the data of the value is changed by the client, the system calls the bound plugin methods to respond to and validate the data.
|
62
|
+
|
63
|
+
=== Supported by {RSence::Plugins::GUIPlugin__ GUIPlugin} bundles:
|
64
|
+
- A {file:JavascriptBundles client_pkgs.yaml file}
|
65
|
+
- Defines the packages of any extra javascript bundles and their themes, when contained in the bundle.
|
66
|
+
- The contents of the packages are loaded and built automatically by the built-in {ClientPkgPlugin +client_pkg+} plugin.
|
67
|
+
- A {file:GUITreeYaml gui/main.yaml file}
|
68
|
+
- Instead of +main.yaml+, can optionally be named like +simple_plugin.yaml+ if the bundle name is +simple_plugin+
|
69
|
+
- Defines structure of the default user interface.
|
70
|
+
- Defines client-side {RSence::HValue value} bindings
|
71
|
+
- The values used must be defined, like using the {file:Values +values.yaml+} file
|
72
|
+
- May define other mappings, like localized strings and other static data.
|
73
|
+
- The system builds a user interface based on this file automatically when a RSence web page is loaded (and reloaded) by the user.
|
74
|
+
|
75
|
+
= Values and data transfer
|
76
|
+
The description is rather lengthy, so it's in its own document {file:Values HERE}.
|
77
|
+
|
78
|
+
= Messages and sessions
|
79
|
+
As a side effect of having the same instances of plugins serve the requests of all sessions, the request/response/session messaging is implemented as messaging objects. These objects contain or delegate all the necessary hooks required by the complete request/response cycle.
|
80
|
+
|
81
|
+
The naming convention of the {RSence::Message Message} instance is +msg+ and it's given as the first parameter of methods using it directly.
|
82
|
+
|
83
|
+
Use {RSence::Message#session_id +msg.session_id+} to identify the session's serial number and {RSence::Message#user_id +msg.user_id+} to identify the user's identity. Both are Numbers.
|
84
|
+
|
85
|
+
Use the {RSence::Message#session +msg.session+} +Hash+ to store any persistent data associated with the user's session, preferably using the name of the plugin or its registered name as the primary key entry in the Hash. To do so automatically, just call the {RSence::Plugins::Plugin__#get_ses +get_ses+} method in your Plugin or GUIPlugin.
|
86
|
+
|
87
|
+
The session data is persistent; it's stored in the session database by the main {RSence::SessionStorage SessionStorage} instance automatically, if a database connection string is properly configured.
|
88
|
+
|
89
|
+
The +msg+ also provides access to the {RSence::Request +msg.request+} and {RSence::Response +msg.response+} objects directly, but don't mess around with them unless you know exactly what you are doing.
|
90
|
+
|
91
|
+
Use the {RSence::PluginManager#method_missing +@plugins+} object to call other plugins, like this:
|
92
|
+
@plugins.plugin_name.method_name( param1, param2 )
|
93
|
+
|
94
|
+
To append Javascript source code to be executed in the client, use the {RSence::Message#reply +msg.reply+} method. The {RSence::Message#console +msg.console+} method displays debugging messages in the browser's Javascript console.
|
95
|
+
|
96
|
+
|
data/docs/Values.rdoc
ADDED
@@ -0,0 +1,163 @@
|
|
1
|
+
= Overview
|
2
|
+
The data exchange system exists to support bi-directional data synchronization between the browser and the plugin. The values are stored in the session as +HValue+ instances.
|
3
|
+
|
4
|
+
Values support Hashes, Arrays, Strings, Numbers, Booleans and logically correct combinations of those. The data is automatically converted between ruby objects (server) and json objects (client). For dates and times, use Numbers as seconds since or before UTC epoch; (1970-01-01 00:00:00.0 equals 0.0) and convert accordingly for the representation intended.
|
5
|
+
|
6
|
+
Each instance may be bound to plugin methods that are used as value change notification responders.
|
7
|
+
|
8
|
+
When a method is bound to the value, the method is called as an event notification whenever the client has changed the value and synchronizes it to the server. The responders act as validators by default.
|
9
|
+
|
10
|
+
Values may be bound in the client to instances of classes that implement the HValueResponder interface, like any derivate of HControl. See the client documentation for instructions about using them.
|
11
|
+
|
12
|
+
To define a value responder method, it needs to respond to exactly two parameters: {RSence::Message +msg+} and {RSence::HValue +value+} (in that specific order). The method's return value must be either +true+ or +false+. When the method returns +false+, the change is discarded and the previously server-set value is sent back to the client.
|
13
|
+
|
14
|
+
= Defining values
|
15
|
+
The simplest and recommended way of defining the values is to define the value configuration file +values.yaml+ at the root level of your plugin bundle. The definition is then copied to each session automatically. Values created using +values.yaml+ files are accessible by their name in each user's session object.
|
16
|
+
|
17
|
+
For instance, if a value has been defined as +:myvalue+, it's accessible in code like this:
|
18
|
+
ses = get_ses(msg) # gets the session object of the local plugin
|
19
|
+
my_value = ses[:myvalue] # reference to the value instance
|
20
|
+
|
21
|
+
=== Syntax reference of the contents of a +values.yaml+ file:
|
22
|
+
|
23
|
+
The name of the value, +:value_name+ in this case. It's a Hash key in the yaml syntax
|
24
|
+
!!!yaml
|
25
|
+
:value_name:
|
26
|
+
|
27
|
+
Definitions of the value; all definitions are optional.
|
28
|
+
|
29
|
+
The static value definition, a string "Foo" in this case. The default is +0+
|
30
|
+
!!!yaml
|
31
|
+
:value: Foo
|
32
|
+
|
33
|
+
A plugin method to call to define the default value dynamically instead of the static value defined in +:value+
|
34
|
+
!!!yaml
|
35
|
+
:value_call:
|
36
|
+
|
37
|
+
The name of the plugin where the responder method is found. It Defaults to the plugin where defined
|
38
|
+
!!!yaml
|
39
|
+
:plugin: plugin_name
|
40
|
+
|
41
|
+
The name of the responder method. Mandatory item when defining a value call. In this case a method named +method_name+
|
42
|
+
!!!yaml
|
43
|
+
:method: method_name
|
44
|
+
|
45
|
+
Optionally, list of parameters for the +:method+ in the order of defined. In this case, three parameters: 1, 'foo' and 3
|
46
|
+
!!!yaml
|
47
|
+
:args:
|
48
|
+
- 1
|
49
|
+
- foo
|
50
|
+
- 3
|
51
|
+
|
52
|
+
If +:uses_msg+ is set to false, the {RSence::Message +msg+} won't be passed as the first parameter to the +:method+. It's +true+ by default.
|
53
|
+
!!!yaml
|
54
|
+
:uses_msg: false
|
55
|
+
|
56
|
+
Restores the default, when the session is restored (page reload etc); defaults to +true+
|
57
|
+
!!!yaml
|
58
|
+
:restore_default: false
|
59
|
+
|
60
|
+
List of value responder methods to bind.
|
61
|
+
!!!yaml
|
62
|
+
:responders:
|
63
|
+
|
64
|
+
The name of the plugin and the method to bind. The plugin defaults to the plugin where defined. The responder methods always use the convention (+msg+, +value+) as their parameters.
|
65
|
+
!!!yaml
|
66
|
+
- :plugin: plugin_name
|
67
|
+
:method: method_name
|
68
|
+
|
69
|
+
Another responder, this one using the same plugin where defined:
|
70
|
+
!!!yaml
|
71
|
+
- :method: another_method
|
72
|
+
|
73
|
+
==== Example 1:
|
74
|
+
A value defined using only the defaults by supplying an empty Hash: { value: 0, default restored, no responders or calls }
|
75
|
+
!!!yaml
|
76
|
+
:value_with_defaults: {}
|
77
|
+
|
78
|
+
==== Example 2:
|
79
|
+
This value defines a Number (123) and doesn't restore the default, when restoring the session.
|
80
|
+
!!!yaml
|
81
|
+
:one_two_three:
|
82
|
+
:value: 123
|
83
|
+
:restore_default: false
|
84
|
+
|
85
|
+
==== Example 3:
|
86
|
+
This value gets a random string and specifies a responder, that ensures it's unique, if changed in the client. (Such methods aren't predefined).
|
87
|
+
!!!yaml
|
88
|
+
:random_unique_string:
|
89
|
+
:value_call:
|
90
|
+
:method: get_unique_random_string
|
91
|
+
:uses_msg: false
|
92
|
+
:responders:
|
93
|
+
- :method: ensure_unique_random_string
|
94
|
+
|
95
|
+
|
96
|
+
= Using values in code
|
97
|
+
|
98
|
+
=== Creating a HValue object in ruby and creates the client representation automatically.
|
99
|
+
Sometimes dynamic value allocation is required. In these cases, use {RSence::HValue HValue} directly in the plugin's ruby code (or any library code that gets a +msg+).
|
100
|
+
a_test_value = HValue.new( msg, 'any_json_mappable_data' )
|
101
|
+
|
102
|
+
=== A minimal value responder method is defined like this:
|
103
|
+
def my_value_responder( msg, my_value )
|
104
|
+
return true
|
105
|
+
end
|
106
|
+
|
107
|
+
=== To access the content of the value, use the {RSence::HValue#data +value.data+} attribute.
|
108
|
+
def int_between_100_and_200( msg, value )
|
109
|
+
data = value.data.to_i
|
110
|
+
return ( data >= 100 and data <= 200 )
|
111
|
+
end
|
112
|
+
|
113
|
+
=== To change the content of the value, use the {RSence::HValue#set +value.set+} method.
|
114
|
+
def int_between_100_and_200( msg, value )
|
115
|
+
data = value.data.to_i
|
116
|
+
value.set( msg, 100 ) if data < 100
|
117
|
+
value.set( msg, 200 ) if data > 200
|
118
|
+
return true
|
119
|
+
end
|
120
|
+
|
121
|
+
=== Setting a HValue object in ruby.
|
122
|
+
Doing the change in ruby sets the client-side accordingly too and causes all client-bound value responders to receive the same data. automatically. The data is synchronized server-client after all server responders have responded to all triggers by the last client-server synchronization, so only the lastly set data of a value is sent to the client.
|
123
|
+
a_test_value.set( msg, 'this_wont_be_on_the_client' )
|
124
|
+
a_test_value.set( msg, ['neither','will','this','be',[true]] )
|
125
|
+
a_test_value.set( msg, { 'and' => 'this', 'also' => 'stays', 'in' => 'the', 'server' => [1,2,3,4] )
|
126
|
+
a_test_value.set( msg, 'this is the last one, this gets through' )
|
127
|
+
|
128
|
+
=== Binding a HValue responder in ruby. Causes the client-server synchronization to respond to all the bound methods.
|
129
|
+
class SomeTestPlugin < Plugin
|
130
|
+
def resp_one( msg, value )
|
131
|
+
puts "got data: #{value.data.inspect}"
|
132
|
+
return true
|
133
|
+
end
|
134
|
+
def resp_two( msg, value )
|
135
|
+
revert_to = "foo foo"
|
136
|
+
value.set( msg, revert_to )
|
137
|
+
puts "got the data too, but changed it to: #{value.data.inspect}"
|
138
|
+
return true
|
139
|
+
end
|
140
|
+
def define_responders( msg )
|
141
|
+
...
|
142
|
+
# the @name is the name of the plugin bundle
|
143
|
+
a_test_value.bind( @name, :resp_one )
|
144
|
+
a_test_value.bind( @name, :resp_two )
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
=== Referring to the value manually in the client, using the server
|
149
|
+
This references the value by id in the client scope and binds it to a new instance of the +HTextArea+ component with its own dedicated app instance.
|
150
|
+
msg.reply( "COMM.Values.values[#{a_test_value.value_id.to_json}].bind( HTextArea.nu( [0,0,100,100], HApplication.nu() ) );" )
|
151
|
+
|
152
|
+
=== Storing a reference to a variable in the session scope.
|
153
|
+
Allows you to retrieve this session-specific object in any scope with access to the same session's +msg+, even in other requests (and server restarts, when a {RSence::SessionStorage SessionStorage} database connection is enabled).
|
154
|
+
get_ses(msg)[:the_test_name] = a_test_value
|
155
|
+
|
156
|
+
=== Freeing a HValue responder, won't be used as a responder anymore
|
157
|
+
a_test_value.release( @name, :resp_two )
|
158
|
+
|
159
|
+
=== Freeing all responders of a value
|
160
|
+
a_test_value.release_all
|
161
|
+
|
162
|
+
=== Destructing a value, releases all bindings on both client and server and destructs the client representation too
|
163
|
+
a_test_value.die!( msg )
|
@@ -0,0 +1,17 @@
|
|
1
|
+
/* RSence
|
2
|
+
* Copyright 2009 Riassence Inc.
|
3
|
+
* http://riassence.com/
|
4
|
+
*
|
5
|
+
* You should have received a copy of the GNU General Public License along
|
6
|
+
* with this software package. If not, contact licensing@riassence.com
|
7
|
+
*/
|
8
|
+
|
9
|
+
// Starts the synchronization upon page load.
|
10
|
+
LOAD(
|
11
|
+
function(){
|
12
|
+
COMM.urlResponder=COMM.URLResponder.nu();
|
13
|
+
COMM.Transporter.url=COMM.Transporter.HelloUrl;
|
14
|
+
COMM.Transporter.stop=false;
|
15
|
+
COMM.Transporter.sync();
|
16
|
+
}
|
17
|
+
);
|
File without changes
|
data/js/comm/comm.js
ADDED
@@ -0,0 +1,203 @@
|
|
1
|
+
/* RSence
|
2
|
+
* Copyright 2009 Riassence Inc.
|
3
|
+
* http://riassence.com/
|
4
|
+
*
|
5
|
+
* You should have received a copy of the GNU General Public License along
|
6
|
+
* with this software package. If not, contact licensing@riassence.com
|
7
|
+
*/
|
8
|
+
|
9
|
+
|
10
|
+
/*** = Description
|
11
|
+
** XMLHttpRequest abstractor, and handler and utilities.
|
12
|
+
** The only public method is +request+
|
13
|
+
** The namespace also holds the following services:
|
14
|
+
**
|
15
|
+
** Service Name:: Service Description
|
16
|
+
** +COMM.Queue+:: Singleton, used for queuing tasks
|
17
|
+
** awaiting asynchronous requests to complete.
|
18
|
+
** +COMM.Session+:: Session key secure hashing service.
|
19
|
+
** +COMM.SessionWatcher+:: Polls server at regular intervals by reporting
|
20
|
+
** the client's local time.
|
21
|
+
** +COMM.Transporter+:: Automated synchronization service, pulls server
|
22
|
+
** data, tasks etc. The main server interface.
|
23
|
+
** +COMM.Values+:: Data value manager, handles synchronized data in
|
24
|
+
** both directions (server-client-server).
|
25
|
+
** +COMM.JSLoader+:: Loads Javascript libraries asynchronously.
|
26
|
+
** +COMM.JSONRenderer+:: Constructs nodes from JSON structures as GUI
|
27
|
+
** tree structures. Lowers the learning curve of GUI
|
28
|
+
** development, because Javascript knowledge is not
|
29
|
+
** required to define user interfaces.
|
30
|
+
** The main purpose is to ease the development of
|
31
|
+
** user interfaces by defining them as data on the
|
32
|
+
** server, converting the data to JSON GUI trees and
|
33
|
+
** letting the client handle the rest. The end result
|
34
|
+
** is the same as defining the structures in
|
35
|
+
** JavaScript code.
|
36
|
+
**
|
37
|
+
***/
|
38
|
+
var//RSence
|
39
|
+
COMM = {
|
40
|
+
|
41
|
+
/** Displays an error alert, if the browser doesn't support XMLHttpRequests
|
42
|
+
**/
|
43
|
+
_FakeHttpRequest: function(){
|
44
|
+
alert("'ERROR: This web browser doesn't support XMLHttpRequest. Please upgrade; unable to continue.");
|
45
|
+
},
|
46
|
+
|
47
|
+
/** = Description
|
48
|
+
* Finds and calls the state responder method upon a readyState change to 4.
|
49
|
+
* - On readyStates other than 4 does nothing.
|
50
|
+
* - The default responder for a successful response code (between 200 to 299) is onSuccess.
|
51
|
+
* - The default responder for unsuccessful response codes is onFailure.
|
52
|
+
* - The responders are called with the request object as the parameter.
|
53
|
+
* - Custom response code handling is implemented as 'on' + status code,
|
54
|
+
* eg. 'on404' for a 404 not found error.
|
55
|
+
**/
|
56
|
+
_stateChange: function(_this){
|
57
|
+
if(_this.X.readyState === 4){
|
58
|
+
var _status = _this.X.status,
|
59
|
+
_responderName = 'on'+_status,
|
60
|
+
_success = ((_status >= 200 && _status < 300) || (_status === 0));
|
61
|
+
_this[_responderName]?_this[_responderName](_this):_success?_this.onSuccess(_this):_this.onFailure(_this);
|
62
|
+
}
|
63
|
+
},
|
64
|
+
|
65
|
+
/** = Description
|
66
|
+
* Converts arrays to valid query strings.
|
67
|
+
*
|
68
|
+
* = Usage
|
69
|
+
* Returns 'productId=100&customerName=J-J%20Heinonen'
|
70
|
+
* COMM._arrayToQueryString(['productId',100,'customerName','J-J Heinonen'])
|
71
|
+
*
|
72
|
+
**/
|
73
|
+
_arrayToQueryString: function(_params){
|
74
|
+
var i = 0,
|
75
|
+
_length = _params.length,
|
76
|
+
_queryString = '';
|
77
|
+
for(;i<_length;i++){
|
78
|
+
_queryString += encodeURIComponent(_params[i]);
|
79
|
+
_queryString += (i===_length-1)?'':(i%2===0)?'=':'&';
|
80
|
+
}
|
81
|
+
return _queryString;
|
82
|
+
},
|
83
|
+
|
84
|
+
/** = Description
|
85
|
+
* The main Request-handling object. Provides a general and fairly easy to use
|
86
|
+
* interface for making "Ajax" requests.
|
87
|
+
*
|
88
|
+
* = Parameters
|
89
|
+
* +_url+:: Full or relative url of the response handler
|
90
|
+
* +_options+:: An +Object+, see below for content:
|
91
|
+
*
|
92
|
+
*
|
93
|
+
* == Required properties for +_options+:
|
94
|
+
* +onSuccess+:: A function that is called on a successful response.
|
95
|
+
* Must accept one parameter: the request object.
|
96
|
+
* +onFailure+:: A function that is called on an unsuccessful response.
|
97
|
+
* Must accept one parameter: the request object.
|
98
|
+
*
|
99
|
+
* == Optional properties for +_options+:
|
100
|
+
* +method+:: The HTTP Request Method, usually 'POST' or 'GET', but will handle
|
101
|
+
* DAV and other extensions if the server supports them.
|
102
|
+
* Defaults to 'POST'.
|
103
|
+
* +async+:: Boolean; Uses asyncronous requests when true.
|
104
|
+
* Defaults to true.
|
105
|
+
* +params+:: Extra parameters to send, format: Array, see COMM._arrayToQueryString()
|
106
|
+
* +headers+:: Extra HTTP headers to send for POST requests, format: Hash.
|
107
|
+
* +body+:: The HTTP POST Body
|
108
|
+
* +username+:: Username for basic authentication
|
109
|
+
* +password+:: Password for basic authentication
|
110
|
+
* +contentType+:: The 'content-type' -header to send.
|
111
|
+
* Defaults to 'application/x-www-form-urlencoded'.
|
112
|
+
* +charset+:: The charset type to use. Defaults to 'UTF-8'.
|
113
|
+
*
|
114
|
+
* = Returns
|
115
|
+
* An +Object+ extended from the +_options+ given in the input.
|
116
|
+
*
|
117
|
+
**/
|
118
|
+
request: function(_url,_options){
|
119
|
+
var _comm = COMM,
|
120
|
+
|
121
|
+
_this = _options?_options:{},
|
122
|
+
|
123
|
+
_method = _options.method?_options.method.toUpperCase():'GET',
|
124
|
+
_async = (_options.async===undefined)?true:_options.async,
|
125
|
+
_params = _options.params?_options.params:[],
|
126
|
+
_headers = _options.headers?_options.headers:{},
|
127
|
+
_contentType = _options.contentType?_options.contentType:'application/x-www-form-urlencoded',
|
128
|
+
_charset = _options.charset?_options.charset:'UTF-8',
|
129
|
+
_username = _options.username?_options.username:null,
|
130
|
+
_password = _options.username?_options.password:null;
|
131
|
+
if(!_options.onFailure){
|
132
|
+
_this.onFailure = function(resp){console.log('No failure handler specified, response: ',resp);};
|
133
|
+
}
|
134
|
+
if(!_options.onSuccess){
|
135
|
+
_this.onSuccess = function(resp){console.log('No success handler specified, response: ',resp);};
|
136
|
+
}
|
137
|
+
if(!_options.on302){
|
138
|
+
/** Redirection handler **/
|
139
|
+
_this.on503 = function(_this){
|
140
|
+
var _retryAfter = parseInt(_this.X.getResponseHeader('Retry-After'),10)*1000,
|
141
|
+
_timeout = setTimeout(function(){COMM.request(_this.url,_this.options);},_retryAfter);
|
142
|
+
};
|
143
|
+
}
|
144
|
+
_this.url = _url;
|
145
|
+
_this.options = _options;
|
146
|
+
_this.X = _comm._XMLHttpRequest();
|
147
|
+
if(_method === 'GET' && _params.length !== 0){
|
148
|
+
_url += ((_url.indexOf('?')!==-1)?'&':'?')+_comm._arrayToQueryString(_params);
|
149
|
+
}
|
150
|
+
if(!_async){
|
151
|
+
console.log("WARNING: Synchronous "+_method+" request to "+_url+", these will fail on the Symbian web browser.");
|
152
|
+
}
|
153
|
+
_this.X.open(
|
154
|
+
_method,
|
155
|
+
_url,
|
156
|
+
_async,
|
157
|
+
_username,
|
158
|
+
_password
|
159
|
+
);
|
160
|
+
_this.X.onreadystatechange = function(){
|
161
|
+
_comm._stateChange(_this);
|
162
|
+
};
|
163
|
+
if(_method === 'POST'){
|
164
|
+
_headers['Content-Type'] = _contentType + '; charset=' + _charset;
|
165
|
+
var _body = _options.body?_options.body:'';
|
166
|
+
for(var _header in _headers){
|
167
|
+
_this.X.setRequestHeader(_header,_headers[_header]);
|
168
|
+
}
|
169
|
+
_this.X.send(_body);
|
170
|
+
}
|
171
|
+
else if(_method === 'GET'){
|
172
|
+
_this.X.send(null);
|
173
|
+
}
|
174
|
+
if(!_async){
|
175
|
+
_comm._stateChange(_this);
|
176
|
+
}
|
177
|
+
return _this;
|
178
|
+
}
|
179
|
+
};
|
180
|
+
|
181
|
+
/** = Description
|
182
|
+
* Creates a new instance of the XMLHttpRequest
|
183
|
+
* object supported by the browser. Evaluated only once,
|
184
|
+
* after that does its things without any extra statements
|
185
|
+
*
|
186
|
+
**/
|
187
|
+
if(window['XMLHttpRequest']!==undefined){
|
188
|
+
COMM._XMLHttpRequest = function(){
|
189
|
+
return new XMLHttpRequest();
|
190
|
+
};
|
191
|
+
}
|
192
|
+
else if(window.ActiveXObject){
|
193
|
+
COMM._XMLHttpRequest = function(){
|
194
|
+
return new ActiveXObject("Microsoft.XMLHTTP");
|
195
|
+
};
|
196
|
+
}
|
197
|
+
else {
|
198
|
+
COMM._XMLHttpRequest = function(){
|
199
|
+
console.log("No XMLHttpRequest object types known. Can't Communicate.");
|
200
|
+
return new COMM._FakeHttpRequst();
|
201
|
+
};
|
202
|
+
}
|
203
|
+
|
data/js/comm/js.inc
ADDED
File without changes
|
File without changes
|