From 81fa64d4bc10512f01e15208f246d6c23685c012 Mon Sep 17 00:00:00 2001
From: Rushabh Mehta
Date: Wed, 22 May 2019 16:53:28 +0530
Subject: [PATCH] refactor(form.js): remove very old API
---
.../doctype/customize_form/customize_form.js | 102 ---
frappe/model/document.py | 2 +-
frappe/public/build.json | 123 +---
frappe/public/js/frappe/chat.js | 2 +-
frappe/public/js/frappe/dom.js | 87 ---
.../js/frappe/form/controls/base_control.js | 10 -
.../public/js/frappe/form/controls/control.js | 50 ++
frappe/public/js/frappe/form/footer/footer.js | 2 +
frappe/public/js/frappe/form/form.js | 26 +-
frappe/public/js/frappe/form/layout.js | 1 -
frappe/public/js/frappe/form/linked_with.js | 1 -
frappe/public/js/frappe/form/print.js | 79 +-
frappe/public/js/frappe/form/save.js | 2 +-
.../form/script_helpers.js} | 0
.../form/{footer => sidebar}/assign_to.js | 2 +-
.../form/{footer => sidebar}/attachments.js | 2 +-
.../form/{ => sidebar}/document_follow.js | 0
.../frappe/form/{ => sidebar}/form_sidebar.js | 11 +-
.../frappe/form/{ => sidebar}/form_viewers.js | 2 +-
.../js/frappe/form/{ => sidebar}/review.js | 2 +-
.../js/frappe/form/{ => sidebar}/share.js | 2 +-
.../frappe/form/{ => sidebar}/user_image.js | 0
.../{footer => templates}/attachment.html | 0
.../form/templates/form_document_flow.html | 12 -
.../{footer => templates}/form_footer.html | 0
.../form/{footer => templates}/timeline.html | 0
.../{footer => templates}/timeline_item.html | 0
frappe/public/js/frappe/form/toolbar.js | 2 +-
frappe/public/js/frappe/misc/tools.js | 152 ----
frappe/public/js/frappe/provide.js | 24 +-
.../{misc => utils}/address_and_contact.js | 0
.../js/frappe/{misc => utils}/common.js | 0
.../js/{legacy => frappe/utils}/datatype.js | 52 +-
.../js/frappe/{misc => utils}/datetime.js | 0
.../frappe/{misc => utils}/display_image.js | 0
.../{misc => utils}/energy_point_utils.js | 0
.../js/frappe/{misc => utils}/file_manager.js | 0
.../public/js/frappe/{misc => utils}/help.js | 0
.../js/frappe/{misc => utils}/help_links.js | 0
.../public/js/frappe/utils/jquery_plugins.js | 39 +
.../frappe/{misc => utils}/number_format.js | 22 +-
.../js/frappe/{misc => utils}/pretty_date.js | 0
.../frappe/{misc => utils}/preview_email.js | 0
.../frappe/{misc => utils}/rating_icons.html | 0
.../js/frappe/{misc => utils}/ratings.html | 0
.../js/frappe/{misc => utils}/test_utils.js | 0
frappe/public/js/frappe/utils/tools.js | 76 ++
frappe/public/js/frappe/utils/urllib.js | 80 ++
.../public/js/frappe/{misc => utils}/user.js | 0
.../public/js/frappe/{misc => utils}/utils.js | 0
frappe/public/js/legacy/dom.js | 168 -----
frappe/public/js/legacy/globals.js | 38 -
frappe/public/js/legacy/handler.js | 73 --
frappe/public/js/legacy/layout.js | 143 ----
frappe/public/js/legacy/print_format.js | 691 ------------------
frappe/public/js/legacy/print_table.js | 208 ------
frappe/public/js/lib/microtemplate.js | 6 +-
frappe/sessions.py | 3 +-
frappe/utils/csvutils.py | 4 +
59 files changed, 391 insertions(+), 1910 deletions(-)
create mode 100644 frappe/public/js/frappe/form/controls/control.js
rename frappe/public/js/{legacy/client_script_helpers.js => frappe/form/script_helpers.js} (100%)
rename frappe/public/js/frappe/form/{footer => sidebar}/assign_to.js (99%)
rename frappe/public/js/frappe/form/{footer => sidebar}/attachments.js (99%)
rename frappe/public/js/frappe/form/{ => sidebar}/document_follow.js (100%)
rename frappe/public/js/frappe/form/{ => sidebar}/form_sidebar.js (97%)
rename frappe/public/js/frappe/form/{ => sidebar}/form_viewers.js (98%)
rename frappe/public/js/frappe/form/{ => sidebar}/review.js (99%)
rename frappe/public/js/frappe/form/{ => sidebar}/share.js (99%)
rename frappe/public/js/frappe/form/{ => sidebar}/user_image.js (100%)
rename frappe/public/js/frappe/form/{footer => templates}/attachment.html (100%)
delete mode 100644 frappe/public/js/frappe/form/templates/form_document_flow.html
rename frappe/public/js/frappe/form/{footer => templates}/form_footer.html (100%)
rename frappe/public/js/frappe/form/{footer => templates}/timeline.html (100%)
rename frappe/public/js/frappe/form/{footer => templates}/timeline_item.html (100%)
delete mode 100644 frappe/public/js/frappe/misc/tools.js
rename frappe/public/js/frappe/{misc => utils}/address_and_contact.js (100%)
rename frappe/public/js/frappe/{misc => utils}/common.js (100%)
rename frappe/public/js/{legacy => frappe/utils}/datatype.js (64%)
rename frappe/public/js/frappe/{misc => utils}/datetime.js (100%)
rename frappe/public/js/frappe/{misc => utils}/display_image.js (100%)
rename frappe/public/js/frappe/{misc => utils}/energy_point_utils.js (100%)
rename frappe/public/js/frappe/{misc => utils}/file_manager.js (100%)
rename frappe/public/js/frappe/{misc => utils}/help.js (100%)
rename frappe/public/js/frappe/{misc => utils}/help_links.js (100%)
create mode 100644 frappe/public/js/frappe/utils/jquery_plugins.js
rename frappe/public/js/frappe/{misc => utils}/number_format.js (96%)
rename frappe/public/js/frappe/{misc => utils}/pretty_date.js (100%)
rename frappe/public/js/frappe/{misc => utils}/preview_email.js (100%)
rename frappe/public/js/frappe/{misc => utils}/rating_icons.html (100%)
rename frappe/public/js/frappe/{misc => utils}/ratings.html (100%)
rename frappe/public/js/frappe/{misc => utils}/test_utils.js (100%)
create mode 100644 frappe/public/js/frappe/utils/tools.js
create mode 100644 frappe/public/js/frappe/utils/urllib.js
rename frappe/public/js/frappe/{misc => utils}/user.js (100%)
rename frappe/public/js/frappe/{misc => utils}/utils.js (100%)
delete mode 100644 frappe/public/js/legacy/dom.js
delete mode 100644 frappe/public/js/legacy/globals.js
delete mode 100644 frappe/public/js/legacy/handler.js
delete mode 100644 frappe/public/js/legacy/layout.js
delete mode 100644 frappe/public/js/legacy/print_format.js
delete mode 100644 frappe/public/js/legacy/print_table.js
diff --git a/frappe/custom/doctype/customize_form/customize_form.js b/frappe/custom/doctype/customize_form/customize_form.js
index c503c903eb..f1eadaaf2e 100644
--- a/frappe/custom/doctype/customize_form/customize_form.js
+++ b/frappe/custom/doctype/customize_form/customize_form.js
@@ -5,8 +5,6 @@ frappe.provide("frappe.customize_form");
frappe.ui.form.on("Customize Form", {
onload: function(frm) {
- frappe.customize_form.add_fields_help(frm);
-
frm.set_query("doc_type", function() {
return {
translate_values: false,
@@ -206,103 +204,3 @@ frappe.customize_form.clear_locals_and_refresh = function(frm) {
frm.refresh();
}
-frappe.customize_form.add_fields_help = function(frm) {
- $(frm.grids[0].parent).before(
- '');
- $('#fields_help').click(function() {
- var d = new frappe.ui.Dialog({
- title: __('Help: Field Properties'),
- width: 600
- });
-
- var help =
- "\
- \
- " + __("Label") + " \
- " + __("Set the display label for the field") + " \
- \
- \
- " + __("Type") + " \
- " + __("Change type of field. (Currently, Type change is \
- allowed among 'Currency and Float')") + " \
- \
- \
- " + __("Options") + " \
- " + __("Specify the value of the field") + " \
- \
- \
- " + __("Perm Level") + " \
- \
- " + __("Assign a permission level to the field.") + " \
- (" + __("Permissions can be managed via Setup > Role Permissions Manager") + "\
- \
- \
- \
- " + __("Width") + " \
- \
- " + __("Width of the input box") + " \
- " + __("Example") + ": 120px \
- \
- \
- \
- " + __("Reqd") + " \
- " + __("Mark the field as Mandatory") + " \
- \
- \
- " + __("In Filter") + " \
- " + __("Use the field to filter records") + " \
- \
- \
- " + __("Hidden") + " \
- " + __("Hide field in form") + " \
- \
- \
- " + __("Print Hide") + " \
- " + __("Hide field in Standard Print Format") + " \
- \
- \
- " + __("Report Hide") + " \
- " + __("Hide field in Report Builder") + " \
- \
- \
- " + __("Allow on Submit") + " \
- " + __("Allow field to remain editable even after submission") + " \
- \
- \
- " + __("Depends On") + " \
- \
- Show field if a condition is met \
- Example: eval:doc.status=='Cancelled'\
- on a field like \"reason_for_cancellation\" will reveal \
- \"Reason for Cancellation\" only if the record is Cancelled.\
- \
- \
- \
- " + __("Description") + " \
- " + __("Show a description below the field") + " \
- \
- \
- " + __("Default") + " \
- " + __("Specify a default value") + " \
- \
- \
- \
- " + __("Press Esc to close") + " \
- \
- \
-
"
-
- $y(d.body, {padding: '32px', textAlign: 'center', lineHeight: '200%'});
-
- $a(d.body, 'div', '', {textAlign: 'left'}, help);
-
- d.show();
-
- frappe.customize_form.fields_help_dialog = d;
-
- });
-}
diff --git a/frappe/model/document.py b/frappe/model/document.py
index 04c802df6e..ace752a2f8 100644
--- a/frappe/model/document.py
+++ b/frappe/model/document.py
@@ -1241,7 +1241,7 @@ class Document(BaseDocument):
file_lock.delete_lock(self.get_signature())
# validation helpers
- def validate_from_to_dates(from_date_field, to_date_field):
+ def validate_from_to_dates(self, from_date_field, to_date_field):
'''
Generic validation to verify date sequence
'''
diff --git a/frappe/public/build.json b/frappe/public/build.json
index d2c2cd5f42..c100aac718 100755
--- a/frappe/public/build.json
+++ b/frappe/public/build.json
@@ -30,12 +30,12 @@
"public/js/lib/md5.min.js",
"public/js/frappe/provide.js",
"public/js/frappe/format.js",
- "public/js/frappe/misc/number_format.js",
- "public/js/frappe/misc/utils.js",
- "public/js/frappe/misc/common.js",
+ "public/js/frappe/utils/number_format.js",
+ "public/js/frappe/utils/utils.js",
+ "public/js/frappe/utils/common.js",
"public/js/frappe/ui/messages.js",
"public/js/frappe/translate.js",
- "public/js/frappe/misc/pretty_date.js",
+ "public/js/frappe/utils/pretty_date.js",
"public/js/lib/microtemplate.js",
"public/js/frappe/query_string.js",
@@ -48,7 +48,7 @@
"public/js/frappe/model/perm.js",
"website/js/website.js",
- "public/js/frappe/misc/rating_icons.html",
+ "public/js/frappe/utils/rating_icons.html",
"public/js/frappe/socketio_client.js"
],
"js/bootstrap-4-web.min.js": [
@@ -56,45 +56,7 @@
],
"js/control.min.js": [
"public/js/frappe/ui/capture.js",
- "public/js/frappe/form/controls/base_control.js",
- "public/js/frappe/form/controls/base_input.js",
- "public/js/frappe/form/controls/data.js",
- "public/js/frappe/form/controls/int.js",
- "public/js/frappe/form/controls/float.js",
- "public/js/frappe/form/controls/currency.js",
- "public/js/frappe/form/controls/date.js",
- "public/js/frappe/form/controls/time.js",
- "public/js/frappe/form/controls/datetime.js",
- "public/js/frappe/form/controls/date_range.js",
- "public/js/frappe/form/controls/select.js",
- "public/js/frappe/form/controls/link.js",
- "public/js/frappe/form/controls/dynamic_link.js",
- "public/js/frappe/form/controls/text.js",
- "public/js/frappe/form/controls/code.js",
- "public/js/frappe/form/controls/text_editor.js",
- "public/js/frappe/form/controls/comment.js",
- "public/js/frappe/form/controls/check.js",
- "public/js/frappe/form/controls/image.js",
- "public/js/frappe/form/controls/attach.js",
- "public/js/frappe/form/controls/attach_image.js",
- "public/js/frappe/form/controls/table.js",
- "public/js/frappe/form/controls/color.js",
- "public/js/frappe/form/controls/signature.js",
- "public/js/frappe/form/controls/password.js",
- "public/js/frappe/form/controls/read_only.js",
- "public/js/frappe/form/controls/button.js",
- "public/js/frappe/form/controls/html.js",
- "public/js/frappe/form/controls/markdown_editor.js",
- "public/js/frappe/form/controls/html_editor.js",
- "public/js/frappe/form/controls/heading.js",
- "public/js/frappe/form/controls/autocomplete.js",
- "public/js/frappe/form/controls/barcode.js",
- "public/js/frappe/form/controls/geolocation.js",
- "public/js/frappe/form/controls/multiselect.js",
- "public/js/frappe/form/controls/multicheck.js",
- "public/js/frappe/form/controls/table_multiselect.js",
- "public/js/frappe/form/controls/multiselect_pills.js",
- "public/js/frappe/form/controls/rating.js"
+ "public/js/frappe/form/controls/control.js"
],
"js/dialog.min.js": [
"public/js/frappe/dom.js",
@@ -177,7 +139,7 @@
"public/js/frappe/request.js",
"public/js/frappe/socketio_client.js",
- "public/js/frappe/misc/utils.js",
+ "public/js/frappe/utils/utils.js",
"public/js/frappe/event_emitter.js",
"public/js/frappe/router.js",
"public/js/frappe/router_history.js",
@@ -185,9 +147,6 @@
"public/js/frappe/roles_editor.js",
"public/js/lib/microtemplate.js",
- "public/js/legacy/globals.js",
- "public/js/legacy/datatype.js",
- "public/js/legacy/dom.js",
"public/js/legacy/handler.js",
"public/js/frappe/ui/page.html",
@@ -214,18 +173,20 @@
"public/js/frappe/model/user_settings.js",
"public/js/lib/md5.min.js",
- "public/js/frappe/misc/user.js",
- "public/js/frappe/misc/common.js",
- "public/js/frappe/misc/pretty_date.js",
- "public/js/frappe/misc/test_utils.js",
- "public/js/frappe/misc/tools.js",
- "public/js/frappe/misc/datetime.js",
- "public/js/frappe/misc/number_format.js",
- "public/js/frappe/misc/help.js",
- "public/js/frappe/misc/help_links.js",
- "public/js/frappe/misc/address_and_contact.js",
- "public/js/frappe/misc/preview_email.js",
- "public/js/frappe/misc/file_manager.js",
+ "public/js/frappe/utils/user.js",
+ "public/js/frappe/utils/common.js",
+ "public/js/frappe/utils/urllib.js",
+ "public/js/frappe/utils/pretty_date.js",
+ "public/js/frappe/utils/test_utils.js",
+ "public/js/frappe/utils/tools.js",
+ "public/js/frappe/utils/jquery_plugins.js",
+ "public/js/frappe/utils/datetime.js",
+ "public/js/frappe/utils/number_format.js",
+ "public/js/frappe/utils/help.js",
+ "public/js/frappe/utils/help_links.js",
+ "public/js/frappe/utils/address_and_contact.js",
+ "public/js/frappe/utils/preview_email.js",
+ "public/js/frappe/utils/file_manager.js",
"public/js/frappe/ui/upload.html",
"public/js/frappe/upload.js",
@@ -257,11 +218,11 @@
"public/js/frappe/query_string.js",
"public/js/frappe/ui/comment.js",
- "public/js/frappe/misc/rating_icons.html",
+ "public/js/frappe/utils/rating_icons.html",
"public/js/frappe/chat.js",
"public/js/frappe/social/social_factory.js",
- "public/js/frappe/misc/energy_point_utils.js"
+ "public/js/frappe/utils/energy_point_utils.js"
],
"css/module.min.css": [
"public/less/module.less"
@@ -270,7 +231,6 @@
"public/less/form_grid.less"
],
"js/form.min.js": [
- "public/js/frappe/form/document_follow.js",
"public/js/frappe/form/templates/print_layout.html",
"public/js/frappe/form/templates/users_in_sidebar.html",
"public/js/frappe/form/templates/set_sharing.html",
@@ -278,31 +238,13 @@
"public/js/frappe/form/templates/form_dashboard.html",
"public/js/frappe/form/templates/form_document_flow.html",
"public/js/frappe/form/templates/form_links.html",
+ "public/js/frappe/form/templates/attachment.html",
+ "public/js/frappe/form/templates/form_footer.html",
+ "public/js/frappe/form/templates/timeline.html",
+ "public/js/frappe/form/templates/timeline_item.html",
+ "public/js/frappe/form/controls/control.js",
"public/js/frappe/views/formview.js",
- "public/js/legacy/form.js",
- "public/js/legacy/client_script_helpers.js",
- "public/js/frappe/form/toolbar.js",
- "public/js/frappe/form/dashboard.js",
- "public/js/frappe/form/save.js",
- "public/js/frappe/form/script_manager.js",
- "public/js/frappe/form/linked_with.js",
- "public/js/frappe/form/workflow.js",
- "public/js/frappe/form/print.js",
- "public/js/frappe/form/form_sidebar.js",
- "public/js/frappe/form/user_image.js",
- "public/js/frappe/form/share.js",
- "public/js/frappe/form/review.js",
- "public/js/frappe/form/form_viewers.js",
- "public/js/frappe/form/footer/attachment.html",
- "public/js/frappe/form/footer/form_footer.html",
- "public/js/frappe/form/footer/timeline.html",
- "public/js/frappe/form/footer/timeline_item.html",
- "public/js/frappe/form/footer/footer.js",
- "public/js/frappe/form/footer/attachments.js",
- "public/js/frappe/form/footer/timeline.js",
- "public/js/frappe/form/footer/assign_to.js",
- "public/js/frappe/form/quick_entry.js",
- "public/js/frappe/form/success_action.js",
+ "public/js/frappe/form/form.js",
"public/js/frappe/meta_tag.js"
],
"css/list.min.css": [
@@ -369,7 +311,7 @@
"public/js/frappe/ui/group_by/group_by.js"
],
"js/web_form.min.js": [
- "public/js/frappe/misc/datetime.js",
+ "public/js/frappe/utils/datetime.js",
"website/js/web_form.js",
"public/js/lib/datepicker/datepicker.min.js",
"public/js/lib/datepicker/datepicker.en.js"
@@ -383,11 +325,6 @@
"public/less/form_grid.less",
"public/less/controls.less"
],
- "js/print_format_v3.min.js": [
- "public/js/legacy/layout.js",
- "public/js/legacy/print_table.js",
- "public/js/legacy/print_format.js"
- ],
"frappe/css/email.css": [
"public/less/email.less"
],
diff --git a/frappe/public/js/frappe/chat.js b/frappe/public/js/frappe/chat.js
index 533ca90856..9b67a7d834 100644
--- a/frappe/public/js/frappe/chat.js
+++ b/frappe/public/js/frappe/chat.js
@@ -9,7 +9,7 @@ import './socketio_client'
import './ui/dialog'
import './ui/capture'
-import './misc/user'
+import './utils/user'
/* eslint semi: "never" */
// Fuck semicolons - https://mislav.net/2010/05/semicolons
diff --git a/frappe/public/js/frappe/dom.js b/frappe/public/js/frappe/dom.js
index 830ed0a5ce..da03bd29f8 100644
--- a/frappe/public/js/frappe/dom.js
+++ b/frappe/public/js/frappe/dom.js
@@ -339,90 +339,3 @@ $(window).on('offline', function() {
message: __('Connection lost. Some features might not work.')
});
});
-
-
-// add list to
-(function($) {
- $.fn.add_options = function(options_list) {
- // create options
- for(var i=0, j=options_list.length; i').html(cstr(label))
- .attr('value', value)
- .prop('disabled', is_disabled)
- .appendTo(this);
- }
- // select the first option
- this.selectedIndex = 0;
- return $(this);
- }
- $.fn.set_working = function() {
- this.prop('disabled', true);
- }
- $.fn.done_working = function() {
- this.prop('disabled', false);
- }
-})(jQuery);
-
-(function($) {
- function pasteIntoInput(el, text) {
- el.focus();
- if (typeof el.selectionStart == "number") {
- var val = el.value;
- var selStart = el.selectionStart;
- el.value = val.slice(0, selStart) + text + val.slice(el.selectionEnd);
- el.selectionEnd = el.selectionStart = selStart + text.length;
- } else if (typeof document.selection != "undefined") {
- var textRange = document.selection.createRange();
- textRange.text = text;
- textRange.collapse(false);
- textRange.select();
- }
- }
-
- function allowTabChar(el) {
- $(el).keydown(function(e) {
- if (e.which == 9) {
- pasteIntoInput(this, "\t");
- return false;
- }
- });
-
- // For Opera, which only allows suppression of keypress events, not keydown
- $(el).keypress(function(e) {
- if (e.which == 9) {
- return false;
- }
- });
- }
-
- $.fn.allowTabs = function() {
- if (this.jquery) {
- this.each(function() {
- if (this.nodeType == 1) {
- var nodeName = this.nodeName.toLowerCase();
- if (nodeName == "textarea" || (nodeName == "input" && this.type == "text")) {
- allowTabChar(this);
- }
- }
- })
- }
- return this;
- }
-})(jQuery);
\ No newline at end of file
diff --git a/frappe/public/js/frappe/form/controls/base_control.js b/frappe/public/js/frappe/form/controls/base_control.js
index 26b6b9767b..cb4fed5de5 100644
--- a/frappe/public/js/frappe/form/controls/base_control.js
+++ b/frappe/public/js/frappe/form/controls/base_control.js
@@ -1,13 +1,3 @@
-frappe.ui.form.make_control = function (opts) {
- var control_class_name = "Control" + opts.df.fieldtype.replace(/ /g, "");
- if(frappe.ui.form[control_class_name]) {
- return new frappe.ui.form[control_class_name](opts);
- } else {
- // eslint-disable-next-line
- console.log("Invalid Control Name: " + opts.df.fieldtype);
- }
-};
-
frappe.ui.form.Control = Class.extend({
init: function(opts) {
$.extend(this, opts);
diff --git a/frappe/public/js/frappe/form/controls/control.js b/frappe/public/js/frappe/form/controls/control.js
new file mode 100644
index 0000000000..87b63c1674
--- /dev/null
+++ b/frappe/public/js/frappe/form/controls/control.js
@@ -0,0 +1,50 @@
+import './base_control';
+import './base_input';
+import './data';
+import './int';
+import './float';
+import './currency';
+import './date';
+import './time';
+import './datetime';
+import './date_range';
+import './select';
+import './link';
+import './dynamic_link';
+import './text';
+import './code';
+import './text_editor';
+import './comment';
+import './check';
+import './image';
+import './attach';
+import './attach_image';
+import './table';
+import './color';
+import './signature';
+import './password';
+import './read_only';
+import './button';
+import './html';
+import './markdown_editor';
+import './html_editor';
+import './heading';
+import './autocomplete';
+import './barcode';
+import './geolocation';
+import './multiselect';
+import './multicheck';
+import './table_multiselect';
+import './multiselect_pills';
+import './rating';
+
+frappe.ui.form.make_control = function (opts) {
+ var control_class_name = "Control" + opts.df.fieldtype.replace(/ /g, "");
+ if(frappe.ui.form[control_class_name]) {
+ return new frappe.ui.form[control_class_name](opts);
+ } else {
+ // eslint-disable-next-line
+ console.log("Invalid Control Name: " + opts.df.fieldtype);
+ }
+};
+
diff --git a/frappe/public/js/frappe/form/footer/footer.js b/frappe/public/js/frappe/form/footer/footer.js
index cedd64fb72..63757be08b 100644
--- a/frappe/public/js/frappe/form/footer/footer.js
+++ b/frappe/public/js/frappe/form/footer/footer.js
@@ -1,6 +1,8 @@
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
// MIT License. See license.txt
+import './timeline.js';
+
frappe.ui.form.Footer = Class.extend({
init: function(opts) {
var me = this;
diff --git a/frappe/public/js/frappe/form/form.js b/frappe/public/js/frappe/form/form.js
index 2b33909ee0..5935232548 100644
--- a/frappe/public/js/frappe/form/form.js
+++ b/frappe/public/js/frappe/form/form.js
@@ -1,5 +1,17 @@
frappe.provide('frappe.ui.form');
+import './quick_entry';
+import './toolbar';
+import './dashboard';
+import './workflow';
+import './save';
+import './print';
+import './success_action';
+import './script_manager';
+import './script_helpers';
+import './sidebar/form_sidebar';
+import './footer/footer';
+
frappe.ui.form.Controller = Class.extend({
init: function(opts) {
$.extend(this, opts);
@@ -283,7 +295,9 @@ frappe.ui.form.Form = class FrappeForm {
// record switch
if(this.docname != docname && (!this.meta.in_dialog || this.in_form) && !this.meta.istable) {
frappe.utils.scroll_to(0);
- this.print_preview.hide();
+ if (this.print_preview) {
+ this.print_preview.hide();
+ }
}
// reset visible columns, since column headings can change in different docs
this.grids.forEach(grid_obj => grid_obj.grid.visible_columns = null);
@@ -425,8 +439,8 @@ frappe.ui.form.Form = class FrappeForm {
}
}
- if(this.meta.autoname && this.meta.autonathis.substr(0,6)=='field:' && !this.doc.__islocal) {
- var fn = this.meta.autonathis.substr(6);
+ if(this.meta.autoname && this.meta.autoname.substr(0,6)=='field:' && !this.doc.__islocal) {
+ var fn = this.meta.autoname.substr(6);
if (this.doc[fn]) {
this.toggle_display(fn, false);
@@ -643,7 +657,7 @@ frappe.ui.form.Form = class FrappeForm {
// HELPERS
- enable_save = function() {
+ enable_save() {
this.save_disabled = false;
this.toolbar.set_primary_action();
}
@@ -1189,7 +1203,7 @@ frappe.ui.form.Form = class FrappeForm {
return frappe.ui.form.get_open_grid_form();
}
- get_title = function() {
+ get_title() {
if(this.meta.title_field) {
return this.doc[this.meta.title_field];
} else {
@@ -1215,7 +1229,7 @@ frappe.ui.form.Form = class FrappeForm {
return selected;
}
- set_indicator_formatter = function(fieldname, get_color, get_text) {
+ set_indicator_formatter(fieldname, get_color, get_text) {
// get doctype from parent
var doctype;
if(frappe.meta.docfield_map[this.doctype][fieldname]) {
diff --git a/frappe/public/js/frappe/form/layout.js b/frappe/public/js/frappe/form/layout.js
index bada3d354a..ffb0de9f00 100644
--- a/frappe/public/js/frappe/form/layout.js
+++ b/frappe/public/js/frappe/form/layout.js
@@ -1,6 +1,5 @@
import '../class';
-frappe.provide("frappe.ui.form");
frappe.ui.form.Layout = Class.extend({
init: function(opts) {
this.views = {};
diff --git a/frappe/public/js/frappe/form/linked_with.js b/frappe/public/js/frappe/form/linked_with.js
index 7188e4131c..e52e3f9b28 100644
--- a/frappe/public/js/frappe/form/linked_with.js
+++ b/frappe/public/js/frappe/form/linked_with.js
@@ -1,7 +1,6 @@
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
// MIT License. See license.txt
-frappe.provide("frappe.ui.form");
frappe.ui.form.LinkedWith = class LinkedWith {
diff --git a/frappe/public/js/frappe/form/print.js b/frappe/public/js/frappe/form/print.js
index ccdae949b7..c10348a02a 100644
--- a/frappe/public/js/frappe/form/print.js
+++ b/frappe/public/js/frappe/form/print.js
@@ -1,4 +1,4 @@
-frappe.provide("frappe.ui.form");
+
frappe.ui.form.PrintPreview = Class.extend({
init: function (opts) {
@@ -55,34 +55,24 @@ frappe.ui.form.PrintPreview = Class.extend({
});
this.wrapper.find(".btn-print-print").click(function () {
- if (me.is_old_style()) {
- me.print_old_style();
- } else {
- me.printit();
- }
+ me.printit();
});
this.wrapper.find(".btn-print-preview").click(function () {
- if (me.is_old_style()) {
- me.new_page_preview_old_style();
- } else {
- me.new_page_preview();
- }
+ me.new_page_preview();
});
this.wrapper.find(".btn-download-pdf").click(function () {
- if (!me.is_old_style()) {
- var w = window.open(
- frappe.urllib.get_full_url("/api/method/frappe.utils.print_format.download_pdf?"
- + "doctype=" + encodeURIComponent(me.frm.doc.doctype)
- + "&name=" + encodeURIComponent(me.frm.doc.name)
- + "&format=" + me.selected_format()
- + "&no_letterhead=" + (me.with_letterhead() ? "0" : "1")
- + (me.lang_code ? ("&_lang=" + me.lang_code) : ""))
- );
- if (!w) {
- frappe.msgprint(__("Please enable pop-ups")); return;
- }
+ var w = window.open(
+ frappe.urllib.get_full_url("/api/method/frappe.utils.print_format.download_pdf?"
+ + "doctype=" + encodeURIComponent(me.frm.doc.doctype)
+ + "&name=" + encodeURIComponent(me.frm.doc.name)
+ + "&format=" + me.selected_format()
+ + "&no_letterhead=" + (me.with_letterhead() ? "0" : "1")
+ + (me.lang_code ? ("&_lang=" + me.lang_code) : ""))
+ );
+ if (!w) {
+ frappe.msgprint(__("Please enable pop-ups")); return;
}
});
@@ -149,12 +139,7 @@ frappe.ui.form.PrintPreview = Class.extend({
},
multilingual_preview: function () {
var me = this;
- if (this.is_old_style()) {
- me.wrapper.find(".btn-print-preview").toggle(true);
- me.wrapper.find(".btn-download-pdf").toggle(false);
- me.set_style();
- me.preview_old_style();
- } else if (this.is_raw_printing()) {
+ if (this.is_raw_printing()) {
me.wrapper.find(".btn-print-preview").toggle(false);
me.wrapper.find(".btn-download-pdf").toggle(false);
me.preview();
@@ -345,51 +330,15 @@ frappe.ui.form.PrintPreview = Class.extend({
return {};
}
},
- preview_old_style: function () {
- var me = this;
- this.with_old_style({
- format: me.print_sel.val(),
- callback: function (html) {
- me.wrapper.find(".print-format").html(''
- + __("Warning: This Print Format is in old style and cannot be generated via the API.")
- + '
'
- + html);
- },
- no_letterhead: !this.with_letterhead(),
- only_body: true,
- no_heading: true
- });
- },
refresh_print_options: function () {
this.print_formats = frappe.meta.get_print_formats(this.frm.doctype);
return this.print_sel
.empty().add_options(this.print_formats);
},
- with_old_style: function (opts) {
- frappe.require("/assets/js/print_format_v3.min.js", function () {
- _p.build(opts.format, opts.callback, opts.no_letterhead, opts.only_body, opts.no_heading);
- });
- },
- print_old_style: function () {
- var me = this;
- frappe.require("/assets/js/print_format_v3.min.js", function () {
- _p.build(me.print_sel.val(), _p.go,
- !me.with_letterhead());
- });
- },
- new_page_preview_old_style: function () {
- var me = this;
- frappe.require("/assets/js/print_format_v3.min.js", function () {
- _p.build(me.print_sel.val(), _p.preview, !me.with_letterhead());
- });
- },
selected_format: function () {
return this.print_sel.val() || this.frm.meta.default_print_format || "Standard";
},
- is_old_style: function (format) {
- return this.get_print_format(format).print_format_type === "Client";
- },
is_raw_printing: function (format) {
return this.get_print_format(format).raw_printing === 1;
},
diff --git a/frappe/public/js/frappe/form/save.js b/frappe/public/js/frappe/form/save.js
index c81171aafa..ca5bc93133 100644
--- a/frappe/public/js/frappe/form/save.js
+++ b/frappe/public/js/frappe/form/save.js
@@ -1,7 +1,7 @@
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
// MIT License. See license.txt
-frappe.provide("frappe.ui.form");
+
frappe.ui.form.save = function (frm, action, callback, btn) {
$(btn).prop("disabled", true);
diff --git a/frappe/public/js/legacy/client_script_helpers.js b/frappe/public/js/frappe/form/script_helpers.js
similarity index 100%
rename from frappe/public/js/legacy/client_script_helpers.js
rename to frappe/public/js/frappe/form/script_helpers.js
diff --git a/frappe/public/js/frappe/form/footer/assign_to.js b/frappe/public/js/frappe/form/sidebar/assign_to.js
similarity index 99%
rename from frappe/public/js/frappe/form/footer/assign_to.js
rename to frappe/public/js/frappe/form/sidebar/assign_to.js
index c8521f835a..1d4adf1edb 100644
--- a/frappe/public/js/frappe/form/footer/assign_to.js
+++ b/frappe/public/js/frappe/form/sidebar/assign_to.js
@@ -1,7 +1,7 @@
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
// MIT License. See license.txt
-frappe.provide("frappe.ui.form");
+
frappe.ui.form.AssignTo = Class.extend({
init: function(opts) {
diff --git a/frappe/public/js/frappe/form/footer/attachments.js b/frappe/public/js/frappe/form/sidebar/attachments.js
similarity index 99%
rename from frappe/public/js/frappe/form/footer/attachments.js
rename to frappe/public/js/frappe/form/sidebar/attachments.js
index 9d5b80d0a2..165527e281 100644
--- a/frappe/public/js/frappe/form/footer/attachments.js
+++ b/frappe/public/js/frappe/form/sidebar/attachments.js
@@ -1,7 +1,7 @@
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
// MIT License. See license.txt
-frappe.provide("frappe.ui.form");
+
frappe.ui.form.Attachments = Class.extend({
init: function(opts) {
diff --git a/frappe/public/js/frappe/form/document_follow.js b/frappe/public/js/frappe/form/sidebar/document_follow.js
similarity index 100%
rename from frappe/public/js/frappe/form/document_follow.js
rename to frappe/public/js/frappe/form/sidebar/document_follow.js
diff --git a/frappe/public/js/frappe/form/form_sidebar.js b/frappe/public/js/frappe/form/sidebar/form_sidebar.js
similarity index 97%
rename from frappe/public/js/frappe/form/form_sidebar.js
rename to frappe/public/js/frappe/form/sidebar/form_sidebar.js
index 6f0fa942cc..927faf4fcc 100644
--- a/frappe/public/js/frappe/form/form_sidebar.js
+++ b/frappe/public/js/frappe/form/sidebar/form_sidebar.js
@@ -1,4 +1,13 @@
-frappe.provide("frappe.ui.form");
+
+
+import './assign_to';
+import './attachments';
+import './share';
+import './review';
+import './document_follow';
+import './user_image';
+import './form_viewers';
+
frappe.ui.form.Sidebar = Class.extend({
init: function(opts) {
$.extend(this, opts);
diff --git a/frappe/public/js/frappe/form/form_viewers.js b/frappe/public/js/frappe/form/sidebar/form_viewers.js
similarity index 98%
rename from frappe/public/js/frappe/form/form_viewers.js
rename to frappe/public/js/frappe/form/sidebar/form_viewers.js
index 28965c01c1..72f4984e94 100644
--- a/frappe/public/js/frappe/form/form_viewers.js
+++ b/frappe/public/js/frappe/form/sidebar/form_viewers.js
@@ -1,4 +1,4 @@
-frappe.provide("frappe.ui.form");
+
frappe.ui.form.Viewers = Class.extend({
init: function(opts) {
diff --git a/frappe/public/js/frappe/form/review.js b/frappe/public/js/frappe/form/sidebar/review.js
similarity index 99%
rename from frappe/public/js/frappe/form/review.js
rename to frappe/public/js/frappe/form/sidebar/review.js
index 90a458d442..617edd19a7 100644
--- a/frappe/public/js/frappe/form/review.js
+++ b/frappe/public/js/frappe/form/sidebar/review.js
@@ -1,7 +1,7 @@
// Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and Contributors
// MIT License. See license.txt
-frappe.provide("frappe.ui.form");
+
frappe.ui.form.Review = class Review {
constructor({parent, frm}) {
diff --git a/frappe/public/js/frappe/form/share.js b/frappe/public/js/frappe/form/sidebar/share.js
similarity index 99%
rename from frappe/public/js/frappe/form/share.js
rename to frappe/public/js/frappe/form/sidebar/share.js
index aeaab1d4a2..0a7cc2b831 100644
--- a/frappe/public/js/frappe/form/share.js
+++ b/frappe/public/js/frappe/form/sidebar/share.js
@@ -1,7 +1,7 @@
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
// MIT License. See license.txt
-frappe.provide("frappe.ui.form");
+
frappe.ui.form.Share = Class.extend({
init: function(opts) {
diff --git a/frappe/public/js/frappe/form/user_image.js b/frappe/public/js/frappe/form/sidebar/user_image.js
similarity index 100%
rename from frappe/public/js/frappe/form/user_image.js
rename to frappe/public/js/frappe/form/sidebar/user_image.js
diff --git a/frappe/public/js/frappe/form/footer/attachment.html b/frappe/public/js/frappe/form/templates/attachment.html
similarity index 100%
rename from frappe/public/js/frappe/form/footer/attachment.html
rename to frappe/public/js/frappe/form/templates/attachment.html
diff --git a/frappe/public/js/frappe/form/templates/form_document_flow.html b/frappe/public/js/frappe/form/templates/form_document_flow.html
deleted file mode 100644
index 42e2b91efd..0000000000
--- a/frappe/public/js/frappe/form/templates/form_document_flow.html
+++ /dev/null
@@ -1,12 +0,0 @@
-
diff --git a/frappe/public/js/frappe/form/footer/form_footer.html b/frappe/public/js/frappe/form/templates/form_footer.html
similarity index 100%
rename from frappe/public/js/frappe/form/footer/form_footer.html
rename to frappe/public/js/frappe/form/templates/form_footer.html
diff --git a/frappe/public/js/frappe/form/footer/timeline.html b/frappe/public/js/frappe/form/templates/timeline.html
similarity index 100%
rename from frappe/public/js/frappe/form/footer/timeline.html
rename to frappe/public/js/frappe/form/templates/timeline.html
diff --git a/frappe/public/js/frappe/form/footer/timeline_item.html b/frappe/public/js/frappe/form/templates/timeline_item.html
similarity index 100%
rename from frappe/public/js/frappe/form/footer/timeline_item.html
rename to frappe/public/js/frappe/form/templates/timeline_item.html
diff --git a/frappe/public/js/frappe/form/toolbar.js b/frappe/public/js/frappe/form/toolbar.js
index 5697ebbe62..a4fb781325 100644
--- a/frappe/public/js/frappe/form/toolbar.js
+++ b/frappe/public/js/frappe/form/toolbar.js
@@ -1,7 +1,7 @@
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
// MIT License. See license.txt
+import './linked_with';
-frappe.provide("frappe.ui.form");
frappe.ui.form.Toolbar = Class.extend({
init: function(opts) {
$.extend(this, opts);
diff --git a/frappe/public/js/frappe/misc/tools.js b/frappe/public/js/frappe/misc/tools.js
deleted file mode 100644
index 27436facd2..0000000000
--- a/frappe/public/js/frappe/misc/tools.js
+++ /dev/null
@@ -1,152 +0,0 @@
-// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
-// MIT License. See license.txt
-
-import showdown from 'showdown';
-
-frappe.provide("frappe.tools");
-
-frappe.tools.downloadify = function(data, roles, title) {
- if(roles && roles.length && !has_common(roles, roles)) {
- frappe.msgprint(__("Export not allowed. You need {0} role to export.", [frappe.utils.comma_or(roles)]));
- return;
- }
-
- var filename = title + ".csv";
- var csv_data = frappe.tools.to_csv(data);
- var a = document.createElement('a');
-
- if ("download" in a) {
- // Used Blob object, because it can handle large files
- var blob_object = new Blob([csv_data], { type: 'text/csv;charset=UTF-8' });
- a.href = URL.createObjectURL(blob_object);
- a.download = filename;
-
- } else {
- // use old method
- a.href = 'data:attachment/csv,' + encodeURIComponent(csv_data);
- a.download = filename;
- a.target = "_blank";
- }
-
- document.body.appendChild(a);
- a.click();
-
- document.body.removeChild(a);
-};
-
-frappe.markdown = function(txt) {
- if(!frappe.md2html) {
- frappe.md2html = new showdown.Converter();
- }
-
- while(txt.substr(0,1)==="\n") {
- txt = txt.substr(1);
- }
-
- // remove leading tab (if they exist in the first line)
- var whitespace_len = 0,
- first_line = txt.split("\n")[0];
-
- while(["\n", "\t"].indexOf(first_line.substr(0,1))!== -1) {
- whitespace_len++;
- first_line = first_line.substr(1);
- }
-
- if(whitespace_len && whitespace_len != first_line.length) {
- var txt1 = [];
- $.each(txt.split("\n"), function(i, t) {
- txt1.push(t.substr(whitespace_len));
- })
- txt = txt1.join("\n");
- }
-
- return frappe.md2html.makeHtml(txt);
-}
-
-
-frappe.tools.to_csv = function(data) {
- var res = [];
- $.each(data, function(i, row) {
- row = $.map(row, function(col) {
- if (col === null || col === undefined) col = '';
- return typeof col === "string" ? ('"' + $('').html(col.replace(/"/g, '""')).text() + '"') : col;
- });
- res.push(row.join(","));
- });
- return res.join("\n");
-};
-
-frappe.slickgrid_tools = {
- get_filtered_items: function(dataView) {
- var data = [];
- for (var i=0, len=dataView.getLength(); i 0 && (isNaN((new Date(val)).valueOf()))) {
- val = " ".repeat(d['indent'] * 8) + val;
- }
- // remove single quotes at start and end of total labels when export to csv
- if(val.charAt(0) == "'" && val.charAt(val.length -1) == "'") {
- val = val.substr(1, val.length-2);
- }
- }
- row.push(val);
- });
-
- if(!filter || filter(row, d)) {
- res.push(row);
- }
- }
- return [col_row].concat(res);
- },
- add_property_setter_on_resize: function(grid) {
- grid.onColumnsResized.subscribe(function(e, args) {
- $.each(grid.getColumns(), function(i, col) {
- if(col.docfield && col.previousWidth != col.width &&
- !in_list(frappe.model.std_fields_list, col.docfield.fieldname) ) {
- frappe.call({
- method:"frappe.client.make_width_property_setter",
- args: {
- doc: {
- doctype:'Property Setter',
- doctype_or_field: 'DocField',
- doc_type: col.docfield.parent,
- field_name: col.docfield.fieldname,
- property: 'width',
- value: col.width,
- "__islocal": 1
- }
- }
- });
- col.previousWidth = col.width;
- col.docfield.width = col.width;
- }
- });
- });
- }
-};
diff --git a/frappe/public/js/frappe/provide.js b/frappe/public/js/frappe/provide.js
index 40610548ec..5535fba1c5 100644
--- a/frappe/public/js/frappe/provide.js
+++ b/frappe/public/js/frappe/provide.js
@@ -23,7 +23,29 @@ frappe.provide("locals");
frappe.provide("frappe.flags");
frappe.provide("frappe.settings");
frappe.provide("frappe.utils");
-frappe.provide("frappe.ui");
+frappe.provide("frappe.ui.form");
frappe.provide("frappe.modules");
frappe.provide("frappe.templates");
frappe.provide("frappe.test_data");
+frappe.provide('frappe.desk.form');
+frappe.provide('frappe.desk.report');
+frappe.provide('frappe.utils');
+frappe.provide('frappe.model');
+frappe.provide('frappe.user');
+frappe.provide('frappe.session');
+frappe.provide('locals.DocType');
+
+// for listviews
+frappe.provide("frappe.listview_settings");
+frappe.provide("frappe.listview_parent_route");
+
+// constants
+window.NEWLINE = '\n';
+window.TAB = 9;
+window.UP_ARROW = 38;
+window.DOWN_ARROW = 40;
+
+// proxy for user globals defined in desk.js
+
+// API globals
+window.cur_frm=null;
diff --git a/frappe/public/js/frappe/misc/address_and_contact.js b/frappe/public/js/frappe/utils/address_and_contact.js
similarity index 100%
rename from frappe/public/js/frappe/misc/address_and_contact.js
rename to frappe/public/js/frappe/utils/address_and_contact.js
diff --git a/frappe/public/js/frappe/misc/common.js b/frappe/public/js/frappe/utils/common.js
similarity index 100%
rename from frappe/public/js/frappe/misc/common.js
rename to frappe/public/js/frappe/utils/common.js
diff --git a/frappe/public/js/legacy/datatype.js b/frappe/public/js/frappe/utils/datatype.js
similarity index 64%
rename from frappe/public/js/legacy/datatype.js
rename to frappe/public/js/frappe/utils/datatype.js
index 9194009a84..f3a57a3d63 100644
--- a/frappe/public/js/legacy/datatype.js
+++ b/frappe/public/js/frappe/utils/datatype.js
@@ -1,18 +1,25 @@
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
// MIT License. See license.txt
-frappe.utils.full_name = function(fn, ln) {
- return fn + (ln ? ' ' : '') + (ln ? ln : '')
+window.cstr = function(s) {
+ if(s==null)return '';
+ return s+'';
}
-function fmt_money(v, format){
- // deprecated!
- // for backward compatibility
- return format_currency(v, format);
+window.cint = function(v, def) {
+ if (v === true)
+ return 1;
+ if (v === false)
+ return 0;
+ v = v + '';
+ if (v !== "0") v = lstrip(v, ['0']);
+ v = parseInt(v);
+ if (isNaN(v)) v = def === undefined ? 0 : def;
+ return v;
}
// to title case
-function toTitle(str){
+window.toTitle = function(str){
var word_in = str.split(" ");
var word_out = [];
@@ -23,25 +30,21 @@ function toTitle(str){
return word_out.join(" ");
}
-function is_null(v) {
+window.is_null = function(v) {
if(v===null || v===undefined || cstr(v).trim()==="") return true;
}
-function copy_dict(d) {
+window.copy_dict = function(d) {
var n = {};
for(var k in d) n[k] = d[k];
return n;
}
-function validate_email(txt) {
+window.validate_email = function(txt) {
return frappe.utils.validate_type(txt, "email");
}
-function cstr(s) {
- if(s==null)return '';
- return s+'';
-}
-function nth(number) {
+window.nth = function(number) {
number = cint(number);
var s = 'th';
if((number+'').substr(-1)=='1') s = 'st';
@@ -50,7 +53,7 @@ function nth(number) {
return number+s;
}
-function has_words(list, item) {
+window.has_words = function(list, item) {
if(!item) return true;
if(!list) return false;
for(var i=0, j=list.length; i list to
+(function($) {
+ $.fn.add_options = function(options_list) {
+ // create options
+ for(var i=0, j=options_list.length; i').html(cstr(label))
+ .attr('value', value)
+ .prop('disabled', is_disabled)
+ .appendTo(this);
+ }
+ // select the first option
+ this.selectedIndex = 0;
+ return $(this);
+ }
+ $.fn.set_working = function() {
+ this.prop('disabled', true);
+ }
+ $.fn.done_working = function() {
+ this.prop('disabled', false);
+ }
+})(jQuery);
+
diff --git a/frappe/public/js/frappe/misc/number_format.js b/frappe/public/js/frappe/utils/number_format.js
similarity index 96%
rename from frappe/public/js/frappe/misc/number_format.js
rename to frappe/public/js/frappe/utils/number_format.js
index 004bcf0a82..57022b22c5 100644
--- a/frappe/public/js/frappe/misc/number_format.js
+++ b/frappe/public/js/frappe/utils/number_format.js
@@ -1,6 +1,8 @@
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
// MIT License. See license.txt
+import './datatype';
+
if (!window.frappe) window.frappe = {};
function flt(v, decimals, number_format) {
@@ -28,18 +30,6 @@ function flt(v, decimals, number_format) {
return v;
}
-function cint(v, def) {
- if (v === true)
- return 1;
- if (v === false)
- return 0;
- v = v + '';
- if (v !== "0") v = lstrip(v, ['0']);
- v = parseInt(v);
- if (isNaN(v)) v = def === undefined ? 0 : def;
- return v;
-}
-
function strip_number_groups(v, number_format) {
if (!number_format) number_format = get_number_format();
var info = get_number_format_info(number_format);
@@ -231,11 +221,19 @@ function round_based_on_smallest_currency_fraction(value, currency, precision) {
return value;
}
+function fmt_money(v, format){
+ // deprecated!
+ // for backward compatibility
+ return format_currency(v, format);
+}
+
+
Object.assign(window, {
flt,
cint,
strip_number_groups,
format_currency,
+ fmt_money,
get_currency_symbol,
get_number_format,
get_number_format_info,
diff --git a/frappe/public/js/frappe/misc/pretty_date.js b/frappe/public/js/frappe/utils/pretty_date.js
similarity index 100%
rename from frappe/public/js/frappe/misc/pretty_date.js
rename to frappe/public/js/frappe/utils/pretty_date.js
diff --git a/frappe/public/js/frappe/misc/preview_email.js b/frappe/public/js/frappe/utils/preview_email.js
similarity index 100%
rename from frappe/public/js/frappe/misc/preview_email.js
rename to frappe/public/js/frappe/utils/preview_email.js
diff --git a/frappe/public/js/frappe/misc/rating_icons.html b/frappe/public/js/frappe/utils/rating_icons.html
similarity index 100%
rename from frappe/public/js/frappe/misc/rating_icons.html
rename to frappe/public/js/frappe/utils/rating_icons.html
diff --git a/frappe/public/js/frappe/misc/ratings.html b/frappe/public/js/frappe/utils/ratings.html
similarity index 100%
rename from frappe/public/js/frappe/misc/ratings.html
rename to frappe/public/js/frappe/utils/ratings.html
diff --git a/frappe/public/js/frappe/misc/test_utils.js b/frappe/public/js/frappe/utils/test_utils.js
similarity index 100%
rename from frappe/public/js/frappe/misc/test_utils.js
rename to frappe/public/js/frappe/utils/test_utils.js
diff --git a/frappe/public/js/frappe/utils/tools.js b/frappe/public/js/frappe/utils/tools.js
new file mode 100644
index 0000000000..cac4e5ab4f
--- /dev/null
+++ b/frappe/public/js/frappe/utils/tools.js
@@ -0,0 +1,76 @@
+// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
+// MIT License. See license.txt
+
+import showdown from 'showdown';
+
+frappe.provide("frappe.tools");
+
+frappe.tools.downloadify = function(data, roles, title) {
+ if(roles && roles.length && !has_common(roles, roles)) {
+ frappe.msgprint(__("Export not allowed. You need {0} role to export.", [frappe.utils.comma_or(roles)]));
+ return;
+ }
+
+ var filename = title + ".csv";
+ var csv_data = frappe.tools.to_csv(data);
+ var a = document.createElement('a');
+
+ if ("download" in a) {
+ // Used Blob object, because it can handle large files
+ var blob_object = new Blob([csv_data], { type: 'text/csv;charset=UTF-8' });
+ a.href = URL.createObjectURL(blob_object);
+ a.download = filename;
+
+ } else {
+ // use old method
+ a.href = 'data:attachment/csv,' + encodeURIComponent(csv_data);
+ a.download = filename;
+ a.target = "_blank";
+ }
+
+ document.body.appendChild(a);
+ a.click();
+
+ document.body.removeChild(a);
+};
+
+frappe.markdown = function(txt) {
+ if(!frappe.md2html) {
+ frappe.md2html = new showdown.Converter();
+ }
+
+ while(txt.substr(0,1)==="\n") {
+ txt = txt.substr(1);
+ }
+
+ // remove leading tab (if they exist in the first line)
+ var whitespace_len = 0,
+ first_line = txt.split("\n")[0];
+
+ while(["\n", "\t"].indexOf(first_line.substr(0,1))!== -1) {
+ whitespace_len++;
+ first_line = first_line.substr(1);
+ }
+
+ if(whitespace_len && whitespace_len != first_line.length) {
+ var txt1 = [];
+ $.each(txt.split("\n"), function(i, t) {
+ txt1.push(t.substr(whitespace_len));
+ })
+ txt = txt1.join("\n");
+ }
+
+ return frappe.md2html.makeHtml(txt);
+};
+
+frappe.tools.to_csv = function(data) {
+ var res = [];
+ $.each(data, function(i, row) {
+ row = $.map(row, function(col) {
+ if (col === null || col === undefined) col = '';
+ return typeof col === "string" ? ('"' + $('').html(col.replace(/"/g, '""')).text() + '"') : col;
+ });
+ res.push(row.join(","));
+ });
+ return res.join("\n");
+};
\ No newline at end of file
diff --git a/frappe/public/js/frappe/utils/urllib.js b/frappe/public/js/frappe/utils/urllib.js
new file mode 100644
index 0000000000..e6aba73717
--- /dev/null
+++ b/frappe/public/js/frappe/utils/urllib.js
@@ -0,0 +1,80 @@
+frappe.urllib = {
+ // get argument from url
+ get_arg: function(name) {
+ name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
+ var regexS = "[\\?&]"+name+"=([^]*)";
+ var regex = new RegExp( regexS );
+ var results = regex.exec( window.location.href );
+ if( results == null )
+ return "";
+ else
+ return decodeURIComponent(results[1]);
+ },
+
+ // returns url dictionary
+ get_dict: function() {
+ var d = {}
+ var t = window.location.href.split('?')[1];
+ if(!t) return d;
+
+ if(t.indexOf('#')!=-1) t = t.split('#')[0];
+ if(!t) return d;
+
+ t = t.split('&');
+ for(var i=0; i1) {
- for(var i=0;i\
- Print \
- Preview \
-
'},
- ]
- });
-
- dialog.$wrapper.find(".btn-print").click(function() {
- var args = dialog.get_values();
- _p.build(
- args.print_format, // fmtname
- _p.go, // onload
- args.no_letterhead // no_letterhead
- );
- });
-
- dialog.$wrapper.find(".btn-preview").click(function() {
- var args = dialog.get_values();
- _p.build(
- args.print_format, // fmtname
- _p.preview, // onload
- args.no_letterhead // no_letterhead
- );
- });
-
- dialog.on_page_show = function() {
- var $print = dialog.fields_dict.print_format.$input;
- $print.empty().add_options(cur_frm.print_preview.print_formats);
-
- if(cur_frm.$print_view_select && cur_frm.$print_view_select.val())
- $print.val(cur_frm.$print_view_select.val());
- }
-
- _p.dialog = dialog;
- },
-
- // Define formats dict
- formats: {},
-
- /* args dict can contain:
- + fmtname --> print format name
- + onload
- + no_letterhead
- + only_body
- */
- build: function(fmtname, onload, no_letterhead, only_body, no_heading) {
- if(!fmtname) {
- fmtname= "Standard";
- }
-
- var args = {
- fmtname: fmtname,
- onload: onload,
- no_letterhead: no_letterhead,
- only_body: only_body
- };
-
- if(!cur_frm) {
- frappe.msgprint(__("No document selected"));
- return;
- }
-
- if(!frappe.model.can_print(cur_frm.doctype, cur_frm)) {
- frappe.msgprint(__("You are not allowed to print this document"));
- return;
- }
-
- // Get current doc (record)
- var doc = locals[cur_frm.doctype][cur_frm.docname];
- if(args.fmtname == 'Standard') {
- args.onload(_p.render({
- body: _p.print_std(args.no_letterhead, no_heading),
- style: _p.print_style,
- doc: doc,
- title: doc.name,
- no_letterhead: args.no_letterhead,
- no_heading: no_heading,
- only_body: args.only_body
- }));
- } else {
- var print_format_doc = locals["Print Format"][args.fmtname];
- if(!print_format_doc) {
- frappe.msgprint(__("Unknown Print Format: {0}", [args.fmtname]));
- return;
- }
- args.onload(_p.render({
- body: print_format_doc.html,
- style: '',
- doc: doc,
- title: doc.name,
- no_letterhead: args.no_letterhead,
- no_heading: no_heading,
- only_body: args.only_body
- }));
- }
- },
-
- render: function(args) {
- var container = document.createElement('div');
- var stat = '';
-
- if(!args.no_heading) {
- // if draft/archived, show draft/archived banner
- stat += _p.show_draft(args);
- stat += _p.show_archived(args);
- stat += _p.show_cancelled(args);
- }
-
- // Append args.body's content as a child of container
- container.innerHTML = args.body;
-
- // Show letterhead?
- _p.show_letterhead(container, args);
-
- _p.run_embedded_js(container, args.doc);
-
- var style = _p.consolidate_css(container, args);
-
- _p.render_header_on_break(container, args);
-
- return _p.render_final(style, stat, container, args);
- },
-
-
- head_banner_format: function() {
- return "\
- \
-
\
- {{HEAD}}\
-
\
- {{DESCRIPTION}}\
-
"
- },
-
- /*
- Check if doc's status is not submitted (docstatus == 0)
- and submission is pending
-
- Display draft in header if true
- */
- show_draft: function(args) {
- var is_doctype_submittable = 0;
- var plist = locals['DocPerm'];
- for(var perm in plist) {
- var p = plist[perm];
- if((p.parent==args.doc.doctype) && (p.submit==1)){
- is_doctype_submittable = 1;
- break;
- }
- }
-
- if(args.doc && cint(args.doc.docstatus)==0 && is_doctype_submittable) {
- var draft = _p.head_banner_format();
- draft = draft.replace("{{HEAD}}", "DRAFT");
- draft = draft.replace("{{DESCRIPTION}}", "This box will go away after the document is submitted.");
- return draft;
- } else {
- return "";
- }
- },
-
-
- /*
- Check if doc is archived
- Display archived in header if true
- */
- show_archived: function(args) {
- if(args.doc && args.doc.__archived) {
- var archived = _p.head_banner_format();
- archived = archived.replace("{{HEAD}}", "ARCHIVED");
- archived = archived.replace("{{DESCRIPTION}}", "You must restore this document to make it editable.");
- return archived;
- } else {
- return "";
- }
- },
-
-
- /*
- Check if doc is cancelled
- Display cancelled in header if true
- */
- show_cancelled: function(args) {
- if(args.doc && args.doc.docstatus==2) {
- var cancelled = _p.head_banner_format();
- cancelled = cancelled.replace("{{HEAD}}", "CANCELLED");
- cancelled = cancelled.replace("{{DESCRIPTION}}", "You must amend this document to make it editable.");
- return cancelled;
- } else {
- return "";
- }
- },
-
-
- consolidate_css: function(container, args) {
- // Extract \
- \
- ';
- var footer = '\
- \
-