[gantry] r1489 committed - Whitespace cleanup

6 views
Skip to first unread message

codesite...@google.com

unread,
Apr 5, 2011, 2:06:11 PM4/5/11
to gan...@googlegroups.com
Revision: 1489
Author: net.a...@gmail.com
Date: Tue Apr 5 11:05:25 2011
Log: Whitespace cleanup
http://code.google.com/p/gantry/source/detail?r=1489

Modified:
/trunk/root/js/ajaxForm.js
/trunk/root/js/ajaxResults.js

=======================================
--- /trunk/root/js/ajaxForm.js Mon Apr 4 09:08:43 2011
+++ /trunk/root/js/ajaxForm.js Tue Apr 5 11:05:25 2011
@@ -34,7 +34,7 @@
var left = 150;

// Set css defaults for bui popup form.
- gantryAjaxFormBuiCss = {
+ gantryAjaxFormBuiCss = {
top: top,
left: offset.left + left,
width: '425px',
@@ -45,9 +45,9 @@
opacity: '1',
color: '#000'
};
-
- // Set css defaults for bui popup error form.
- gantryAjaxErrorFormBuiCss = {
+
+ // Set css defaults for bui popup error form.
+ gantryAjaxErrorFormBuiCss = {
width: '300px',
border: 'none',
padding: '15px',
@@ -57,7 +57,7 @@
opacity: '.8',
color: '#fff'
};
-
+
/**
*
* function: $j.address.change(fn)
@@ -65,25 +65,25 @@
* parameters: event
*
* description: Method that gets called when navigation changes occur.
- * event object contains the following:
- * value - url including query string.
- * path - url minus the query string.
- * pathNames - comma separated list of each part of the path.
- * parameterNames - comma separated list of parameter names.
- * parameters - object containing parameter values.
- * queryString - url query string.
- *
+ * event object contains the following:
+ * value - url including query string.
+ * path - url minus the query string.
+ * pathNames - comma separated list of each part
of the path.
+ * parameterNames - comma separated list of
parameter names.
+ * parameters - object containing parameter
values.
+ * queryString - url query string.
+ *
*/
- $j.address.change(function(event) {
- if (event.value == '/') {
- if (blocking == true) {
- $j.unblockUI();
- }
- }
- else {
- gantryAjaxDisplayForm(event.path, event.parameters.gftype,
event.parameters.eftype);
- }
- });
+ $j.address.change(function(event) {
+ if (event.value == '/') {
+ if (blocking == true) {
+ $j.unblockUI();
+ }
+ }
+ else {
+ gantryAjaxDisplayForm(event.path, event.parameters.gftype,
event.parameters.eftype);
+ }
+ });
});

/**
@@ -93,553 +93,553 @@
* parameters: formType, json
*
* description: Given the type of form (currently bui or inline) and a json
-* representation of a gantry form, it will render the form
-* to the page. bui type forms use the blockUI jquery plugin
-* to create a blocking popup form. Inline forms will replace
-* the content on the page with output of the form.
+* representation of a gantry form, it will render the form
+* to the page. bui type forms use the blockUI jquery plugin
+* to create a blocking popup form. Inline forms will
replace
+* the content on the page with output of the form.
*/
function gantryAjaxRenderForm (formType, json) {
- var fieldsets = [];
- var cfsgroup = {};
- var jform = $j(
- $j.sprintf(
- '<form action="%s" method="post" class="form-box">' +
- '<div class="form-box">' +
- '</div>' +
- '</form>',
- json.form.action
- )
- );
- var ajaxFormOptions = {
- 'dataType' : 'json',
- 'success' : function (result_json, status_text) {
- // Response contains a form...
- if (result_json.form != null) {
- // Set form action to original form action if none was specified.
- if (result_json.form.action == null) {
- result_json.form.action = json.form.action;
- }
-
- gantryAjaxRenderForm(formType, result_json);
- }
- // Response contains results.
- else if (result_json.headings != null) {
- gantryAjaxRenderResults(result_json);
- $j.address.value('/');
- }
- else {
- $j.address.value('/');
- }
- },
- };
-
- // Add any specified callbacks to the options.
- for (var cb in gantryAjaxFormOptions) {
- alert(cb);
- ajaxFormOptions[cb] = gantryAjaxFormOptions[cb];
- }
-
- // Handle form error summary.
- if (json.form.results != null && json.form.show_error_summary == 1) {
- if (json.form.results.msgs.group_by_field == 1) {
- var invalid = false;
- var missing = false;
-
- // Check for invalid.
- for (var i in json.form.results.invalid) {
- invalid = true;
- }
-
- // Check for missing.
- for (var i in json.form.results.missing) {
- missing = true;
- }
-
- // If there are any invalid or missing fields...
- if (invalid || missing) {
- var jep = $j('<p class="missing" style="color: red"></p>');
-
- for (var i = 0; i < json.form.fields.length; i++) {
- var field = json.form.fields[i];
-
- if (json.form.results.invalid[field.name] ||
json.form.results.missing[field.name]) {
- jep.append(
- $j.sprintf(
- '<b>%s:</b> %s<br />',
- field.label,
- json.form.results.msgs[field.name]
- )
- );
- }
- }
-
- jform.prepend(jep);
- }
- }
- }
-
- // Init cfsgroup.
- cfsgroup.legend = 'gantry-default';
- cfsgroup.fields = [];
-
- // Output any message contained in the form.
- if (json.form.message != null) {
- jform.find('div').append(
- $j.sprintf(
- '<div class="msg">%s</div>',
- json.form.message
- )
- );
- }
-
- if (json.form.fields != null) {
- // Foreach over the fields and add them to the fieldset.
- for (var i = 0; i < json.form.fields.length; i++) {
- var field = json.form.fields[i];
-
- if (field.fieldset != null && field.fieldset != cfsgroup.legend) {
- if (cfsgroup.fields.length > 0) {
- fieldsets.push(cfsgroup);
- }
-
- cfsgroup = {};
- cfsgroup.fields = [];
- cfsgroup.legend = field.fieldset;
- cfsgroup.fields.push(field);
- }
- else {
- cfsgroup.fields.push(field);
- }
- }
-
- // Add last fieldset.
- fieldsets.push(cfsgroup);
-
- // Loop over the fieldsets created above.
- for (var i = 0; i < fieldsets.length; i++) {
- var fieldset = fieldsets[i];
- var jfs = $j(
- $j.sprintf(
- '<fieldset class="%s"></fieldset>',
- fieldset.legend.replace(/ /g, '').replace("'", '').toLowerCase()
- )
- );
-
- // Loop over the fields in the fieldset.
- for (var f = 0; f < fieldset.fields.length; f++) {
- var field = fieldset.fields[f];
- var jlabel = $j(
- $j.sprintf(
- '<label id="%s_label">%s%s</label>',
- field.name,
- field.label,
- (field.optional != 1 ? ' *' : '')
- )
- );
-
- // Determine label class based on if the field is optional or not.
- if (field.optional != 1) {
- jlabel.addClass('required');
- }
-
- // Set 'for' attribute for all types except display and html.
- if (field.type != 'display' && field.type != 'html') {
- jlabel.attr('for', field.name);
- }
-
- // Add the label to the fieldset unless the field type is hidden.
- if (field.type != 'hidden') {
- jfs.append(jlabel);
- }
-
- // Handle file type fields.
- if (field.type == 'file') {
- // Add the file input to the fieldset.
- jfs.append(
- $j.sprintf(
- '<input type="file" name="%s" />',
- field.name
- )
- );
- }
- // Handle display type fields.
- else if (field.type == 'display') {
- var fieldDisplay;
-
- // Get the display value from either the row or the default value.
- if (json.form.row != null && json.form.row[field.name] != null) {
- fieldDisplay = json.form.row[field.name];
- }
- else {
- fieldDisplay = field.default_value;
- }
-
- // Add the display div to the fieldset.
- jfs.append(
- $j.sprintf(
- '<div class="display">%s</div>',
- fieldDisplay
- )
- );
- }
- // Handle textarea type fields.
- else if (field.type == 'textarea') {
- var val = '';
- var jtextarea;
-
- // Determine val.
- if (field.name in json.params) {
- val = json.params[field.name];
- }
- else if (json.form.row != null) {
- val = json.form.row[field.name];
- }
- else {
- val = field.default_value;
- }
-
- // Create textarea.
- jtextarea = $j(
- $j.sprintf(
- '<%s name="%s" id="%s">%s</%s>',
- field.type,
- field.name,
- field.name,
- val,
- field.type
- )
- );
-
- // Determine field class if any.
- if (field['class'] != null) {
- jtextarea.addClass(field['class']);
- }
-
- // Determine field rows if any.
- if (field['rows'] != null) {
- jtextarea.attr('rows', field['rows']);
- }
-
- // Determine field cols if any.
- if (field['cols'] != null) {
- jtextarea.attr('cols', field['cols']);
- }
-
- // Determine if disabled.
- if (field['disabled'] == 1) {
- jtextarea.attr('disabled', 'disabled');
- }
-
- // Add textarea field.
- jfs.append(jtextarea);
- }
- // Handle select and multiple select type fields.
- else if (field.type == 'select' || field.type == 'multiple_select') {
- var selected = {};
- var jselect = $j(
- $j.sprintf(
- '<select name="%s" id="%s"></select>',
- field.name,
- field.name
- )
- );
-
- // Determine if any options are selected.
- if (json.params[field.name] != null) {
- if (json.params[field.name] instanceof Array) {
- for (var p = 0; p < json.params[field.name].length; p++) {
- selected[json.params[field.name][p]] = true;
- }
- }
- else {
- selected[json.params[field.name]] = true;
- }
- }
- else if (json.form.row != null && json.form.row[field.name] != null) {
- selected[json.form.row[field.name]] = true;
- }
- else {
- selected[field.default_value] = true;
- }
-
- // Determine field class if any.
- if (field['class'] != null) {
- jselect.addClass(field['class']);
- }
-
- // Determine field size if any.
- if (field['display_size'] != null) {
- jselect.attr('size', field['display_size']);
- }
-
- // Determine if disabled.
- if (field['disabled'] == 1) {
- jselect.attr('disabled', 'disabled');
- }
-
- // Determine on change if any.
- if (field['onchange'] != null) {
- jselect.attr('onchange', field['onchange']);
- }
-
- // Determine if this is a multi select.
- if (field['type'] == 'multiple_select') {
- jselect.attr('multiple', 'multiple');
- }
-
- // Add options to the select list.
- for (var opt = 0; opt < field.options.length; opt++) {
- var option = field.options[opt];
- var joption = $j(
- $j.sprintf(
- '<option value="%s">%s</option>',
- option.value,
- option.label
- )
- );
-
- // Determine if current option should be selected.
- if (selected[option.value]) {
- joption.attr('selected', 'selected');
- }
-
- // Add option to select element.
- jselect.append(joption);
- }
-
- // Add select to fieldset.
- jfs.append(jselect);
- }
- else if (field.type == 'html') {
- jfs.append(field.html);
- }
- // Handle all other type fields.
- else {
- var val;
- var jinput;
-
- // Determine val.
- if (field.name in json.params) {
- val = json.params[field.name];
- }
- else if (json.form.row != null) {
- val = json.form.row[field.name];
- }
- else if (field.default_value != null) {
- val = field.default_value;
- }
-
- // Create input.
- jinput = $j(
- $j.sprintf(
- '<input type="%s" name="%s" id="%s" />',
- field.type,
- field.name,
- field.name
- )
- );
-
- // Determine field class if any.
- if (field['class'] != null) {
- jinput.addClass(field['class']);
- }
-
- // Determine field size if any.
- if (field['display_size'] != null) {
- jinput.attr('size', field['display_size']);
- }
-
- // Determine field value if any.
- if (val != null) {
- jinput.attr('value', val);
- }
-
- // Determine if disabled.
- if (field['disabled'] == 1) {
- jinput.attr('disabled', 'disabled');
- }
-
- // Add input field.
- jfs.append(jinput);
- }
-
- if (field.type != 'hidden') {
- // Add field hint.
- jfs.append(
- $j.sprintf(
- '<span id="%s_hint" class="hint">%s</span>',
- field.name,
- (field.hint != null ? field.hint : '')
- )
- );
-
- // If we have results...
- if (json.form.results != null) {
- // Display invalid span if necessary.
- if (json.form.results.invalid[field.name] != null) {
- jfs.append(' <span class="invalid">invalid</span>');
- }
-
- // Display missing span if necessary.
- if (json.form.results.missing[field.name] != null) {
- jfs.append(' <span class="missing">required</span>');
- }
- }
-
- jfs.append(
- $j.sprintf(
- '<br id="%s_br" style="clear: both" />',
- field.name
- )
- );
- }
- }
-
- // Add the legend unless its the gantry default legend.
- if (fieldset.legend != 'gantry-default') {
- jfs.prepend(
- $j.sprintf(
- '<legend>%s</legend>',
- fieldset.legend
- )
- );
- }
-
- // Add the fieldset to the form.
- jform.find('div').append(jfs);
- }
- }
-
- // Output actions box if we have a submit or cancel action.
- if (json.form.no_submit != 1 || json.form.no_cancel != 1) {
- var jactionsDiv = $j(
- $j.sprintf(
- '<div class="form-box actions"></div>'
- )
- )
-
- // Add additional form class if necessary.
- if (json.form['class'] != null) {
- jactionsDiv.addClass(json.form['class']);
- }
-
-
- // Add submit button.
- if (json.form.no_submit != 1) {
- jactionsDiv.append(
- $j.sprintf(
- '<input type="submit" name="submit_button" id="submit_button"
value="%s" />',
- (json.form.submit_button_label ?
json.form.submit_button_label : 'Submit')
- )
- );
- }
-
- // Add submit and add another button.
- if (json.form.submit_and_add_another == 1) {
- var value = (
- json.form.submit_and_add_another_label
- ? json.form.submit_and_add_another_label
- : 'Submit &amp; Add Another'
- );
-
- jactionsDiv.append(
- $j.sprintf(
- '<input type="submit" name="submit_add_another" ' +
- 'id="submit_add_another" value="%s" />',
- (
- json.form.submit_and_add_another_label
- ? json.form.submit_and_add_another_label
- : 'Submit &amp; Add Another'
- )
- )
- );
- }
-
- // Add cancel button.
- if (json.form.no_cancel != 1) {
- var value = (
- json.form.cancel_button_label
- ? json.form.cancel_button_label
- : 'Cancel'
- );
-
- jactionsDiv.append(
- $j.sprintf(
- '<input type="submit" name="cancel" id="cancel" value="%s" />',
- (
- json.form.cancel_button_label
- ? json.form.cancel_button_label
- : 'Cancel'
- )
- )
- );
- }
-
- // Add actions_div to form.
- jform.append(jactionsDiv);
- }
-
- // Output form header unless its not wanted.
- if (json.form.nohead != 1) {
- jform.find('div:first').prepend(
- $j.sprintf(
- '<h4 class="heading">%s</h4>',
- json.title
- )
- );
- }
-
- // Add ajax to form.
+ var fieldsets = [];
+ var cfsgroup = {};
+ var jform = $j(
+ $j.sprintf(
+ '<form action="%s" method="post" class="form-box">' +
+ '<div class="form-box">' +
+ '</div>' +
+ '</form>',
+ json.form.action
+ )
+ );
+ var ajaxFormOptions = {
+ 'dataType' : 'json',
+ 'success' : function (result_json, status_text) {
+ // Response contains a form...
+ if (result_json.form != null) {
+ // Set form action to original form
action if none was specified.
+ if (result_json.form.action == null) {
+ result_json.form.action =
json.form.action;
+ }
+
+ gantryAjaxRenderForm(formType,
result_json);
+ }
+ // Response contains results.
+ else if (result_json.headings != null) {
+ gantryAjaxRenderResults(result_json);
+ $j.address.value('/');
+ }
+ else {
+ $j.address.value('/');
+ }
+ },
+ };
+
+ // Add any specified callbacks to the options.
+ for (var cb in gantryAjaxFormOptions) {
+ alert(cb);
+ ajaxFormOptions[cb] = gantryAjaxFormOptions[cb];
+ }
+
+ // Handle form error summary.
+ if (json.form.results != null && json.form.show_error_summary == 1) {
+ if (json.form.results.msgs.group_by_field == 1) {
+ var invalid = false;
+ var missing = false;
+
+ // Check for invalid.
+ for (var i in json.form.results.invalid) {
+ invalid = true;
+ }
+
+ // Check for missing.
+ for (var i in json.form.results.missing) {
+ missing = true;
+ }
+
+ // If there are any invalid or missing fields...
+ if (invalid || missing) {
+ var jep = $j('<p class="missing" style="color: red"></p>');
+
+ for (var i = 0; i < json.form.fields.length; i++) {
+ var field = json.form.fields[i];
+
+ if (json.form.results.invalid[field.name] ||
json.form.results.missing[field.name]) {
+ jep.append(
+ $j.sprintf(
+ '<b>%s:</b> %s<br />',
+ field.label,
+ json.form.results.msgs[field.name]
+ )
+ );
+ }
+ }
+
+ jform.prepend(jep);
+ }
+ }
+ }
+
+ // Init cfsgroup.
+ cfsgroup.legend = 'gantry-default';
+ cfsgroup.fields = [];
+
+ // Output any message contained in the form.
+ if (json.form.message != null) {
+ jform.find('div').append(
+ $j.sprintf(
+ '<div class="msg">%s</div>',
+ json.form.message
+ )
+ );
+ }
+
+ if (json.form.fields != null) {
+ // Foreach over the fields and add them to the fieldset.
+ for (var i = 0; i < json.form.fields.length; i++) {
+ var field = json.form.fields[i];
+
+ if (field.fieldset != null && field.fieldset !=
cfsgroup.legend) {
+ if (cfsgroup.fields.length > 0) {
+ fieldsets.push(cfsgroup);
+ }
+
+ cfsgroup = {};
+ cfsgroup.fields = [];
+ cfsgroup.legend = field.fieldset;
+ cfsgroup.fields.push(field);
+ }
+ else {
+ cfsgroup.fields.push(field);
+ }
+ }
+
+ // Add last fieldset.
+ fieldsets.push(cfsgroup);
+
+ // Loop over the fieldsets created above.
+ for (var i = 0; i < fieldsets.length; i++) {
+ var fieldset = fieldsets[i];
+ var jfs = $j(
+ $j.sprintf(
+ '<fieldset class="%s"></fieldset>',
+ fieldset.legend.replace(/
/g, '').replace("'", '').toLowerCase()
+ )
+ );
+
+ // Loop over the fields in the fieldset.
+ for (var f = 0; f < fieldset.fields.length; f++) {
+ var field = fieldset.fields[f];
+ var jlabel = $j(
+ $j.sprintf(
+ '<label id="%s_label">%s%s</label>',
+ field.name,
+ field.label,
+ (field.optional != 1 ? ' *' : '')
+ )
+ );
+
+ // Determine label class based on if the field is optional
or not.
+ if (field.optional != 1) {
+ jlabel.addClass('required');
+ }
+
+ // Set 'for' attribute for all types except display and
html.
+ if (field.type != 'display' && field.type != 'html') {
+ jlabel.attr('for', field.name);
+ }
+
+ // Add the label to the fieldset unless the field type is
hidden.
+ if (field.type != 'hidden') {
+ jfs.append(jlabel);
+ }
+
+ // Handle file type fields.
+ if (field.type == 'file') {
+ // Add the file input to the fieldset.
+ jfs.append(
+ $j.sprintf(
+ '<input type="file" name="%s" />',
+ field.name
+ )
+ );
+ }
+ // Handle display type fields.
+ else if (field.type == 'display') {
+ var fieldDisplay;
+
+ // Get the display value from either the row or the
default value.
+ if (json.form.row != null &&
json.form.row[field.name] != null) {
+ fieldDisplay = json.form.row[field.name];
+ }
+ else {
+ fieldDisplay = field.default_value;
+ }
+
+ // Add the display div to the fieldset.
+ jfs.append(
+ $j.sprintf(
+ '<div class="display">%s</div>',
+ fieldDisplay
+ )
+ );
+ }
+ // Handle textarea type fields.
+ else if (field.type == 'textarea') {
+ var val = '';
+ var jtextarea;
+
+ // Determine val.
+ if (field.name in json.params) {
+ val = json.params[field.name];
+ }
+ else if (json.form.row != null) {
+ val = json.form.row[field.name];
+ }
+ else {
+ val = field.default_value;
+ }
+
+ // Create textarea.
+ jtextarea = $j(
+ $j.sprintf(
+ '<%s name="%s" id="%s">%s</%s>',
+ field.type,
+ field.name,
+ field.name,
+ val,
+ field.type
+ )
+ );
+
+ // Determine field class if any.
+ if (field['class'] != null) {
+ jtextarea.addClass(field['class']);
+ }
+
+ // Determine field rows if any.
+ if (field['rows'] != null) {
+ jtextarea.attr('rows', field['rows']);
+ }
+
+ // Determine field cols if any.
+ if (field['cols'] != null) {
+ jtextarea.attr('cols', field['cols']);
+ }
+
+ // Determine if disabled.
+ if (field['disabled'] == 1) {
+ jtextarea.attr('disabled', 'disabled');
+ }
+
+ // Add textarea field.
+ jfs.append(jtextarea);
+ }
+ // Handle select and multiple select type fields.
+ else if (field.type == 'select' || field.type
== 'multiple_select') {
+ var selected = {};
+ var jselect = $j(
+ $j.sprintf(
+ '<select name="%s" id="%s"></select>',
+ field.name,
+ field.name
+ )
+ );
+
+ // Determine if any options are selected.
+ if (json.params[field.name] != null) {
+ if (json.params[field.name] instanceof Array) {
+ for (var p = 0; p <
json.params[field.name].length; p++) {
+ selected[json.params[field.name][p]] =
true;
+ }
+ }
+ else {
+ selected[json.params[field.name]] = true;
+ }
+ }
+ else if (json.form.row != null &&
json.form.row[field.name] != null) {
+ selected[json.form.row[field.name]] = true;
+ }
+ else {
+ selected[field.default_value] = true;
+ }
+
+ // Determine field class if any.
+ if (field['class'] != null) {
+ jselect.addClass(field['class']);
+ }
+
+ // Determine field size if any.
+ if (field['display_size'] != null) {
+ jselect.attr('size', field['display_size']);
+ }
+
+ // Determine if disabled.
+ if (field['disabled'] == 1) {
+ jselect.attr('disabled', 'disabled');
+ }
+
+ // Determine on change if any.
+ if (field['onchange'] != null) {
+ jselect.attr('onchange', field['onchange']);
+ }
+
+ // Determine if this is a multi select.
+ if (field['type'] == 'multiple_select') {
+ jselect.attr('multiple', 'multiple');
+ }
+
+ // Add options to the select list.
+ for (var opt = 0; opt < field.options.length; opt++) {
+ var option = field.options[opt];
+ var joption = $j(
+ $j.sprintf(
+ '<option value="%s">%s</option>',
+ option.value,
+ option.label
+ )
+ );
+
+ // Determine if current option should be selected.
+ if (selected[option.value]) {
+ joption.attr('selected', 'selected');
+ }
+
+ // Add option to select element.
+ jselect.append(joption);
+ }
+
+ // Add select to fieldset.
+ jfs.append(jselect);
+ }
+ else if (field.type == 'html') {
+ jfs.append(field.html);
+ }
+ // Handle all other type fields.
+ else {
+ var val;
+ var jinput;
+
+ // Determine val.
+ if (field.name in json.params) {
+ val = json.params[field.name];
+ }
+ else if (json.form.row != null) {
+ val = json.form.row[field.name];
+ }
+ else if (field.default_value != null) {
+ val = field.default_value;
+ }
+
+ // Create input.
+ jinput = $j(
+ $j.sprintf(
+ '<input type="%s" name="%s" id="%s" />',
+ field.type,
+ field.name,
+ field.name
+ )
+ );
+
+ // Determine field class if any.
+ if (field['class'] != null) {
+ jinput.addClass(field['class']);
+ }
+
+ // Determine field size if any.
+ if (field['display_size'] != null) {
+ jinput.attr('size', field['display_size']);
+ }
+
+ // Determine field value if any.
+ if (val != null) {
+ jinput.attr('value', val);
+ }
+
+ // Determine if disabled.
+ if (field['disabled'] == 1) {
+ jinput.attr('disabled', 'disabled');
+ }
+
+ // Add input field.
+ jfs.append(jinput);
+ }
+
+ if (field.type != 'hidden') {
+ // Add field hint.
+ jfs.append(
+ $j.sprintf(
+ '<span id="%s_hint" class="hint">%s</span>',
+ field.name,
+ (field.hint != null ? field.hint : '')
+ )
+ );
+
+ // If we have results...
+ if (json.form.results != null) {
+ // Display invalid span if necessary.
+ if (json.form.results.invalid[field.name] != null)
{
+ jfs.append(' <span
class="invalid">invalid</span>');
+ }
+
+ // Display missing span if necessary.
+ if (json.form.results.missing[field.name] != null)
{
+ jfs.append(' <span
class="missing">required</span>');
+ }
+ }
+
+ jfs.append(
+ $j.sprintf(
+ '<br id="%s_br" style="clear: both" />',
+ field.name
+ )
+ );
+ }
+ }
+
+ // Add the legend unless its the gantry default legend.
+ if (fieldset.legend != 'gantry-default') {
+ jfs.prepend(
+ $j.sprintf(
+ '<legend>%s</legend>',
+ fieldset.legend
+ )
+ );
+ }
+
+ // Add the fieldset to the form.
+ jform.find('div').append(jfs);
+ }
+ }
+
+ // Output actions box if we have a submit or cancel action.
+ if (json.form.no_submit != 1 || json.form.no_cancel != 1) {
+ var jactionsDiv = $j(
+ $j.sprintf(
+ '<div class="form-box actions"></div>'
+ )
+ )
+
***The diff for this file has been truncated for email.***
=======================================
--- /trunk/root/js/ajaxResults.js Mon Apr 4 09:08:43 2011
+++ /trunk/root/js/ajaxResults.js Tue Apr 5 11:05:25 2011
@@ -31,55 +31,55 @@
* parameters: jobj, options
*
* description: This function will build the jquery options object for
gantry
-* result tables. This includes both pre header, header, and row
-* options.
+* result tables. This includes both pre header, header,
and row
+* options.
*/
function buildOptions (jobj, options) {
- // Loop over all the header options.
- for (var i = 0; i < options.length; i++) {
- var option = options[i];
-
- // Output left bracket on first iteration.
- if (i == 0) {
- jobj.append('[ ');
- }
-
- // If a link was specfied for the option...
- if (option.link != null || option.rel != null) {
- var anchor = $j(
- $j.sprintf(
- '<a>%s</a>',
- option.text
- )
- );
-
- // Add href to anchor.
- if (option.link != null) {
- anchor.attr('href', option.link);
- }
-
- // Add rel attribute to anchor.
- if (option.rel) {
- anchor.attr('rel', option.rel);
- }
-
- // Add anchor to jquery object.
- jobj.append(anchor);
- }
- // Add the option text without any link.
- else {
- jobj.append(option.text);
- }
-
- // Add a separator if its not the last option.
- if (i != options.length - 1) {
- jobj.append(' | ');
- }
- // Add closing bracket after last option.
- else {
- jobj.append(' ]');
- }
- }
+ // Loop over all the header options.
+ for (var i = 0; i < options.length; i++) {
+ var option = options[i];
+
+ // Output left bracket on first iteration.
+ if (i == 0) {
+ jobj.append('[ ');
+ }
+
+ // If a link was specfied for the option...
+ if (option.link != null || option.rel != null) {
+ var anchor = $j(
+ $j.sprintf(
+ '<a>%s</a>',
+ option.text
+ )
+ );
+
+ // Add href to anchor.
+ if (option.link != null) {
+ anchor.attr('href', option.link);
+ }
+
+ // Add rel attribute to anchor.
+ if (option.rel) {
+ anchor.attr('rel', option.rel);
+ }
+
+ // Add anchor to jquery object.
+ jobj.append(anchor);
+ }
+ // Add the option text without any link.
+ else {
+ jobj.append(option.text);
+ }
+
+ // Add a separator if its not the last option.
+ if (i != options.length - 1) {
+ jobj.append(' | ');
+ }
+ // Add closing bracket after last option.
+ else {
+ jobj.append(' ]');
+ }
+ }
}

/**
@@ -89,285 +89,285 @@
* parameters: json
*
* description: Given a json representation of a gantry result table,
-* this method will render the results to the content section
-* of the page.
+* this method will render the results to the content
section
+* of the page.
*/
function gantryAjaxRenderResults (json) {
- var $j = jQuery.noConflict();
- var resultsBox = $j(
- $j.sprintf(
- '<div class="box">' +
- '<table id="%s" class="%s">' +
- '<thead>' +
- '</thead>' +
- '<tbody>' +
- '</tbody>' +
- '</table>' +
- '</div>',
- ( json.id ? json.id : 'results'),
- 'results ' + ( json['class'] != null ? json['class'] : '' )
- )
- );
- var colspan = ( json.headings != null ? json.headings.length : 0 );
- var altBG = 1;
- var hdrRow;
-
- // Add 1 to colspan if there are options.
- if (json.no_options != 1) {
- colspan += 1;
- }
-
- // If pre headings are not disabled...
- if (json.no_pre_headings != 1) {
- var preheadingRow = $j('<tr class="pre-hdr-row"></tr>');
- var hidePreHeadings = ( json.params != null &&
json.params.hide_preheadings == 1 ? 'true' : 'false' );
- var phocolspan = colspan;
-
- // Check if there are table preheadings to output.
- if (json.pre_headings != null && json.pre_headings.length > 0 && !
hidePreHeadings) {
- var preHeadingClass = '';
-
- for (var i = 0; i < json.pre_headings.length; i++) {
- var preHeading = json.pre_headings[i];
- var colspanAttr = '';
- var preHeadingText;
- var td;
-
- // Pre heading is an object.
- if (typeof preHeading == 'object') {
- if (preHeading.colspan != null && preHeading.colspan > 0) {
- colspanAttr = 'colspan="' + preHeading.colspan + '"';
- phocolspan -= preHeading.colspan;
- }
-
- preHeadingText = preHeading.text;
- preHeadingClass = preHeading['class'];
- }
- // Pre heading is just text.
- else {
- preHeadingText = preHeading;
- }
-
- // Create pre heading jquery td object with the correct
- // class, colspan, and text.
- td = $j(
- $j.sprintf(
- '<td class="%s" %s>' +
- '%s' +
- '</td>',
- 'hdr ' + preHeading['class'],
- colspanAttr,
- preHeadingText
- )
- );
-
- preHeadingRow.append(td);
- }
-
- // Add options if there are any.
- if (json.pre_header_options.length > 0) {
- var tdOpt = $j('<td class="rhdr"></td>');
-
- // Add additional class if it exists.
- if (json.pre_header_options['class']) {
- tdOpt.addClass(json.pre_header_options['class']);
- }
-
- // Build the options.
- buildOptions(tdOpt, json.pre_header_options);
-
- // Add options cell to header row.
- preHeadingRow.append(tdOpt);
- }
- }
- // Add empty preheading row.
- else {
- preheadingRow.append(
- $j.sprintf(
- '<td class="hdr" colspan="%s">&nbsp;</td>',
- colspan
- )
- );
- }
-
- resultsBox.find('thead').append(preheadingRow);
- }
-
- // Create header row.
- hdrRow = $j('<tr class="hdr-row"></td>');
-
- // Add columns to header row.
- for (var i = 0; i < json.headings.length; i++) {
- var heading = json.headings[i];
- var th = $j('<th class="hdr"></th>');
-
- // heading is an object...
- if (typeof heading == 'object') {
- // Add additional class.
- if (heading['class'] != null) {
- th.addClass(heading['class']);
- }
-
- // Add title.
- if (heading['title'] != null) {
- th.attr('title', heading['title']);
- }
-
- // Add text.
- th.html(heading['text']);
- }
- // heading is just text...
- else {
- th.html(heading);
- }
-
- // Add th to header row.
- hdrRow.append(th);
- }
-
- // Add header options unless no_options is set.
- if (json.no_options != 1) {
- var thOpt = $j('<th class="rhdr"></th>');
-
- // Add additional class if it exists.
- if (json.header_options['class']) {
- thOpt.addClass(json.header_options['class']);
- }
-
- // Build the options.
- buildOptions(thOpt, json.header_options);
-
- // Add options cell to header row.
- hdrRow.append(thOpt);
- }
-
- // Add header row.
- resultsBox.find('thead').append(hdrRow);
-
- if (json.rows != null && json.rows.length > 0) {
- // Foreach over the table rows...
- for ( var i = 0; i < json.rows.length; i++) {
- var row = json.rows[i];
- var tr = $j('<tr class="results-row"></tr>');
-
- // Add id to row.
- if (row.id != null) {
- tr.attr('id', row.id);
- }
-
- // Unless the row class matches (warning|highlighted)-row then add
- // the standard alt-bgx class.
- if (row['class'] == null || (row['class'] != null && !
row['class'].match(/(warning|highlighted)-row/i))) {
- tr.addClass('alt-bg' + altBG);
- }
-
- // Add any additional class.
- if (row['class'] != null) {
- tr.addClass(row['class']);
- }
-
- // Foreach over the data items in the row...
- for ( var e = 0; e < row.data.length; e++) {
- var elem = row.data[e];
- var td = $j('<td class="dta"></td>');
-
- // If we have an object...
- if (typeof elem == 'object') {
- // Add id to td if it exists.
- if (elem['class'] != null) {
- td.attr('id', elem['class']);
- }
-
- // Add additional class if it exists.
- if (elem['class'] != null) {
- td.addClass(elem['class']);
- }
-
- // Add style if it exists.
- if (elem['td_style'] != null) {
- var style = elem['td_style'];
-
- style.replace(/^style="|"$/ig);
-
- td.attr('style', style);
- }
-
- // Add colspan if it exists.
- if (elem['colspan'] != null) {
- td.attr('colspan', elem['colspan']);
- }
-
- // Add element text.
- td.html(elem['text']);
- }
- // elem is not an object so just add the text.
- else {
- td.html(elem);
- }
-
- // Add last class if this is the last row in the table.
- if (i == json.rows.length - 1) {
- td.addClass('last');
- }
-
- // Add the column to the row.
- tr.append(td);
- }
-
- // Add row options if necessary.
- if (json.no_options != 1) {
- var tdOpt = $j('<td class="rdta"></td>');
- var optClasses = [];
-
- // Add id if it exists.
- if (row.options['id']) {
- tdOpt.attr('id', row.options['id']);
- }
-
- // Add additional class if it exists.
- if (row.options['class']) {
- tdOpt.addClass(row.options['class']);
- }
-
- // Add last class if this is the last row in the table.
- if (i == json.rows.length - 1) {
- tdOpt.addClass('last');
- }
-
- // Add style if it exists.
- if (row.options['td_style'] != null) {
- var style = row.options['td_style'];
-
- style.replace(/^style="|"$/ig);
-
- tdOpt.attr('style', style);
- }
-
- // Build the options.
- buildOptions(tdOpt, row.options);
-
- // Add options cell to header row.
- tr.append(tdOpt);
- }
-
- // Add row to table body.
- resultsBox.find('tbody').append(tr);
-
- // Switch bg color.
- altBG = ( altBG == 1 ? 0 : 1 );
- }
- }
- // No row data found...
- else {
- resultsBox.find('tbody').append(
- $j.sprintf(
- '<tr class="no-data"><td colspan="%s">No Data</td></tr>',
- colspan
- )
- );
- }
-
- // Clear content and add resultsBox.
- $j('#content').html('');
- $j('#content').prepend(resultsBox);
-}
+ var $j = jQuery.noConflict();
+ var resultsBox = $j(
+ $j.sprintf(
+ '<div class="box">' +
+ '<table id="%s" class="%s">' +
+ '<thead>' +
+ '</thead>' +
+ '<tbody>' +
+ '</tbody>' +
+ '</table>' +
+ '</div>',
+ ( json.id ? json.id : 'results'),
+ 'results ' + ( json['class'] != null ? json['class'] : '' )
+ )
+ );
+ var colspan = ( json.headings != null ? json.headings.length : 0 );
+ var altBG = 1;
+ var hdrRow;
+
+ // Add 1 to colspan if there are options.
+ if (json.no_options != 1) {
+ colspan += 1;
+ }
+
+ // If pre headings are not disabled...
+ if (json.no_pre_headings != 1) {
+ var preheadingRow = $j('<tr class="pre-hdr-row"></tr>');
+ var hidePreHeadings = ( json.params != null &&
json.params.hide_preheadings == 1 ? 'true' : 'false' );
+ var phocolspan = colspan;
+
+ // Check if there are table preheadings to output.
+ if (json.pre_headings != null && json.pre_headings.length > 0 && !
hidePreHeadings) {
+ var preHeadingClass = '';
+
+ for (var i = 0; i < json.pre_headings.length; i++) {
+ var preHeading = json.pre_headings[i];
+ var colspanAttr = '';
+ var preHeadingText;
+ var td;
+
+ // Pre heading is an object.
+ if (typeof preHeading == 'object') {
+ if (preHeading.colspan != null && preHeading.colspan >
0) {
+ colspanAttr = 'colspan="' + preHeading.colspan
+ '"';
+ phocolspan -= preHeading.colspan;
+ }
+
+ preHeadingText = preHeading.text;
+ preHeadingClass = preHeading['class'];
+ }
+ // Pre heading is just text.
+ else {
+ preHeadingText = preHeading;
+ }
+
+ // Create pre heading jquery td object with the correct
+ // class, colspan, and text.
+ td = $j(
+ $j.sprintf(
+ '<td class="%s" %s>' +
+ '%s' +
+ '</td>',
+ 'hdr ' + preHeading['class'],
+ colspanAttr,
+ preHeadingText
+ )
+ );
+
+ preHeadingRow.append(td);
+ }
+
+ // Add options if there are any.
+ if (json.pre_header_options.length > 0) {
+ var tdOpt = $j('<td class="rhdr"></td>');
+
+ // Add additional class if it exists.
+ if (json.pre_header_options['class']) {
+ tdOpt.addClass(json.pre_header_options['class']);
+ }
+
+ // Build the options.
+ buildOptions(tdOpt, json.pre_header_options);
+
+ // Add options cell to header row.
+ preHeadingRow.append(tdOpt);
+ }
+ }
+ // Add empty preheading row.
+ else {
+ preheadingRow.append(
+ $j.sprintf(
+ '<td class="hdr" colspan="%s">&nbsp;</td>',
+ colspan
+ )
+ );
+ }
+
+ resultsBox.find('thead').append(preheadingRow);
+ }
+
+ // Create header row.
+ hdrRow = $j('<tr class="hdr-row"></td>');
+
+ // Add columns to header row.
+ for (var i = 0; i < json.headings.length; i++) {
+ var heading = json.headings[i];
+ var th = $j('<th class="hdr"></th>');
+
+ // heading is an object...
+ if (typeof heading == 'object') {
+ // Add additional class.
+ if (heading['class'] != null) {
+ th.addClass(heading['class']);
+ }
+
+ // Add title.
+ if (heading['title'] != null) {
+ th.attr('title', heading['title']);
+ }
+
+ // Add text.
+ th.html(heading['text']);
+ }
+ // heading is just text...
+ else {
+ th.html(heading);
+ }
+
+ // Add th to header row.
+ hdrRow.append(th);
+ }
+
+ // Add header options unless no_options is set.
+ if (json.no_options != 1) {
+ var thOpt = $j('<th class="rhdr"></th>');
+
+ // Add additional class if it exists.
+ if (json.header_options['class']) {
+ thOpt.addClass(json.header_options['class']);
+ }
+
+ // Build the options.
+ buildOptions(thOpt, json.header_options);
+
+ // Add options cell to header row.
+ hdrRow.append(thOpt);
+ }
+
+ // Add header row.
+ resultsBox.find('thead').append(hdrRow);
+
+ if (json.rows != null && json.rows.length > 0) {
+ // Foreach over the table rows...
+ for ( var i = 0; i < json.rows.length; i++) {
+ var row = json.rows[i];
+ var tr = $j('<tr class="results-row"></tr>');
+
+ // Add id to row.
+ if (row.id != null) {
+ tr.attr('id', row.id);
+ }
+
+ // Unless the row class matches (warning|highlighted)-row then
add
+ // the standard alt-bgx class.
+ if (row['class'] == null || (row['class'] != null && !
row['class'].match(/(warning|highlighted)-row/i))) {
+ tr.addClass('alt-bg' + altBG);
+ }
+
+ // Add any additional class.
+ if (row['class'] != null) {
+ tr.addClass(row['class']);
+ }
+
+ // Foreach over the data items in the row...
+ for ( var e = 0; e < row.data.length; e++) {
+ var elem = row.data[e];
+ var td = $j('<td class="dta"></td>');
+
+ // If we have an object...
+ if (typeof elem == 'object') {
+ // Add id to td if it exists.
+ if (elem['class'] != null) {
+ td.attr('id', elem['class']);
+ }
+
+ // Add additional class if it exists.
+ if (elem['class'] != null) {
+ td.addClass(elem['class']);
+ }
+
+ // Add style if it exists.
+ if (elem['td_style'] != null) {
+ var style = elem['td_style'];
+
+ style.replace(/^style="|"$/ig);
+
+ td.attr('style', style);
+ }
+
+ // Add colspan if it exists.
+ if (elem['colspan'] != null) {
+ td.attr('colspan', elem['colspan']);
+ }
+
+ // Add element text.
+ td.html(elem['text']);
+ }
+ // elem is not an object so just add the text.
+ else {
+ td.html(elem);
+ }
+
+ // Add last class if this is the last row in the table.
+ if (i == json.rows.length - 1) {
+ td.addClass('last');
+ }
+
+ // Add the column to the row.
+ tr.append(td);
+ }
+
+ // Add row options if necessary.
+ if (json.no_options != 1) {
+ var tdOpt = $j('<td class="rdta"></td>');
+ var optClasses = [];
+
+ // Add id if it exists.
+ if (row.options['id']) {
+ tdOpt.attr('id', row.options['id']);
+ }
+
+ // Add additional class if it exists.
+ if (row.options['class']) {
+ tdOpt.addClass(row.options['class']);
+ }
+
+ // Add last class if this is the last row in the table.
+ if (i == json.rows.length - 1) {
+ tdOpt.addClass('last');
+ }
+
+ // Add style if it exists.
+ if (row.options['td_style'] != null) {
+ var style = row.options['td_style'];
+
+ style.replace(/^style="|"$/ig);
+
+ tdOpt.attr('style', style);
+ }
+
+ // Build the options.
+ buildOptions(tdOpt, row.options);
+
+ // Add options cell to header row.
+ tr.append(tdOpt);
+ }
+
+ // Add row to table body.
+ resultsBox.find('tbody').append(tr);
+
+ // Switch bg color.
+ altBG = ( altBG == 1 ? 0 : 1 );
+ }
+ }
+ // No row data found...
+ else {
+ resultsBox.find('tbody').append(
+ $j.sprintf(
+ '<tr class="no-data"><td colspan="%s">No Data</td></tr>',
+ colspan
+ )
+ );
+ }
+
+ // Clear content and add resultsBox.
+ $j('#content').html('');
+ $j('#content').prepend(resultsBox);
+}

Reply all
Reply to author
Forward
0 new messages