File: view-form-information.js

package info (click to toggle)
webdeveloper 1.2.5%2Brepack-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 5,364 kB
  • ctags: 1,608
  • sloc: makefile: 10
file content (189 lines) | stat: -rw-r--r-- 5,793 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
var WebDeveloper = WebDeveloper || {};

WebDeveloper.Generated = WebDeveloper.Generated || {};

// Displays a form
WebDeveloper.Generated.displayForm = function(form, container, formsCounter, locale)
{
  var childElement   = document.createElement("th");
  var element        = document.createElement("h4");
  var separator      = document.createElement("div");
  var table          = document.createElement("table");
  var tableContainer = document.createElement("thead");

  element.appendChild(document.createTextNode(locale.form));
  element.setAttribute("class", "web-developer-form");
  element.setAttribute("id", "form-" + formsCounter);
  container.appendChild(element);

  element = document.createElement("tr");

  childElement.appendChild(document.createTextNode(locale.id));
  element.appendChild(childElement);

  childElement = document.createElement("th");

  childElement.appendChild(document.createTextNode(locale.name));
  element.appendChild(childElement);

  childElement = document.createElement("th");

  childElement.appendChild(document.createTextNode(locale.method));
  element.appendChild(childElement);

  childElement = document.createElement("th");

  childElement.appendChild(document.createTextNode(locale.action));
  element.appendChild(childElement);
  tableContainer.appendChild(element);
  table.appendChild(tableContainer);

  tableContainer = document.createElement("tbody");

  $(tableContainer).append(ich.form(form));
  table.appendChild(tableContainer);
  table.setAttribute("class", "table table-bordered table-striped");
  container.appendChild(table);

  // If there are form elements
  if(form.elements.length > 0)
  {
    element        = document.createElement("h4");
    table          = document.createElement("table");
    tableContainer = document.createElement("thead");

    element.appendChild(document.createTextNode(locale.elements));
    container.appendChild(element);

    childElement = document.createElement("th");
    element      = document.createElement("tr");

    childElement.appendChild(document.createTextNode(locale.id));
    element.appendChild(childElement);

    childElement = document.createElement("th");

    childElement.appendChild(document.createTextNode(locale.name));
    element.appendChild(childElement);

    childElement = document.createElement("th");

    childElement.appendChild(document.createTextNode(locale.type));
    element.appendChild(childElement);

    childElement = document.createElement("th");

    childElement.appendChild(document.createTextNode(locale.value));
    element.appendChild(childElement);

    childElement = document.createElement("th");

    childElement.appendChild(document.createTextNode(locale.label));
    element.appendChild(childElement);

    childElement = document.createElement("th");

    childElement.appendChild(document.createTextNode(locale.size));
    element.appendChild(childElement);

    childElement = document.createElement("th");

    childElement.appendChild(document.createTextNode(locale.maximumLength));
    element.appendChild(childElement);
    tableContainer.appendChild(element);
    table.appendChild(tableContainer);

    tableContainer = document.createElement("tbody");

    $(tableContainer).append(ich.formElements(form, true));
    table.appendChild(tableContainer);
    table.setAttribute("class", "table table-bordered table-striped");
    container.appendChild(table);
  }

  separator.setAttribute("class", "web-developer-separator");
  container.appendChild(separator);

  childElement = document.createElement("a");
  element      = document.createElement("li");

  childElement.appendChild(document.createTextNode(WebDeveloper.Generated.formatFormDescription(form)));
  childElement.setAttribute("href", "#form-" + formsCounter);
  element.appendChild(childElement);
  $(".dropdown-menu", $("#forms-dropdown")).get(0).appendChild(element);
};

// Formats the form description
WebDeveloper.Generated.formatFormDescription = function(form)
{
  // If the form id is set
  if(form.id)
  {
    return form.id;
  }
  else if(form.name)
  {
    return form.name;
  }

  return form.action;
};

// Initializes the page with data
WebDeveloper.Generated.initialize = function(data, locale)
{
  var container        = null;
  var contentDocument  = null;
  var documents        = data.documents;
  var formDescription  = null;
  var forms            = null;
  var formsCounter     = 1;
  var formsDescription = locale.forms;
  var formsDropdown    = $("#forms-dropdown");
  var formsLength      = null;

  WebDeveloper.Generated.emptyContent();
  WebDeveloper.Generated.localizeHeader(locale);
  WebDeveloper.Generated.setPageTitle(formsDescription, data, locale);

  $(".dropdown-toggle", formsDropdown).prepend(formsDescription);

  // Loop through the documents
  for(var i = 0, l = documents.length; i < l; i++)
  {
    contentDocument = documents[i];
    formDescription = formsDescription.toLowerCase();
    forms           = contentDocument.forms;
    formsLength     = forms.length;

    // If there is only one form
    if(formsLength == 1)
    {
      formDescription = locale.form.toLowerCase();
    }

    WebDeveloper.Generated.addDocument(contentDocument.url, i, formDescription, formsLength);

    // If there are forms
    if(formsLength > 0)
    {
      container = WebDeveloper.Generated.generateDocumentContainer();

      // Loop through the forms
      for(var j = 0; j < formsLength; j++)
      {
        WebDeveloper.Generated.displayForm(forms[j], container, formsCounter, locale);

        formsCounter++;
      }

      document.getElementById("content").appendChild(container);
    }
    else
    {
      WebDeveloper.Generated.addSeparator();
    }
  }

  WebDeveloper.Generated.initializeCommonElements();
};