You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

83 lines
2.1 KiB

  1. // Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
  2. // MIT License. See license.txt
  3. // for license information please see license.txt
  4. wn.provide("wn.ui.form")
  5. wn.ui.form.LinkedWith = Class.extend({
  6. init: function(opts) {
  7. var me = this;
  8. $.extend(this, opts);
  9. },
  10. show: function() {
  11. if(!this.dialog)
  12. this.make_dialog();
  13. this.dialog.show();
  14. },
  15. make_dialog: function() {
  16. var me = this;
  17. this.linked_with = this.frm.meta.__linked_with;
  18. var links = [];
  19. $.each(this.linked_with, function(doctype, tmp) {
  20. if(wn.model.can_get_report(doctype)) {
  21. links.push({label: wn._(doctype), value: doctype});
  22. }
  23. });
  24. links = wn.utils.sort(links, "label");
  25. this.dialog = new wn.ui.Dialog({
  26. width: 700,
  27. hide_on_page_refresh: true,
  28. title: wn._("Linked With"),
  29. fields: [
  30. { fieldtype: "HTML", label: "list" }
  31. ]
  32. });
  33. if(!links) {
  34. this.dialog.fields_dict.list.$wrapper.html("<div class='alert alert-warning'>"
  35. + this.frm.doctype + ": "
  36. + (this.linked_with ? wn._("Not Linked to any record.") : wn._("Not enough permission to see links."))
  37. + "</div>")
  38. return;
  39. }
  40. this.dialog.onshow = function() {
  41. me.dialog.fields_dict.list.$wrapper.html('<div class="progress progress-striped active">\
  42. <div class="progress-bar" style="width: 100%;">\
  43. </div></div>');
  44. wn.call({
  45. method:"webnotes.widgets.form.utils.get_linked_docs",
  46. args: {
  47. doctype: me.frm.doctype,
  48. name: me.frm.docname,
  49. metadata_loaded: keys(locals.DocType)
  50. },
  51. callback: function(r) {
  52. var parent = me.dialog.fields_dict.list.$wrapper.empty();
  53. if(keys(r.message || {}).length) {
  54. $.each(keys(r.message).sort(), function(i, doctype) {
  55. var listview = wn.views.get_listview(doctype, me);
  56. listview.no_delete = true;
  57. $("<h4>").html(wn._(doctype)).appendTo(parent);
  58. $.each(r.message[doctype], function(i, d) {
  59. d.doctype = doctype;
  60. listview.render($("<div>").appendTo(parent), d, me);
  61. })
  62. })
  63. } else {
  64. parent.html(wn._("Not Linked to any record."));
  65. }
  66. }
  67. })
  68. }
  69. },
  70. });