blob: f39618685d28cc98fa385b10aae21fb21ccc5126 [file] [log] [blame]
Rushabh Mehtae67d1fb2013-08-05 14:59:54 +05301// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
2// License: GNU General Public License v3. See license.txt
3
Rushabh Mehta2f7e1ab2013-06-26 17:20:12 +05304wn.pages['Setup'].onload = function(wrapper) {
5 if(msg_dialog && msg_dialog.display) msg_dialog.hide();
6 wn.ui.make_app_page({
7 parent: wrapper,
8 title: 'Setup',
9 single_column: true
10 });
Rushabh Mehta3966f1d2012-02-23 12:35:32 +053011
Rushabh Mehta2f7e1ab2013-06-26 17:20:12 +053012 wrapper.appframe.add_module_icon("Setup");
Rushabh Mehta8f81a6f2013-07-25 15:01:44 +053013 wrapper.appframe.add_button("Refresh", function() {
14 wn.pages.Setup.make(wrapper);
15 }, "icon-refresh");
Rushabh Mehta2f7e1ab2013-06-26 17:20:12 +053016
Rushabh Mehta8f81a6f2013-07-25 15:01:44 +053017 wn.pages.Setup.make(wrapper);
18
19}
20
21wn.pages.Setup.make = function(wrapper) {
Rushabh Mehta2f7e1ab2013-06-26 17:20:12 +053022 var body = $(wrapper).find(".layout-main"),
23 total = 0,
24 completed = 0;
Rushabh Mehta978d4e82013-01-09 17:23:45 +053025
Rushabh Mehta2f7e1ab2013-06-26 17:20:12 +053026 body.html('<div class="progress progress-striped active">\
Anand Doshia648f462013-07-30 14:42:15 +053027 <div class="progress-bar" style="width: 100%;"></div></div>');
Rushabh Mehta2f7e1ab2013-06-26 17:20:12 +053028
29 var render_item = function(item, dependency) {
30 if(item.type==="Section") {
31 $("<h3>")
32 .css({"margin": "20px 0px 15px 0px"})
33 .html('<i class="'+item.icon+'"></i> ' + item.title).appendTo(body);
34 return;
35 }
36 var row = $('<div class="row">')
37 .css({
38 "margin-bottom": "7px",
39 "padding-bottom": "7px",
40 "border-bottom": "1px solid #eee"
41 })
42 .appendTo(body);
43
Rushabh Mehtacce21d12013-08-21 17:48:08 +053044 $('<div class="col-md-1"></div>').appendTo(row);
Anand Doshia648f462013-07-30 14:42:15 +053045
Rushabh Mehta2f7e1ab2013-06-26 17:20:12 +053046 if(item.type==="Link") {
Rushabh Mehtacce21d12013-08-21 17:48:08 +053047 var col = $('<div class="col-md-5"><b><a href="#'
Rushabh Mehta2f7e1ab2013-06-26 17:20:12 +053048 +item.route+'"><i class="'+item.icon+'"></i> '
49 +item.title+'</a></b></div>').appendTo(row);
Anand Doshia648f462013-07-30 14:42:15 +053050
Rushabh Mehta2f7e1ab2013-06-26 17:20:12 +053051 } else {
Rushabh Mehtacce21d12013-08-21 17:48:08 +053052 var col = $(repl('<div class="col-md-5">\
Anand Doshi946e0de2013-07-11 18:26:00 +053053 <span class="badge view-link">%(count)s</span>\
Rushabh Mehta44c14472013-07-09 10:42:10 +053054 <b><i class="%(icon)s"></i>\
55 <a class="data-link">%(title)s</a></b>\
56 </div>', {
57 count: item.count,
58 title: wn._(item.title || item.doctype),
59 icon: wn.boot.doctype_icons[item.doctype]
60 }))
Rushabh Mehta2f7e1ab2013-06-26 17:20:12 +053061 .appendTo(row);
62
Rushabh Mehta2f7e1ab2013-06-26 17:20:12 +053063 col.find(".badge")
64 .css({
65 "background-color": (item.count ? "green" : "orange"),
66 "display": "inline-block",
67 "min-width": "40px"
68 });
69
70 total += 1;
71 if(item.count)
72 completed += 1;
73 }
Rushabh Mehta65d12922013-06-26 22:31:22 +053074
75 if(dependency)
Rushabh Mehtacce21d12013-08-21 17:48:08 +053076 col.addClass("col-md-offset-1");
Rushabh Mehta65d12922013-06-26 22:31:22 +053077 else
Rushabh Mehtacce21d12013-08-21 17:48:08 +053078 $('<div class="col-md-1"></div>').appendTo(row);
Anand Doshia648f462013-07-30 14:42:15 +053079
Rushabh Mehta2f7e1ab2013-06-26 17:20:12 +053080 if(item.doctype) {
Rushabh Mehta44c14472013-07-09 10:42:10 +053081 var badge = col.find(".badge, .data-link")
Rushabh Mehta2f7e1ab2013-06-26 17:20:12 +053082 .attr("data-doctype", item.doctype)
83 .css({"cursor": "pointer"})
Anand Doshia648f462013-07-30 14:42:15 +053084
Rushabh Mehta44c14472013-07-09 10:42:10 +053085 if(item.single) {
86 badge.click(function() {
87 wn.set_route("Form", $(this).attr("data-doctype"))
88 })
89 } else {
90 badge.click(function() {
Rushabh Mehta65d12922013-06-26 22:31:22 +053091 wn.set_route(item.tree || "List", $(this).attr("data-doctype"))
Rushabh Mehta2f7e1ab2013-06-26 17:20:12 +053092 })
Rushabh Mehta44c14472013-07-09 10:42:10 +053093 }
Rushabh Mehta2f7e1ab2013-06-26 17:20:12 +053094 }
Anand Doshia648f462013-07-30 14:42:15 +053095
Rushabh Mehta2f7e1ab2013-06-26 17:20:12 +053096 // tree
Rushabh Mehtacce21d12013-08-21 17:48:08 +053097 $links = $('<div class="col-md-5">').appendTo(row);
Anand Doshia648f462013-07-30 14:42:15 +053098
Rushabh Mehta2f7e1ab2013-06-26 17:20:12 +053099 if(item.tree) {
100 $('<a class="view-link"><i class="icon-sitemap"></i> Browse</a>\
101 <span class="text-muted">|</span> \
102 <a class="import-link"><i class="icon-upload"></i> Import</a>')
103 .appendTo($links)
104
Rushabh Mehta44c14472013-07-09 10:42:10 +0530105 var mylink = $links.find(".view-link")
Rushabh Mehta2f7e1ab2013-06-26 17:20:12 +0530106 .attr("data-doctype", item.doctype)
Rushabh Mehta44c14472013-07-09 10:42:10 +0530107
108 mylink.click(function() {
109 wn.set_route(item.tree, item.doctype);
110 })
Anand Doshia648f462013-07-30 14:42:15 +0530111
Rushabh Mehta2f7e1ab2013-06-26 17:20:12 +0530112 } else if(item.single) {
113 $('<a class="view-link"><i class="icon-edit"></i> Edit</a>')
114 .appendTo($links)
115
116 $links.find(".view-link")
117 .attr("data-doctype", item.doctype)
118 .click(function() {
119 wn.set_route("Form", $(this).attr("data-doctype"));
120 })
121 } else if(item.type !== "Link"){
122 $('<a class="new-link"><i class="icon-plus"></i> New</a> \
123 <span class="text-muted">|</span> \
124 <a class="view-link"><i class="icon-list"></i> View</a> \
125 <span class="text-muted">|</span> \
126 <a class="import-link"><i class="icon-upload"></i> Import</a>')
127 .appendTo($links)
128
129 $links.find(".view-link")
130 .attr("data-doctype", item.doctype)
131 .click(function() {
132 if($(this).attr("data-filter")) {
133 wn.route_options = JSON.parse($(this).attr("data-filter"));
134 }
135 wn.set_route("List", $(this).attr("data-doctype"));
136 })
137
138 if(item.filter)
139 $links.find(".view-link").attr("data-filter", JSON.stringify(item.filter))
140
141 if(wn.model.can_create(item.doctype)) {
142 $links.find(".new-link")
143 .attr("data-doctype", item.doctype)
144 .click(function() {
145 new_doc($(this).attr("data-doctype"))
146 })
147 } else {
148 $links.find(".new-link").remove();
149 $links.find(".text-muted:first").remove();
150 }
151
152 }
153
154 $links.find(".import-link")
155 .attr("data-doctype", item.doctype)
156 .click(function() {
157 wn.route_options = {doctype:$(this).attr("data-doctype")}
158 wn.set_route("data-import-tool");
159 })
Anand Doshia648f462013-07-30 14:42:15 +0530160
Rushabh Mehta2f7e1ab2013-06-26 17:20:12 +0530161 if(item.links) {
162 $.each(item.links, function(i, link) {
163 var newlinks = $('<span class="text-muted"> |</span> \
164 <a class="import-link" href="#'+link.route
165 +'"><i class="'+link.icon+'"></i> '+link.title+'</a>')
166 .appendTo($links)
167 })
168 }
Anand Doshia648f462013-07-30 14:42:15 +0530169
Rushabh Mehta2f7e1ab2013-06-26 17:20:12 +0530170 if(item.dependencies) {
171 $.each(item.dependencies, function(i, d) {
172 render_item(d, true);
173 })
174 }
Anand Doshi197d1b42012-12-07 15:21:34 +0530175 }
Anand Doshia648f462013-07-30 14:42:15 +0530176
177 return wn.call({
178 method: "setup.page.setup.setup.get",
179 callback: function(r) {
180 if(r.message) {
181 body.empty();
182 if(wn.boot.expires_on) {
183 $(body).prepend("<div class='text-muted' style='text-align:right'>Account expires on "
184 + wn.datetime.global_date_format(wn.boot.expires_on) + "</div>");
185 }
186
187 $completed = $('<h4>Setup Completed <span class="completed-percent"></span><h4>\
188 <div class="progress"><div class="progress-bar"></div></div>')
189 .appendTo(body);
190
191 $.each(r.message, function(i, item) {
192 render_item(item)
193 });
194
195 var completed_percent = cint(flt(completed) / total * 100) + "%";
196 $completed
197 .find(".progress-bar")
198 .css({"width": completed_percent});
199 $(body)
200 .find(".completed-percent")
201 .html("(" + completed_percent + ")");
202 }
203 }
204 });
Rushabh Mehtac5471dd2012-02-22 12:07:42 +0530205}