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.

linked_with.js 2.4 KiB

12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. var wrapper = $('<div class="panel panel-default"><div>').appendTo(parent);
  58. $('<div class="panel-heading">').html(wn._(doctype).bold()).appendTo(wrapper);
  59. var body = $('<div class="panel-body">').appendTo(wrapper)
  60. .css({"padding-top": "0px", "padding-bottom": "0px"});
  61. $.each(r.message[doctype], function(i, d) {
  62. d.doctype = doctype;
  63. listview.render($("<div>")
  64. .appendTo(body), d, me);
  65. })
  66. })
  67. } else {
  68. parent.html(wn._("Not Linked to any record."));
  69. }
  70. }
  71. })
  72. }
  73. },
  74. });