25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 
 

234 satır
6.6 KiB

  1. wn.pages['user-properties'].onload = function(wrapper) {
  2. wn.ui.make_app_page({
  3. parent: wrapper,
  4. title: 'User Properties',
  5. single_column: true
  6. });
  7. $(wrapper).find(".layout-main").html("<div class='user-settings'></div>\
  8. <table class='table table-bordered' style='background-color: #f9f9f9;'>\
  9. <tr><td>\
  10. <h4><i class='icon-question-sign'></i> "+wn._("Quick Help for User Properties")+":</h4>\
  11. <ol>\
  12. <li>"+wn._("You can set various 'properties' to Users to set default values and apply permission rules based on the value of these properties in various forms.")+"</li>\
  13. <li>"+wn._("These properties are Link Type fields from all Documents.")+"</li>\
  14. <li>"+wn._("These properties will appear as values in forms that contain them.")+"</li>\
  15. <li>"+wn._("These properties can also be used to 'assign' a particular document, whose property matches with the User's property to a User. These can be set using the <a href='#permission-manager'>Permission Manager</a>")+"</li>\
  16. <li>"+wn._("A user can have multiple values for a property.")+"</li>\
  17. </ol>\
  18. </tr></td>\
  19. </table>");
  20. wrapper.user_properties = new wn.UserProperties(wrapper);
  21. }
  22. wn.pages['user-properties'].refresh = function(wrapper) {
  23. wrapper.user_properties.set_from_route();
  24. }
  25. wn.UserProperties = Class.extend({
  26. init: function(wrapper) {
  27. this.wrapper = wrapper;
  28. this.body = $(this.wrapper).find(".user-settings");
  29. this.make();
  30. this.refresh();
  31. },
  32. make: function() {
  33. var me = this;
  34. return wn.call({
  35. module:"core",
  36. page:"user_properties",
  37. method: "get_users_and_links",
  38. callback: function(r) {
  39. me.options = r.message;
  40. me.user_select =
  41. me.wrapper.appframe.add_select("users",
  42. ["Select User..."].concat(r.message.users))
  43. .css("width", "200px")
  44. .change(function() {
  45. me.set_route();
  46. });
  47. me.property_select =
  48. me.wrapper.appframe.add_select("links",
  49. ["Select Property..."].concat(me.get_link_names()))
  50. .css("width", "200px")
  51. .change(function() {
  52. me.set_route();
  53. });
  54. me.set_from_route();
  55. }
  56. });
  57. },
  58. get_link_names: function() {
  59. return $.map(this.options.link_fields, function(l) { return l[0]; });
  60. },
  61. set_route: function() {
  62. wn.set_route("user-properties", this.user_select.val(),
  63. this.property_select.val());
  64. },
  65. set_from_route: function() {
  66. var route = wn.get_route();
  67. if((route.length > 1) && this.user_select && this.property_select) {
  68. this.user_select.val(route[1]);
  69. this.property_select.val(route[2]);
  70. }
  71. this.refresh();
  72. },
  73. get_user: function() {
  74. var user = this.user_select.val();
  75. return user=="Select User..." ? null : user;
  76. },
  77. get_property: function() {
  78. var property = this.property_select.val();
  79. return property=="Select Property..." ? null : property;
  80. },
  81. render: function(prop_list) {
  82. this.body.empty();
  83. this.prop_list = prop_list;
  84. if(!prop_list.length) {
  85. this.body.html("<div class='alert alert-info'>"+wn._("No User Properties found.")+"</div>");
  86. } else {
  87. this.show_property_table();
  88. }
  89. this.show_add_property();
  90. },
  91. refresh: function() {
  92. var me = this;
  93. if(!me.user_select) {
  94. this.body.html("<div class='alert alert-info'>"+wn._("Loading")+"...</div>");
  95. return;
  96. }
  97. if(!me.get_user() && !me.get_property()) {
  98. this.body.html("<div class='alert alert-warning'>"+wn._("Select User or Property to start.")+"</div>");
  99. return;
  100. }
  101. // get permissions
  102. return wn.call({
  103. module: "core",
  104. page: "user_properties",
  105. method: "get_properties",
  106. args: {
  107. user: me.get_user(),
  108. key: me.get_property()
  109. },
  110. callback: function(r) {
  111. me.render(r.message);
  112. }
  113. });
  114. },
  115. show_property_table: function() {
  116. var me = this;
  117. this.table = $("<table class='table table-bordered'>\
  118. <thead><tr></tr></thead>\
  119. <tbody></tbody>\
  120. </table>").appendTo(this.body);
  121. $.each([[wn._("User"), 150], [wn._("Property"), 150], [wn._("Value"),150], ["", 50]],
  122. function(i, col) {
  123. $("<th>").html(col[0]).css("width", col[1]+"px")
  124. .appendTo(me.table.find("thead tr"));
  125. });
  126. $.each(this.prop_list, function(i, d) {
  127. var row = $("<tr>").appendTo(me.table.find("tbody"));
  128. $("<td>").html('<a href="#Form/Profile/'+d.parent+'">'
  129. +d.parent+'</a>').appendTo(row);
  130. $("<td>").html(d.defkey).appendTo(row);
  131. $("<td>").html(d.defvalue).appendTo(row);
  132. me.add_delete_button(row, d);
  133. });
  134. },
  135. add_delete_button: function(row, d) {
  136. var me = this;
  137. $("<button class='btn btn-small'><i class='icon-remove'></i></button>")
  138. .appendTo($("<td>").appendTo(row))
  139. .attr("data-name", d.name)
  140. .attr("data-user", d.parent)
  141. .click(function() {
  142. return wn.call({
  143. module: "core",
  144. page: "user_properties",
  145. method: "remove",
  146. args: {
  147. name: $(this).attr("data-name"),
  148. user: $(this).attr("data-user")
  149. },
  150. callback: function(r) {
  151. if(r.exc) {
  152. msgprint("Did not remove.");
  153. } else {
  154. me.refresh();
  155. }
  156. }
  157. })
  158. });
  159. },
  160. show_add_property: function() {
  161. var me = this;
  162. $("<button class='btn btn-info'>"+wn._("Add A Property")+"</button>")
  163. .appendTo($("<p>").appendTo(this.body))
  164. .click(function() {
  165. var d = new wn.ui.Dialog({
  166. title: "Add New Property",
  167. fields: [
  168. {fieldtype:"Select", label:wn._("User"),
  169. options:me.options.users, reqd:1, fieldname:"parent"},
  170. {fieldtype:"Select", label: wn._("Property"), fieldname:"defkey",
  171. options:me.get_link_names(), reqd:1},
  172. {fieldtype:"Link", label:wn._("Value"), fieldname:"defvalue",
  173. options:'[Select]', reqd:1},
  174. {fieldtype:"Button", label: wn._("Add"), fieldname:"add"},
  175. ]
  176. });
  177. if(me.get_user()) {
  178. d.set_value("parent", me.get_user());
  179. d.get_input("parent").prop("disabled", true);
  180. }
  181. if(me.get_property()) {
  182. d.set_value("defkey", me.get_property());
  183. d.get_input("defkey").prop("disabled", true);
  184. }
  185. d.fields_dict["defvalue"].get_query = function(txt) {
  186. var key = d.get_value("defkey");
  187. var doctype = $.map(me.options.link_fields, function(l) {
  188. if(l[0]==key) return l[1];
  189. })[0];
  190. return {
  191. query: "core.page.user_properties.user_properties.get_defvalue",
  192. filters: {
  193. doctype: doctype
  194. },
  195. doctype: doctype,
  196. }
  197. };
  198. d.get_input("add").click(function() {
  199. var args = d.get_values();
  200. if(!args) {
  201. return;
  202. }
  203. wn.call({
  204. module: "core",
  205. page: "user_properties",
  206. method: "add",
  207. args: args,
  208. callback: function(r) {
  209. if(r.exc) {
  210. msgprint("Did not add.");
  211. } else {
  212. me.refresh();
  213. }
  214. }
  215. })
  216. d.hide();
  217. });
  218. d.show();
  219. });
  220. }
  221. })