foreman_hosts 2.0.4.7 → 2.1.0

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.
Files changed (36) hide show
  1. data/README.md +1 -117
  2. data/app/assets/javascripts/application.js +2 -0
  3. data/app/assets/javascripts/jquery.battatech.excelexport.js +180 -0
  4. data/app/controllers/foreman_hosts/syhostmodeldetails_controller.rb +83 -0
  5. data/app/controllers/foreman_hosts/syhostmodels_controller.rb +83 -0
  6. data/app/models/concerns/foreman_hosts/{host_extensions.rb → hosts_extensions.rb} +1 -1
  7. data/app/models/foreman_hosts/syhostmodel.rb +8 -0
  8. data/app/models/foreman_hosts/syhostmodeldetail.rb +5 -0
  9. data/app/views/foreman_hosts/hosts/report_index.html.erb +188 -3
  10. data/app/views/foreman_hosts/syhostmodeldetails/_form.html.erb +29 -0
  11. data/app/views/foreman_hosts/syhostmodeldetails/_list.html.erb +43 -0
  12. data/app/views/foreman_hosts/syhostmodeldetails/_sygroup.html.erb +3 -0
  13. data/app/views/foreman_hosts/syhostmodeldetails/_sygroup_td.html.erb +7 -0
  14. data/app/views/foreman_hosts/syhostmodeldetails/create.js.erb +2 -0
  15. data/app/views/foreman_hosts/syhostmodeldetails/destroy.js.erb +1 -0
  16. data/app/views/foreman_hosts/syhostmodeldetails/edit.html.erb +1 -0
  17. data/app/views/foreman_hosts/syhostmodeldetails/edit.js.erb +3 -0
  18. data/app/views/foreman_hosts/syhostmodeldetails/index.html.erb +5 -0
  19. data/app/views/foreman_hosts/syhostmodeldetails/new.html.erb +1 -0
  20. data/app/views/foreman_hosts/syhostmodeldetails/new.js.erb +3 -0
  21. data/app/views/foreman_hosts/syhostmodeldetails/show.html.erb +28 -0
  22. data/app/views/foreman_hosts/syhostmodeldetails/update.js.erb +3 -0
  23. data/app/views/foreman_hosts/syhostmodels/_form.html.erb +30 -0
  24. data/app/views/foreman_hosts/syhostmodels/_list.html.erb +41 -0
  25. data/app/views/foreman_hosts/syhostmodels/_report.html.erb +258 -0
  26. data/app/views/foreman_hosts/syhostmodels/_sub.html.erb +37 -0
  27. data/app/views/foreman_hosts/syhostmodels/edit.html.erb +1 -0
  28. data/app/views/foreman_hosts/syhostmodels/index.html.erb +5 -0
  29. data/app/views/foreman_hosts/syhostmodels/new.html.erb +1 -0
  30. data/app/views/foreman_hosts/syhostmodels/show.html.erb +72 -0
  31. data/config/routes.rb +6 -3
  32. data/db/migrate/20151015022411_create_syhostmodels.rb +10 -0
  33. data/db/migrate/20151015050239_create_syhostmodeldetails.rb +13 -0
  34. data/lib/foreman_hosts/engine.rb +10 -11
  35. data/lib/foreman_hosts/version.rb +1 -1
  36. metadata +47 -2
data/README.md CHANGED
@@ -1,120 +1,4 @@
1
- *** LOCAL GEMS ***
2
-
3
- actionmailer (3.2.8)
4
- actionpack (3.2.8)
5
- activemodel (3.2.8)
6
- activerecord (3.2.8)
7
- activeresource (3.2.8)
8
- activesupport (4.2.4, 3.2.8)
9
- ancestry (2.0.0)
10
- apipie-rails (0.2.6)
11
- arel (3.0.2)
12
- audited (3.0.0)
13
- audited-activerecord (3.0.0)
14
- bigdecimal (1.1.0)
15
- builder (3.0.0)
16
- bundler (1.3.5)
17
- bundler_ext (0.3.0)
18
- coffee-rails (3.2.2)
19
- coffee-script (2.2.0)
20
- coffee-script-source (1.3.3)
21
- colorize (0.7.7)
22
- deep_cloneable (2.0.2)
23
- deface (1.0.1)
24
- diff-lcs (1.1.3)
25
- erubis (2.7.0)
26
- execjs (1.4.0)
27
- fast_gettext (0.9.2)
28
- foreigner (1.7.1)
29
- foreman-hosts (0.0.1)
30
- foreman_setup (3.0.1)
31
- friendly_id (4.0.10.1)
32
- gettext_i18n_rails (1.2.1)
33
- hike (1.2.1)
34
- i18n (0.7.0, 0.6.0)
35
- io-console (0.3)
36
- journey (1.0.4)
37
- json (1.8.3, 1.5.5)
38
- ldap_fluff (0.3.5)
39
- little-plugger (1.1.3)
40
- logging (1.8.2)
41
- loofah (2.0.3)
42
- mail (2.4.4)
43
- mime-types (1.19)
44
- mini_portile (0.6.2)
45
- minitest (5.8.1, 2.5.1)
46
- multi_json (1.10.1)
47
- net-http-persistent (2.7)
48
- net-ldap (0.11)
49
- netrc (0.7.7)
50
- nokogiri (1.6.6.2)
51
- oauth (0.4.7)
52
- passenger (4.0.18)
53
- pg (0.12.2)
54
- polyglot (0.3.3)
55
- rabl (0.11.6)
56
- rack (1.6.4, 1.4.1)
57
- rack-cache (1.2)
58
- rack-jsonp (1.3.1)
59
- rack-ssl (1.3.2)
60
- rack-test (0.6.3, 0.6.1)
61
- rails (3.2.8)
62
- railties (3.2.8)
63
- rake (0.9.2.2)
64
- rdoc (3.9.5)
65
- rest-client (1.6.7)
66
- ruby2ruby (2.1.3)
67
- ruby_parser (3.6.3)
68
- safemode (1.2.2)
69
- scoped_search (3.2.1)
70
- secure_headers (1.4.1)
71
- sexp_processor (4.4.4)
72
- sprockets (2.12.3)
73
- thor (0.18.1)
74
- thread_safe (0.3.5)
75
- tilt (1.3.3)
76
- treetop (1.4.10)
77
- turbolinks (2.5.3)
78
- tzinfo (1.2.2, 0.3.33)
79
- validates_lengths_from_database (0.4.0)
80
- will_paginate (3.0.2)
81
-
82
-
83
- ============================================================================
84
- Fetching: mini_portile-0.6.2.gem (100%)
85
- Fetching: nokogiri-1.6.6.2.gem (100%)
86
- Building native extensions. This could take a while...
87
- Fetching: colorize-0.7.7.gem (100%)
88
- Fetching: deface-1.0.1.gem (100%)
89
- Fetching: foreman-hosts-0.0.1.gem (100%)
90
- Fetching: i18n-0.7.0.gem (100%)
91
- Fetching: json-1.8.3.gem (100%)
92
- Building native extensions. This could take a while...
93
- Fetching: thread_safe-0.3.5.gem (100%)
94
- Fetching: tzinfo-1.2.2.gem (100%)
95
- Fetching: minitest-5.8.1.gem (100%)
96
- Fetching: activesupport-4.2.4.gem (100%)
97
- Fetching: rack-1.6.4.gem (100%)
98
- Fetching: rack-test-0.6.3.gem (100%)
99
- Fetching: loofah-2.0.3.gem (100%)
100
- Fetching: rails-html-sanitizer-1.0.2.gem (100%)
101
- Fetching: rails-deprecated_sanitizer-1.0.3.gem (100%)
102
- Fetching: rails-dom-testing-1.0.7.gem (100%)
103
- Fetching: builder-3.2.2.gem (100%)
104
- Fetching: actionview-4.2.4.gem (100%)
105
- Fetching: actionpack-4.2.4.gem (100%)
106
- Fetching: activemodel-4.2.4.gem (100%)
107
- Fetching: arel-6.0.3.gem (100%)
108
- Fetching: activerecord-4.2.4.gem (100%)
109
- Fetching: globalid-0.3.6.gem (100%)
110
- Fetching: activejob-4.2.4.gem (100%)
111
- Fetching: mail-2.6.3.gem (100%)
112
- Fetching: actionmailer-4.2.4.gem (100%)
113
- Fetching: railties-4.2.4.gem (100%)
114
- Fetching: sprockets-rails-2.3.3.gem (100%)
115
-
116
-
117
-
1
+ # 导出host信息,可默认导出所有主机的所有信息,也可以通过定制模板导出主机信息
118
2
  # ForemanHosts
119
3
 
120
4
  *Introdction here*
@@ -0,0 +1,2 @@
1
+ //= require jquery_nested_form
2
+ //= require jquery.battatech.excelexport
@@ -0,0 +1,180 @@
1
+ /*
2
+ * jQuery Client Side Excel Export Plugin Library
3
+ * http://www.battatech.com/
4
+ *
5
+ * Copyright (c) 2013 Batta Tech Private Limited
6
+ * Licensed under https://github.com/battatech/battatech_excelexport/blob/master/LICENSE.txt
7
+ */
8
+
9
+ (function ($) {
10
+ var $defaults = {
11
+ containerid: null
12
+ , datatype: 'table'
13
+ , dataset: null
14
+ , columns: null
15
+ , returnUri: false
16
+ , worksheetName: "Sheet1"
17
+ , encoding: "utf-8"
18
+ };
19
+
20
+ var $settings = $defaults;
21
+
22
+ $.fn.battatech_excelexport = function (options) {
23
+ $settings = $.extend({}, $defaults, options);
24
+
25
+ var gridData = [];
26
+ var excelData;
27
+
28
+ return Initialize();
29
+
30
+ function Initialize() {
31
+ var type = $settings.datatype.toLowerCase();
32
+
33
+ BuildDataStructure(type);
34
+
35
+ switch (type) {
36
+ case 'table':
37
+ excelData = Export(ConvertFromTable());
38
+ break;
39
+ case 'json':
40
+ excelData = Export(ConvertDataStructureToTable());
41
+ break;
42
+ case 'xml':
43
+ excelData = Export(ConvertDataStructureToTable());
44
+ break;
45
+ case 'jqgrid':
46
+ excelData = Export(ConvertDataStructureToTable());
47
+ break;
48
+ }
49
+
50
+ if ($settings.returnUri) {
51
+ return excelData;
52
+ }
53
+ else {
54
+ window.open(excelData);
55
+ }
56
+ }
57
+
58
+ function BuildDataStructure(type) {
59
+ switch (type) {
60
+ case 'table':
61
+ break;
62
+ case 'json':
63
+ gridData = $settings.dataset;
64
+ break;
65
+ case 'xml':
66
+ $($settings.dataset).find("row").each(function (key, value) {
67
+ var item = {};
68
+
69
+ if (this.attributes != null && this.attributes.length > 0) {
70
+ $(this.attributes).each(function () {
71
+ item[this.name] = this.value;
72
+ });
73
+
74
+ gridData.push(item);
75
+ }
76
+ });
77
+ break;
78
+ case 'jqgrid':
79
+ $($settings.dataset).find("rows > row").each(function (key, value) {
80
+ var item = {};
81
+
82
+ if (this.children != null && this.children.length > 0) {
83
+ $(this.children).each(function () {
84
+ item[this.tagName] = $(this).text();
85
+ });
86
+
87
+ gridData.push(item);
88
+ }
89
+ });
90
+ break;
91
+ }
92
+ }
93
+
94
+ function ConvertFromTable() {
95
+ var result = $('<div>').append($('#' + $settings.containerid).clone()).html();
96
+ return result;
97
+ }
98
+
99
+ function ConvertDataStructureToTable() {
100
+ var result = "<table>";
101
+
102
+ result += "<thead><tr>";
103
+ $($settings.columns).each(function (key, value) {
104
+ if (this.ishidden != true) {
105
+ result += "<th";
106
+ if (this.width != null) {
107
+ result += " style='width: " + this.width + "'";
108
+ }
109
+ result += ">";
110
+ result += this.headertext;
111
+ result += "</th>";
112
+ }
113
+ });
114
+ result += "</tr></thead>";
115
+
116
+ result += "<tbody>";
117
+ $(gridData).each(function (key, value) {
118
+ result += "<tr>";
119
+ $($settings.columns).each(function (k, v) {
120
+ if (value.hasOwnProperty(this.datafield)) {
121
+ if (this.ishidden != true) {
122
+ result += "<td";
123
+ if (this.width != null) {
124
+ result += " style='width: " + this.width + "'";
125
+ }
126
+ result += ">";
127
+ result += value[this.datafield];
128
+ result += "</td>";
129
+ }
130
+ }
131
+ });
132
+ result += "</tr>";
133
+ });
134
+ result += "</tbody>";
135
+
136
+ result += "</table>";
137
+ return result;
138
+ }
139
+
140
+ function Export(htmltable) {
141
+ var excelFile = "<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:x='urn:schemas-microsoft-com:office:excel' xmlns='http://www.w3.org/TR/REC-html40'>";
142
+ excelFile += "<head>";
143
+ excelFile += '<meta http-equiv="Content-type" content="text/html;charset=' + $defaults.encoding + '" />';
144
+ excelFile += "<!--[if gte mso 9]>";
145
+ excelFile += "<xml>";
146
+ excelFile += "<x:ExcelWorkbook>";
147
+ excelFile += "<x:ExcelWorksheets>";
148
+ excelFile += "<x:ExcelWorksheet>";
149
+ excelFile += "<x:Name>";
150
+ excelFile += "{worksheet}";
151
+ excelFile += "</x:Name>";
152
+ excelFile += "<x:WorksheetOptions>";
153
+ excelFile += "<x:DisplayGridlines/>";
154
+ excelFile += "</x:WorksheetOptions>";
155
+ excelFile += "</x:ExcelWorksheet>";
156
+ excelFile += "</x:ExcelWorksheets>";
157
+ excelFile += "</x:ExcelWorkbook>";
158
+ excelFile += "</xml>";
159
+ excelFile += "<![endif]-->";
160
+ excelFile += "</head>";
161
+ excelFile += "<body>";
162
+ excelFile += htmltable.replace(/"/g, '\'');
163
+ excelFile += "</body>";
164
+ excelFile += "</html>";
165
+
166
+ var uri = "data:application/vnd.ms-excel;base64,";
167
+ var ctx = { worksheet: $settings.worksheetName, table: htmltable };
168
+
169
+ return (uri + base64(format(excelFile, ctx)));
170
+ }
171
+
172
+ function base64(s) {
173
+ return window.btoa(unescape(encodeURIComponent(s)));
174
+ }
175
+
176
+ function format(s, c) {
177
+ return s.replace(/{(\w+)}/g, function (m, p) { return c[p]; });
178
+ }
179
+ };
180
+ })(jQuery);
@@ -0,0 +1,83 @@
1
+ class ForemanHosts::SyhostmodeldetailsController < ApplicationController
2
+ # GET /syhostmodeldetails
3
+ # GET /syhostmodeldetails.json
4
+ def index
5
+ @syhostmodeldetails = ForemanHosts::Syhostmodeldetail.all.paginate(:page => params[:page])
6
+
7
+ respond_to do |format|
8
+ format.html # index.html.erb
9
+ format.json { render json: @syhostmodeldetails }
10
+ end
11
+ end
12
+
13
+ # GET /syhostmodeldetails/1
14
+ # GET /syhostmodeldetails/1.json
15
+ def show
16
+ @syhostmodeldetail = ForemanHosts::Syhostmodeldetail.find(params[:id])
17
+
18
+ respond_to do |format|
19
+ format.html # show.html.erb
20
+ format.json { render json: @syhostmodeldetail }
21
+ end
22
+ end
23
+
24
+ # GET /syhostmodeldetails/new
25
+ # GET /syhostmodeldetails/new.json
26
+ def new
27
+ @syhostmodeldetail = ForemanHosts::Syhostmodeldetail.new
28
+ respond_to do |format|
29
+ format.html # new.html.erb
30
+ format.json { render json: @syhostmodeldetail }
31
+ end
32
+ end
33
+
34
+ # GET /syhostmodeldetails/1/edit
35
+ def edit
36
+ @syhostmodeldetail = ForemanHosts::Syhostmodeldetail.find(params[:id])
37
+ end
38
+
39
+ # POST /syhostmodeldetails
40
+ # POST /syhostmodeldetails.json
41
+ def create
42
+ @syhostmodeldetail = ForemanHosts::Syhostmodeldetail.new(params[:foreman_hosts_syhostmodeldetail])
43
+
44
+ respond_to do |format|
45
+ if @syhostmodeldetail.save
46
+ format.html { redirect_to @syhostmodeldetail, notice: 'syhostmodeldetail was successfully created.' }
47
+ format.json { render json: @syhostmodeldetail, status: :created, location: @syhostmodeldetail }
48
+ else
49
+ format.html { render action: "new" }
50
+ format.json { render json: @syhostmodeldetail.errors, status: :unprocessable_entity }
51
+ end
52
+ end
53
+ end
54
+
55
+ # PUT /syhostmodeldetails/1
56
+ # PUT /syhostmodeldetails/1.json
57
+ def update
58
+ @syhostmodeldetail = ForemanHosts::Syhostmodeldetail.find(params[:id])
59
+
60
+ respond_to do |format|
61
+ if @syhostmodeldetail.update_attributes(params[:foreman_hosts_syhostmodeldetail])
62
+ format.html { redirect_to @syhostmodeldetail, notice: 'syhostmodeldetail was successfully updated.' }
63
+ format.json { head :no_content }
64
+ else
65
+ format.html { render action: "edit" }
66
+ format.json { render json: @syhostmodeldetail.errors, status: :unprocessable_entity }
67
+ end
68
+ end
69
+ end
70
+
71
+ # DELETE /syhostmodeldetails/1
72
+ # DELETE /syhostmodeldetails/1.json
73
+ def destroy
74
+ @syhostmodeldetail = ForemanHosts::Syhostmodeldetail.find(params[:id])
75
+ @syhostmodeldetail.destroy
76
+ respond_to do |format|
77
+ format.html { redirect_to foreman_hosts_syhostmodeldetails_url }
78
+ format.json { head :no_content }
79
+ end
80
+
81
+
82
+ end
83
+ end
@@ -0,0 +1,83 @@
1
+ class ForemanHosts::SyhostmodelsController < ApplicationController
2
+ # GET /syhostmodels
3
+ # GET /syhostmodels.json
4
+ def index
5
+ @syhostmodels = ForemanHosts::Syhostmodel.all.paginate(:page => params[:page])
6
+
7
+ respond_to do |format|
8
+ format.html # index.html.erb
9
+ format.json { render json: @syhostmodels }
10
+ end
11
+ end
12
+
13
+ # GET /syhostmodels/1
14
+ # GET /syhostmodels/1.json
15
+ def show
16
+ @syhostmodel = ForemanHosts::Syhostmodel.find(params[:id])
17
+
18
+ respond_to do |format|
19
+ format.html # show.html.erb
20
+ format.json { render json: @syhostmodel }
21
+ end
22
+ end
23
+
24
+ # GET /syhostmodels/new
25
+ # GET /syhostmodels/new.json
26
+ def new
27
+ @syhostmodel = ForemanHosts::Syhostmodel.new
28
+ respond_to do |format|
29
+ format.html # new.html.erb
30
+ format.json { render json: @syhostmodel }
31
+ end
32
+ end
33
+
34
+ # GET /syhostmodels/1/edit
35
+ def edit
36
+ @syhostmodel = ForemanHosts::Syhostmodel.find(params[:id])
37
+ end
38
+
39
+ # POST /syhostmodels
40
+ # POST /syhostmodels.json
41
+ def create
42
+ @syhostmodel = ForemanHosts::Syhostmodel.new(params[:foreman_hosts_syhostmodel])
43
+
44
+ respond_to do |format|
45
+ if @syhostmodel.save
46
+ format.html { redirect_to @syhostmodel, notice: 'syhostmodel was successfully created.' }
47
+ format.json { render json: @syhostmodel, status: :created, location: @syhostmodel }
48
+ else
49
+ format.html { render action: "new" }
50
+ format.json { render json: @syhostmodel.errors, status: :unprocessable_entity }
51
+ end
52
+ end
53
+ end
54
+
55
+ # PUT /syhostmodels/1
56
+ # PUT /syhostmodels/1.json
57
+ def update
58
+ @syhostmodel = ForemanHosts::Syhostmodel.find(params[:id])
59
+
60
+ respond_to do |format|
61
+ if @syhostmodel.update_attributes(params[:foreman_hosts_syhostmodel])
62
+ format.html { redirect_to @syhostmodel, notice: 'syhostmodel was successfully updated.' }
63
+ format.json { head :no_content }
64
+ else
65
+ format.html { render action: "edit" }
66
+ format.json { render json: @syhostmodel.errors, status: :unprocessable_entity }
67
+ end
68
+ end
69
+ end
70
+
71
+ # DELETE /syhostmodels/1
72
+ # DELETE /syhostmodels/1.json
73
+ def destroy
74
+ @syhostmodel = ForemanHosts::Syhostmodel.find(params[:id])
75
+ @syhostmodel.destroy
76
+ respond_to do |format|
77
+ format.html { redirect_to foreman_hosts_syhostmodels_url }
78
+ format.json { head :no_content }
79
+ end
80
+
81
+
82
+ end
83
+ end
@@ -16,4 +16,4 @@ module ForemanHosts
16
16
  end
17
17
  end
18
18
  end
19
- end
19
+ end
@@ -0,0 +1,8 @@
1
+ class ForemanHosts::Syhostmodel < ActiveRecord::Base
2
+
3
+ attr_accessible :name, :remark, :syhostmodeldetails_attributes
4
+ has_many :syhostmodeldetails, class_name: "ForemanHosts::Syhostmodeldetail"
5
+ accepts_nested_attributes_for :syhostmodeldetails, reject_if: proc { |attributes| attributes['no'].blank?| attributes['status'].blank? | attributes['fact_name_id'].blank? } , allow_destroy: true
6
+
7
+
8
+ end
@@ -0,0 +1,5 @@
1
+ class ForemanHosts::Syhostmodeldetail < ActiveRecord::Base
2
+ attr_accessible :no, :status, :fact_name_id, :syhostmodel_id, :syhostmodel_type
3
+ belongs_to :foreman_hosts_syhostmodel, class_name: "ForemanHosts::Syhostmodel",foreign_key: "syhostmodel_id"
4
+ belongs_to :fact_name, class_name: "FactName", foreign_key: "fact_name_id"
5
+ end
@@ -24,9 +24,13 @@
24
24
  <tr>
25
25
  <td class='ellipsis'><%= name_column(host) %></td>
26
26
 
27
- <% @fact_names.each do |fact_name| %>
28
- <td><%= get_fact_value(host, fact_name) %> </td>
29
- <% end %>
27
+ <% @fact_names.each do |fact_name| %>
28
+ <td>
29
+ <%= FactValue.where(host_id: host.id, fact_name_id: fact_name.id).last.value rescue nil%>
30
+ </td>
31
+ <% end %>
32
+
33
+
30
34
 
31
35
  </tr>
32
36
  <% end %>
@@ -69,4 +73,185 @@
69
73
  }
70
74
 
71
75
  }
76
+ /*
77
+ * jQuery Client Side Excel Export Plugin Library
78
+ * http://www.battatech.com/
79
+ *
80
+ * Copyright (c) 2013 Batta Tech Private Limited
81
+ * Licensed under https://github.com/battatech/battatech_excelexport/blob/master/LICENSE.txt
82
+ */
83
+
84
+ (function ($) {
85
+ var $defaults = {
86
+ containerid: null
87
+ , datatype: 'table'
88
+ , dataset: null
89
+ , columns: null
90
+ , returnUri: false
91
+ , worksheetName: "Sheet1"
92
+ , encoding: "utf-8"
93
+ };
94
+
95
+ var $settings = $defaults;
96
+
97
+ $.fn.battatech_excelexport = function (options) {
98
+ $settings = $.extend({}, $defaults, options);
99
+
100
+ var gridData = [];
101
+ var excelData;
102
+
103
+ return Initialize();
104
+
105
+ function Initialize() {
106
+ var type = $settings.datatype.toLowerCase();
107
+
108
+ BuildDataStructure(type);
109
+
110
+ switch (type) {
111
+ case 'table':
112
+ excelData = Export(ConvertFromTable());
113
+ break;
114
+ case 'json':
115
+ excelData = Export(ConvertDataStructureToTable());
116
+ break;
117
+ case 'xml':
118
+ excelData = Export(ConvertDataStructureToTable());
119
+ break;
120
+ case 'jqgrid':
121
+ excelData = Export(ConvertDataStructureToTable());
122
+ break;
123
+ }
124
+
125
+ if ($settings.returnUri) {
126
+ return excelData;
127
+ }
128
+ else {
129
+ window.open(excelData);
130
+ }
131
+ }
132
+
133
+ function BuildDataStructure(type) {
134
+ switch (type) {
135
+ case 'table':
136
+ break;
137
+ case 'json':
138
+ gridData = $settings.dataset;
139
+ break;
140
+ case 'xml':
141
+ $($settings.dataset).find("row").each(function (key, value) {
142
+ var item = {};
143
+
144
+ if (this.attributes != null && this.attributes.length > 0) {
145
+ $(this.attributes).each(function () {
146
+ item[this.name] = this.value;
147
+ });
148
+
149
+ gridData.push(item);
150
+ }
151
+ });
152
+ break;
153
+ case 'jqgrid':
154
+ $($settings.dataset).find("rows > row").each(function (key, value) {
155
+ var item = {};
156
+
157
+ if (this.children != null && this.children.length > 0) {
158
+ $(this.children).each(function () {
159
+ item[this.tagName] = $(this).text();
160
+ });
161
+
162
+ gridData.push(item);
163
+ }
164
+ });
165
+ break;
166
+ }
167
+ }
168
+
169
+ function ConvertFromTable() {
170
+ var result = $('<div>').append($('#' + $settings.containerid).clone()).html();
171
+ return result;
172
+ }
173
+
174
+ function ConvertDataStructureToTable() {
175
+ var result = "<table>";
176
+
177
+ result += "<thead><tr>";
178
+ $($settings.columns).each(function (key, value) {
179
+ if (this.ishidden != true) {
180
+ result += "<th";
181
+ if (this.width != null) {
182
+ result += " style='width: " + this.width + "'";
183
+ }
184
+ result += ">";
185
+ result += this.headertext;
186
+ result += "</th>";
187
+ }
188
+ });
189
+ result += "</tr></thead>";
190
+
191
+ result += "<tbody>";
192
+ $(gridData).each(function (key, value) {
193
+ result += "<tr>";
194
+ $($settings.columns).each(function (k, v) {
195
+ if (value.hasOwnProperty(this.datafield)) {
196
+ if (this.ishidden != true) {
197
+ result += "<td";
198
+ if (this.width != null) {
199
+ result += " style='width: " + this.width + "'";
200
+ }
201
+ result += ">";
202
+ result += value[this.datafield];
203
+ result += "</td>";
204
+ }
205
+ }
206
+ });
207
+ result += "</tr>";
208
+ });
209
+ result += "</tbody>";
210
+
211
+ result += "</table>";
212
+ return result;
213
+ }
214
+
215
+ function Export(htmltable) {
216
+ var excelFile = "<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:x='urn:schemas-microsoft-com:office:excel' xmlns='http://www.w3.org/TR/REC-html40'>";
217
+ excelFile += "<head>";
218
+ excelFile += '<meta http-equiv="Content-type" content="text/html;charset=' + $defaults.encoding + '" />';
219
+ excelFile += "<!--[if gte mso 9]>";
220
+ excelFile += "<xml>";
221
+ excelFile += "<x:ExcelWorkbook>";
222
+ excelFile += "<x:ExcelWorksheets>";
223
+ excelFile += "<x:ExcelWorksheet>";
224
+ excelFile += "<x:Name>";
225
+ excelFile += "{worksheet}";
226
+ excelFile += "</x:Name>";
227
+ excelFile += "<x:WorksheetOptions>";
228
+ excelFile += "<x:DisplayGridlines/>";
229
+ excelFile += "</x:WorksheetOptions>";
230
+ excelFile += "</x:ExcelWorksheet>";
231
+ excelFile += "</x:ExcelWorksheets>";
232
+ excelFile += "</x:ExcelWorkbook>";
233
+ excelFile += "</xml>";
234
+ excelFile += "<![endif]-->";
235
+ excelFile += "</head>";
236
+ excelFile += "<body>";
237
+ excelFile += htmltable.replace(/"/g, '\'');
238
+ excelFile += "</body>";
239
+ excelFile += "</html>";
240
+
241
+ var uri = "data:application/vnd.ms-excel;base64,";
242
+ var ctx = { worksheet: $settings.worksheetName, table: htmltable };
243
+
244
+ return (uri + base64(format(excelFile, ctx)));
245
+ }
246
+
247
+ function base64(s) {
248
+ return window.btoa(unescape(encodeURIComponent(s)));
249
+ }
250
+
251
+ function format(s, c) {
252
+ return s.replace(/{(\w+)}/g, function (m, p) { return c[p]; });
253
+ }
254
+ };
255
+ })(jQuery);
256
+
72
257
  </script>