diff --git a/.eslintrc b/.eslintrc index e9586cf945..d7aa0f2e61 100644 --- a/.eslintrc +++ b/.eslintrc @@ -4,6 +4,10 @@ "node": true, "es6": true }, + "parserOptions": { + "ecmaVersion": 6, + "sourceType": "module" + }, "extends": "eslint:recommended", "rules": { "indent": [ @@ -56,21 +60,6 @@ "root": true, "globals": { "frappe": true, - "$": true, - "jQuery": true, - "moment": true, - "hljs": true, - "Awesomplete": true, - "Sortable": true, - "Showdown": true, - "Taggle": true, - "Gantt": true, - "Slick": true, - "Webcam": true, - "PhotoSwipe": true, - "PhotoSwipeUI_Default": true, - "fluxify": true, - "io": true, "__": true, "_p": true, "_f": true, @@ -94,7 +83,6 @@ "format_number": true, "format_currency": true, "comment_when": true, - "replace_newlines": true, "open_url_post": true, "toTitle": true, "lstrip": true, @@ -103,7 +91,6 @@ "replace_all": true, "flt": true, "precision": true, - "md5": true, "CREATE": true, "AMEND": true, "CANCEL": true, @@ -129,6 +116,23 @@ "getCookie": true, "getCookies": true, "get_url_arg": true, + + "md5": true, + "$": true, + "jQuery": true, + "moment": true, + "hljs": true, + "Awesomplete": true, + "Sortable": true, + "Showdown": true, + "Taggle": true, + "Gantt": true, + "Slick": true, + "Webcam": true, + "PhotoSwipe": true, + "PhotoSwipeUI_Default": true, + "fluxify": true, + "io": true, "QUnit": true, "JsBarcode": true, "L": true, diff --git a/.travis.yml b/.travis.yml index 854fc41abc..0aedaec96d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,7 +15,7 @@ install: - sudo apt-get purge -y mysql-common mysql-server mysql-client - nvm install v7.10.0 - wget https://raw.githubusercontent.com/frappe/bench/master/playbooks/install.py - + - sudo python install.py --develop --user travis --without-bench-setup - sudo pip install -e ~/bench @@ -35,8 +35,8 @@ before_script: - bench setup-help - bench scheduler disable - bench start & - - sleep 10 + - sleep 20 script: - - set -e + # - set -e - bench run-tests diff --git a/frappe-html-plugin.js b/frappe-html-plugin.js new file mode 100644 index 0000000000..b6ff6b57c4 --- /dev/null +++ b/frappe-html-plugin.js @@ -0,0 +1,26 @@ +const path = require('path'); + +function scrub_html_template(content) { + content = content.replace(/\s/g, ' '); + content = content.replace(/()/g, ''); + return content.replace("'", "\'"); // eslint-disable-line +} + +module.exports = function frappe_html() { + return { + name: 'frappe-html', + transform(code, id) { + if (!id.endsWith('.html')) return null; + + var filepath = path.basename(id).split('.'); + filepath.splice(-1); + + var key = filepath.join("."); + var content = scrub_html_template(code); + + return ` + frappe.templates['${key}'] = '${content}'; + `; + } + }; +}; \ No newline at end of file diff --git a/frappe/build.py b/frappe/build.py index 7b7127ea89..e58f676eb6 100644 --- a/frappe/build.py +++ b/frappe/build.py @@ -3,10 +3,10 @@ from __future__ import unicode_literals, print_function from frappe.utils.minify import JavascriptMinify -import subprocess import warnings from six import iteritems, text_type +import subprocess """ Build the `public` folders and setup languages @@ -28,36 +28,18 @@ def bundle(no_compress, make_copy=False, restore=False, verbose=False): """concat / minify js files""" # build js files setup() - make_asset_dirs(make_copy=make_copy, restore=restore) - # new nodejs build system - command = 'node --use_strict ../apps/frappe/frappe/build.js --build' - if not no_compress: - command += ' --minify' - subprocess.call(command.split(' ')) - - # build(no_compress, verbose) + command = 'yarn run build' if no_compress else 'yarn run production' + frappe_app_path = os.path.abspath(os.path.join(app_paths[0], '..')) + subprocess.call(command.split(" "), cwd=frappe_app_path) def watch(no_compress): """watch and rebuild if necessary""" + setup() - # new nodejs file watcher - command = 'node --use_strict ../apps/frappe/frappe/build.js --watch' - subprocess.call(command.split(' ')) - - # setup() - - # import time - # compile_less() - # build(no_compress=True) - - # while True: - # compile_less() - # if files_dirty(): - # build(no_compress=True) - - # time.sleep(3) + frappe_app_path = os.path.abspath(os.path.join(app_paths[0], '..')) + subprocess.call('yarn run watch'.split(" "), cwd = frappe_app_path) def make_asset_dirs(make_copy=False, restore=False): # don't even think of making assets_path absolute - rm -rf ahead. diff --git a/frappe/commands/__init__.py b/frappe/commands/__init__.py index 579da214c5..993f1f7d11 100644 --- a/frappe/commands/__init__.py +++ b/frappe/commands/__init__.py @@ -8,6 +8,7 @@ import cProfile import pstats import frappe import frappe.utils +import subprocess # nosec from functools import wraps from six import StringIO @@ -46,6 +47,26 @@ def get_site(context): print('Please specify --site sitename') sys.exit(1) +def popen(command, *args, **kwargs): + output = kwargs.get('output', True) + cwd = kwargs.get('cwd') + shell = kwargs.get('shell', True) + raise_err = kwargs.get('raise_err') + + proc = subprocess.Popen(command, + stdout = None if output else subprocess.PIPE, + stderr = None if output else subprocess.PIPE, + shell = shell, + cwd = cwd + ) + + return_ = proc.wait() + + if raise_err: + raise subprocess.CalledProcessError(return_, command) + + return return_ + def call_command(cmd, context): return click.Context(cmd, obj=context).forward(cmd) diff --git a/frappe/commands/utils.py b/frappe/commands/utils.py index 4ff60c2c16..fbf9609bce 100644 --- a/frappe/commands/utils.py +++ b/frappe/commands/utils.py @@ -328,7 +328,7 @@ def console(context): frappe.connect() frappe.local.lang = frappe.db.get_default("lang") import IPython - IPython.embed() + IPython.embed(disable_banner = True) @click.command('run-tests') @click.option('--app', help="For App") diff --git a/frappe/public/build.json b/frappe/public/build.json index 46601575df..af37eedbe7 100755 --- a/frappe/public/build.json +++ b/frappe/public/build.json @@ -2,8 +2,8 @@ "css/frappe-web.css": [ "public/css/font-awesome.css", "public/css/octicons/octicons.css", - "public/css/website.css", - "public/css/avatar.css" + "public/less/website.less", + "public/less/avatar.less" ], "js/frappe-web.min.js": [ "public/js/frappe/class.js", @@ -111,20 +111,20 @@ "public/css/bootstrap.css", "public/css/font-awesome.css", "public/css/octicons/octicons.css", - "public/css/desk.css", - "public/css/flex.css", - "public/css/indicator.css", - "public/css/avatar.css", - "public/css/navbar.css", - "public/css/sidebar.css", - "public/css/page.css", - "public/css/tree.css", - "public/css/desktop.css", - "public/css/form.css", - "public/css/mobile.css", - "public/css/kanban.css", - "public/css/controls.css", - "public/css/chat.css" + "public/less/desk.less", + "public/less/flex.less", + "public/less/indicator.less", + "public/less/avatar.less", + "public/less/navbar.less", + "public/less/sidebar.less", + "public/less/page.less", + "public/less/tree.less", + "public/less/desktop.less", + "public/less/form.less", + "public/less/mobile.less", + "public/less/kanban.less", + "public/less/controls.less", + "public/less/chat.less" ], "css/frappe-rtl.css": [ "public/css/bootstrap-rtl.css", @@ -140,7 +140,6 @@ "public/js/lib/moment/moment-with-locales.min.js", "public/js/lib/moment/moment-timezone-with-data.min.js", "public/js/lib/socket.io.min.js", - "public/js/lib/markdown.js", "public/js/lib/jSignature.min.js", "public/js/frappe/translate.js", "public/js/lib/datepicker/datepicker.min.js", @@ -255,10 +254,10 @@ "public/js/frappe/chat.js" ], "css/module.min.css": [ - "public/css/module.css" + "public/less/module.less" ], "css/form.min.css": [ - "public/css/form_grid.css" + "public/less/form_grid.less" ], "js/form.min.js": [ "public/js/frappe/form/templates/grid_form.html", @@ -299,10 +298,10 @@ "public/js/frappe/form/quick_entry.js" ], "css/list.min.css": [ - "public/css/list.css", - "public/css/calendar.css", - "public/css/role_editor.css", - "public/css/gantt.css" + "public/less/list.less", + "public/less/calendar.less", + "public/less/role_editor.less", + "public/less/gantt.less" ], "js/list.min.js": [ "public/js/frappe/ui/listing.html", @@ -351,9 +350,9 @@ "public/js/frappe/views/kanban/kanban_card.html" ], "css/report.min.css": [ - "public/css/report.css", + "public/less/report.less", "public/css/tree_grid.css", - "public/css/frappe-datatable.css", + "public/less/frappe-datatable.less", "public/js/lib/slickgrid/slick.grid.css", "public/js/lib/slickgrid/slick-default-theme.css", diff --git a/frappe/public/js/docs.js b/frappe/public/js/docs.js index 4fea7d676e..c216de67f9 100644 --- a/frappe/public/js/docs.js +++ b/frappe/public/js/docs.js @@ -1,7 +1,7 @@ // used in documenation site built via document generator $(function() { - if(hljs) { + if(window.hljs) { $('pre code').each(function(i, block) { hljs.highlightBlock(block); }); @@ -10,7 +10,7 @@ $(function() { // search $('.sidebar-navbar-items .octicon-search, .navbar .octicon-search').parent().on("click", function() { var modal = frappe.get_modal("Search", - '

\ + '

\

Search via Google

'); modal.find(".search-input").on("keyup", function(e) { if(e.which===13) { @@ -49,4 +49,4 @@ frappe = { return modal; }, -} +}; diff --git a/frappe/public/js/frappe/chat.js b/frappe/public/js/frappe/chat.js index 4b9a421767..1ecf9a058b 100644 --- a/frappe/public/js/frappe/chat.js +++ b/frappe/public/js/frappe/chat.js @@ -16,19 +16,19 @@ frappe.provide('frappe.model') /** * @description Subscribe to a model for realtime updates. - * + * * @example * frappe.model.subscribe('User') * // Subscribe to all User records - * + * * frappe.model.subscribe('User', 'achilles@frappe.io') * frappe.model.subscribe('User', ['achilles@frappe.io', 'rushabh@frappe.io']) * // Subscribe to User of name(s) - * + * * frappe.model.subscribe('User', 'achilles@frappe.io', 'username') * frappe.model.subscribe('User', ['achilles@frappe.io', 'rushabh@frappe.io'], ['email', 'username']) * // Subscribe to User of name for field(s) - * + * * @todo Under Development */ frappe.model.subscribe = (doctype, name, field) => @@ -43,62 +43,66 @@ frappe.model.subscribe = (doctype, name, field) => * catch (e) * console.log(e.name) * // returns "FrappeError" - * + * * @see https://stackoverflow.com/a/32749533 * @todo Requires "transform-builtin-extend" for Babel 6 */ -frappe.Error = class extends Error { - constructor (message) { - super (message) +frappe.Error = Error; +// class extends Error { +// constructor (message) { +// super (message) - this.name = 'FrappeError' +// this.name = 'FrappeError' - if ( typeof Error.captureStackTrace === 'function' ) - Error.captureStackTrace(this, this.constructor) - else - this.stack = (new Error(message)).stack - } -} +// if ( typeof Error.captureStackTrace === 'function' ) +// Error.captureStackTrace(this, this.constructor) +// else +// this.stack = (new Error(message)).stack +// } +// } /** * @description TypeError */ -frappe.TypeError = class extends frappe.Error { - constructor (message) { - super (message) +frappe.TypeError = TypeError; +// class extends frappe.Error { +// constructor (message) { +// super (message) - this.name = this.constructor.name - } -} +// this.name = this.constructor.name +// } +// } /** * @description ValueError */ -frappe.ValueError = class extends frappe.Error { - constructor (message) { - super (message) +frappe.ValueError = Error +// class extends frappe.Error { +// constructor (message) { +// super (message) - this.name = this.constructor.name - } -} +// this.name = this.constructor.name +// } +// } /** * @description ImportError */ -frappe.ImportError = class extends frappe.Error { - constructor (message) { - super (message) +frappe.ImportError = Error +// class extends frappe.Error { +// constructor (message) { +// super (message) - this.name = this.constructor.name - } -} +// this.name = this.constructor.name +// } +// } // frappe.datetime frappe.provide('frappe.datetime') /** * @description Frappe's datetime object. (Inspired by Python's datetime object). - * + * * @example * const datetime = new frappe.datetime.datetime() */ @@ -124,7 +128,7 @@ frappe.datetime.datetime = class { /** * @description Returns the current datetime. - * + * * @example * const datetime = new frappe.datetime.now() */ @@ -141,17 +145,17 @@ frappe.datetime.equal = (a, b, type) => { /** * @description Compares two frappe.datetime.datetime objects. - * + * * @param {frappe.datetime.datetime} a - A frappe.datetime.datetime/moment object. * @param {frappe.datetime.datetime} b - A frappe.datetime.datetime/moment object. - * + * * @returns {number} 0 (if a and b are equal), 1 (if a is before b), -1 (if a is after b). - * + * * @example * frappe.datetime.compare(frappe.datetime.now(), frappe.datetime.now()) * // returns 0 * const then = frappe.datetime.now() - * + * * frappe.datetime.compare(then, frappe.datetime.now()) * // returns 1 */ @@ -176,12 +180,12 @@ frappe.provide('frappe._') /** * @description Python-inspired format extension for string objects. - * + * * @param {string} string - A string with placeholders. * @param {object} object - An object with placeholder, value pairs. - * + * * @return {string} - The formatted string. - * + * * @example * frappe._.format('{foo} {bar}', { bar: 'foo', foo: 'bar' }) * // returns "bar foo" @@ -195,17 +199,17 @@ frappe._.format = (string, object) => { /** * @description Fuzzy Search a given query within a dataset. - * + * * @param {string} query - A query string. * @param {array} dataset - A dataset to search within, can contain singletons or objects. * @param {object} options - Options as per fuze.js - * + * * @return {array} - The fuzzy matched index/object within the dataset. - * + * * @example * frappe._.fuzzy_search("foobar", ["foobar", "bartender"]) * // returns [0, 1] - * + * * @see http://fusejs.io */ frappe._.fuzzy_search = (query, dataset, options) => { @@ -227,29 +231,29 @@ frappe._.fuzzy_search = (query, dataset, options) => { /** * @description Pluralizes a given word. - * + * * @param {string} word - The word to be pluralized. * @param {number} count - The count. - * + * * @return {string} - The pluralized string. - * + * * @example * frappe._.pluralize('member', 1) * // returns "member" * frappe._.pluralize('members', 0) * // returns "members" - * + * * @todo Handle more edge cases. */ frappe._.pluralize = (word, count = 0, suffix = 's') => `${word}${count === 1 ? '' : suffix}` /** * @description Captializes a given string. - * + * * @param {word} - The word to be capitalized. - * + * * @return {string} - The capitalized word. - * + * * @example * frappe._.capitalize('foobar') * // returns "Foobar" @@ -260,11 +264,11 @@ frappe._.capitalize = word => `${word.charAt(0).toUpperCase()}${word.slice(1)}` /** * @description Returns the first element of an array. - * + * * @param {array} array - The array. - * + * * @returns - The first element of an array, undefined elsewise. - * + * * @example * frappe._.head([1, 2, 3]) * // returns 1 @@ -275,15 +279,15 @@ frappe._.head = arr => frappe._.is_empty(arr) ? undefined : arr[0] /** * @description Returns a copy of the given array (shallow). - * + * * @param {array} array - The array to be copied. - * + * * @returns {array} - The copied array. - * + * * @example * frappe._.copy_array(["foobar", "barfoo"]) * // returns ["foobar", "barfoo"] - * + * * @todo Add optional deep copy. */ frappe._.copy_array = array => { @@ -295,23 +299,23 @@ frappe._.copy_array = array => { /** * @description Check whether an array|string|object|jQuery is empty. - * + * * @param {any} value - The value to be checked on. - * - * @returns {boolean} - Returns if the object is empty. - * + * + * @returns {boolean} - Returns if the object is empty. + * * @example * frappe._.is_empty([]) // returns true * frappe._.is_empty(["foo"]) // returns false - * + * * frappe._.is_empty("") // returns true * frappe._.is_empty("foo") // returns false - * + * * frappe._.is_empty({ }) // returns true * frappe._.is_empty({ foo: "bar" }) // returns false - * + * * frappe._.is_empty($('.papito')) // returns false - * + * * @todo Handle other cases. */ frappe._.is_empty = value => { @@ -331,31 +335,31 @@ frappe._.is_empty = value => { /** * @description Converts a singleton to an array, if required. - * + * * @param {object} item - An object - * + * * @example * frappe._.as_array("foo") * // returns ["foo"] - * + * * frappe._.as_array(["foo"]) * // returns ["foo"] - * + * * @see https://docs.oracle.com/javase/8/docs/api/java/util/Arrays.html#asList-T...- */ frappe._.as_array = item => Array.isArray(item) ? item : [item] /** * @description Return a singleton if array contains a single element. - * + * * @param {array} list - An array to squash. - * + * * @returns {array|object} - Returns an array if there's more than 1 object else the first object itself. - * + * * @example * frappe._.squash(["foo"]) * // returns "foo" - * + * * frappe._.squash(["foo", "bar"]) * // returns ["foo", "bar"] */ @@ -363,11 +367,11 @@ frappe._.squash = list => Array.isArray(list) && list.length === 1 ? list[0] : l /** * @description Returns true, if the current device is a mobile device. - * + * * @example * frappe._.is_mobile() * // returns true|false - * + * * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Browser_detection_using_the_user_agent */ frappe._.is_mobile = () => { @@ -380,7 +384,7 @@ frappe._.is_mobile = () => { /** * @description Removes falsey values from an array. - * + * * @example * frappe._.compact([1, 2, false, NaN, '']) * // returns [1, 2] @@ -395,11 +399,11 @@ frappe.utils = { ...frappe.utils, ...frappe._ } // frappe.user extensions /** * @description Returns the first name of a User. - * + * * @param {string} user - User - * + * * @returns The first name of the user. - * + * * @example * frappe.user.first_name("Rahul Malhotra") * // returns "Rahul" @@ -411,9 +415,9 @@ frappe.user.first_name = user => frappe._.head(frappe.user.full_name(user).split frappe.provide('frappe.ui') /** * @description Frappe's Uploader Widget - * + * * @see - Heavily inspired https://uppy.io - * + * * @todo Under Development */ frappe.ui.Uploader = class { @@ -458,7 +462,7 @@ frappe.ui.keycode = { RETURN: 13 } frappe.provide('frappe.stores') /** * @description Frappe's Store Class - * + * * @todo Under Development */ frappe.Store = class { @@ -471,18 +475,18 @@ frappe.Store = class { frappe.provide('frappe.loggers') /** * @description Frappe's Logger Class - * + * * @example * frappe.log = frappe.Logger.get('foobar') * frappe.log.level = frappe.Logger.DEBUG - * + * * frappe.log.info('foobar') * // prints '[timestamp] foobar: foobar' */ frappe.Logger = class { /** * @description Frappe's Logger Class's constructor. - * + * * @param {string} name - Name of the logger. */ constructor (name) { @@ -499,7 +503,7 @@ frappe.Logger = class { /** * @description Get instance of frappe.Logger (return registered one if declared). - * + * * @param {string} name - Name of the logger. */ static get (name) { @@ -544,15 +548,15 @@ frappe.provide('frappe.chat.profile') /** * @description Create a Chat Profile. - * + * * @param {string|array} fields - (Optional) fields to be retrieved after creating a Chat Profile. * @param {function} fn - (Optional) callback with the returned Chat Profile. - * + * * @returns {Promise} - * + * * @example * frappe.chat.profile.create(console.log) - * + * * frappe.chat.profile.create("status").then(console.log) // { status: "Online" } */ frappe.chat.profile.create = (fields, fn) => { @@ -569,7 +573,7 @@ frappe.chat.profile.create = (fields, fn) => { response => { if ( fn ) fn(response.message) - + resolve(response.message) }) }) @@ -577,10 +581,10 @@ frappe.chat.profile.create = (fields, fn) => { /** * @description Updates a Chat Profile. - * + * * @param {string} user - (Optional) Chat Profile User, defaults to session user. * @param {object} update - (Required) Updates to be dispatched. - * + * * @example * frappe.chat.profile.update(frappe.session.user, { "status": "Offline" }) */ @@ -591,7 +595,7 @@ frappe.chat.profile.update = (user, update, fn) => { response => { if ( fn ) fn(response.message) - + resolve(response.message) }) }) @@ -602,11 +606,11 @@ frappe.provide('frappe.chat.profile.on') /** * @description Triggers on a Chat Profile update of a user (Only if there's a one-on-one conversation). - * + * * @param {function} fn - (Optional) callback with the User and the Chat Profile update. - * + * * @returns {Promise} - * + * * @example * frappe.chat.profile.on.update(function (user, update) * { @@ -638,15 +642,15 @@ frappe.provide('frappe.chat.room') /** * @description Creates a Chat Room. - * + * * @param {string} kind - (Required) "Direct", "Group" or "Visitor". * @param {string} owner - (Optional) Chat Room owner (defaults to current user). * @param {string|array} users - (Required for "Direct" and "Visitor", Optional for "Group") User(s) within Chat Room. * @param {string} name - Chat Room name. * @param {function} fn - callback with created Chat Room. - * + * * @returns {Promise} - * + * * @example * frappe.chat.room.create("Direct", frappe.session.user, "foo@bar.com", function (room) { * // do stuff @@ -662,7 +666,7 @@ frappe.chat.room.create = function (kind, owner, users, name, fn) { } users = frappe._.as_array(users) - + return new Promise(resolve => { frappe.call("frappe.chat.doctype.chat_room.chat_room.create", { kind: kind, owner: owner || frappe.session.user, users: users, name: name }, @@ -680,13 +684,13 @@ frappe.chat.room.create = function (kind, owner, users, name, fn) { /** * @description Returns Chat Room(s). - * + * * @param {string|array} names - (Optional) Chat Room(s) to retrieve. * @param {string|array} fields - (Optional) fields to be retrieved for each Chat Room. * @param {function} fn - (Optional) callback with the returned Chat Room(s). - * + * * @returns {Promise} - * + * * @example * frappe.chat.room.get(function (rooms) { * // do stuff @@ -694,17 +698,17 @@ frappe.chat.room.create = function (kind, owner, users, name, fn) { * frappe.chat.room.get().then(function (rooms) { * // do stuff * }) - * + * * frappe.chat.room.get(null, ["room_name", "avatar"], function (rooms) { * // do stuff * }) - * + * * frappe.chat.room.get("CR00001", "room_name", function (room) { * // do stuff * }) - * + * * frappe.chat.room.get(["CR00001", "CR00002"], ["room_name", "last_message"], function (rooms) { - * + * * }) */ frappe.chat.room.get = function (names, fields, fn) { @@ -754,9 +758,9 @@ frappe.chat.room.get = function (names, fields, fn) { /** * @description Subscribe current user to said Chat Room(s). - * + * * @param {string|array} rooms - Chat Room(s). - * + * * @example * frappe.chat.room.subscribe("CR00001") */ @@ -766,11 +770,11 @@ frappe.chat.room.subscribe = function (rooms) { /** * @description Get Chat Room history. - * + * * @param {string} name - Chat Room name - * + * * @returns {Promise} - Chat Message(s) - * + * * @example * frappe.chat.room.history(function (messages) * { @@ -787,7 +791,7 @@ frappe.chat.room.history = function (name, fn) { if ( fn ) fn(messages) - + resolve(messages) }) }) @@ -795,10 +799,10 @@ frappe.chat.room.history = function (name, fn) { /** * @description Searches Rooms based on a query. - * + * * @param {string} query - The query string. * @param {array} rooms - A list of Chat Rooms. - * + * * @returns {array} - A fuzzy searched list of rooms. */ frappe.chat.room.search = function (query, rooms) { @@ -819,7 +823,7 @@ frappe.chat.room.search = function (query, rooms) { /** * @description Sort Chat Room(s) based on Last Message Timestamp or Creation Date. - * + * * @param {array} - A list of Chat Room(s) * @param {compare} - (Optional) a comparision function. */ @@ -846,7 +850,7 @@ frappe.provide('frappe.chat.room.on') /** * @description Triggers on Chat Room updated. - * + * * @param {function} fn - callback with the Chat Room and Update. */ frappe.chat.room.on.update = function (fn) { @@ -854,14 +858,14 @@ frappe.chat.room.on.update = function (fn) { if ( r.data.last_message ) // creation to frappe.datetime.datetime (easier to manipulate). r.data = { ...r.data, last_message: { ...r.data.last_message, creation: new frappe.datetime.datetime(r.data.last_message.creation) } } - + fn(r.room, r.data) }) } /** * @description Triggers on Chat Room created. - * + * * @param {function} fn - callback with the created Chat Room. */ frappe.chat.room.on.create = function (fn) { @@ -870,7 +874,7 @@ frappe.chat.room.on.create = function (fn) { /** * @description Triggers when a User is typing in a Chat Room. - * + * * @param {function} fn - callback with the typing User within the Chat Room. */ frappe.chat.room.on.typing = function (fn) { @@ -930,7 +934,7 @@ frappe.chat.message.on.update = function (fn) { frappe.chat.pretty_datetime = function (date) { const today = moment() const instance = date.moment - + if ( today.isSame(instance, "d") ) return instance.format("hh:mm A") else @@ -945,9 +949,9 @@ frappe.provide('frappe.chat.sound') /** * @description Plays a given registered sound. - * + * * @param {value} - The name of the registered sound. - * + * * @example * frappe.chat.sound.play("message") */ @@ -984,7 +988,7 @@ frappe.chat.emoji = function (fn) { else $.get('https://cdn.rawgit.com/frappe/emoji/master/emoji', (data) => { frappe.chat.emojis = JSON.parse(data) - + if ( fn ) fn(frappe.chat.emojis) @@ -1003,7 +1007,7 @@ frappe.provide('frappe.chat.component') /** * @description Button Component - * + * * @prop {string} type - (Optional) "default", "primary", "info", "success", "warning", "danger" (defaults to "default") * @prop {boolean} block - (Optional) Render a button block (defaults to false). */ @@ -1038,7 +1042,7 @@ frappe.components.Button.defaultProps /** * @description FAB Component - * + * * @extends frappe.components.Button */ frappe.components.FAB @@ -1047,7 +1051,7 @@ class extends frappe.components.Button { render ( ) { const { props } = this const size = frappe.components.FAB.SIZE[props.size] - + return ( h(frappe.components.Button, { ...props, class: `${props.class} ${size && size.class}`}, h("i", { class: props.icon }) @@ -1103,7 +1107,7 @@ frappe.components.FontAwesome.defaultProps /** * @description Octicon Component - * + * * @extends frappe.Component */ frappe.components.Octicon @@ -1118,7 +1122,7 @@ class extends Component { /** * @description Avatar Component - * + * * @prop {string} title - (Optional) title for the avatar. * @prop {string} abbr - (Optional) abbreviation for the avatar, defaults to the first letter of the title. * @prop {string} size - (Optional) size of the avatar to be displayed. @@ -1157,13 +1161,13 @@ frappe.components.Avatar.SIZE /** * @description Frappe Chat Object. - * + * * @example * const chat = new frappe.Chat(options) // appends to "body" * chat.render() * const chat = new frappe.Chat(".selector", options) * chat.render() - * + * * const chat = new frappe.Chat() * chat.set_wrapper('.selector') * .set_options(options) @@ -1174,7 +1178,7 @@ frappe.Chat class { /** * @description Frappe Chat Object. - * + * * @param {string} selector - A query selector, HTML Element or jQuery object. * @param {object} options - Optional configurations. */ @@ -1196,9 +1200,9 @@ class { /** * Set the container on which the chat widget is mounted on. * @param {string|HTMLElement} selector - A query selector, HTML Element or jQuery object. - * + * * @returns {frappe.Chat} - The instance. - * + * * @example * const chat = new frappe.Chat() * chat.set_wrapper(".selector") @@ -1212,9 +1216,9 @@ class { /** * Set the configurations for the chat interface. * @param {object} options - Optional Configurations. - * + * * @returns {frappe.Chat} - The instance. - * + * * @example * const chat = new frappe.Chat() * chat.set_options({ layout: frappe.Chat.Layout.PAGE }) @@ -1227,9 +1231,9 @@ class { /** * @description Destory the chat widget. - * + * * @returns {frappe.Chat} - The instance. - * + * * @example * const chat = new frappe.Chat() * chat.render() @@ -1244,9 +1248,9 @@ class { /** * @description Render the chat widget component onto destined wrapper. - * + * * @returns {frappe.Chat} - The instance. - * + * * @example * const chat = new frappe.Chat() * chat.render() @@ -1289,10 +1293,10 @@ class extends Component { this.room.add = (rooms) => { rooms = frappe._.as_array(rooms) const names = rooms.map(r => r.name) - + frappe.log.info(`Subscribing ${frappe.session.user} to Chat Rooms ${names.join(", ")}.`) frappe.chat.room.subscribe(names) - + const state = [ ] for (const room of rooms) @@ -1353,13 +1357,13 @@ class extends Component { frappe.chat.room.history(name, (messages) => { const { state } = this const room = state.rooms.find(r => r.name === name) - + this.set_state({ room: { ...state.room, ...room, messages: messages } }) }) } - + this.state = frappe.Chat.Widget.defaultState this.make() @@ -1382,7 +1386,7 @@ class extends Component { this.bind() }) } - + bind ( ) { frappe.chat.profile.on.update((user, update) => { frappe.log.warn(`TRIGGER: Chat Profile update ${JSON.stringify(update)} of User ${user}.`) @@ -1395,7 +1399,7 @@ class extends Component { } else { const status = frappe.chat.profile.STATUSES.find(s => s.name === update.status) const color = status.color - + const alert = ` ${frappe.user.full_name(user)} is currently ${update.status}` frappe.show_alert(alert, 3) } @@ -1411,19 +1415,19 @@ class extends Component { frappe.log.warn(`TRIGGER: Chat Room ${room} update ${JSON.stringify(update)} recieved.`) this.room.update(room, update) }) - + frappe.chat.room.on.typing((room, user) => { if ( user !== frappe.session.user ) { frappe.log.warn(`User ${user} typing in Chat Room ${room}.`) this.room.update(room, { typing: user }) - + setTimeout(() => this.room.update(room, { typing: null }), 5000) } }) frappe.chat.message.on.create((r) => { const { state } = this - + // play sound. if ( state.room.name ) state.profile.conversation_tones && frappe.chat.sound.play('message') @@ -1433,21 +1437,21 @@ class extends Component { if ( r.user !== frappe.session.user && state.profile.message_preview && !state.toggle ) { const $element = $('body').find('.frappe-chat-alert') $element.remove() - + const alert = // TODO: ellipses content ` ${frappe.user.first_name(r.user)}: ${r.content} ` - + frappe.show_alert(alert, 3) } - + if ( r.room === state.room.name ) { const mess = frappe._.copy_array(state.room.messages) mess.push(r) - + this.set_state({ room: { ...state.room, messages: mess } }) } }) @@ -1460,7 +1464,7 @@ class extends Component { render ( ) { const { props, state } = this const me = this - + const ActionBar = h(frappe.Chat.Widget.ActionBar, { placeholder: __("Search or Create a New Chat"), class: "level", @@ -1541,7 +1545,7 @@ class extends Component { return { owner: frappe.session.user, users: [frappe.boot.user_info[key].email] } }) const rooms = state.query ? frappe.chat.room.search(state.query, state.rooms.concat(contacts)) : frappe.chat.room.sort(state.rooms) - + const RoomList = frappe._.is_empty(rooms) && !state.query ? h("div", { class: "vcenter" }, h("div", { class: "text-center text-extra-muted" }, @@ -1583,7 +1587,7 @@ class extends Component { ) ) ) - + return component ? h("div", { class: "frappe-chat" }, component @@ -1624,7 +1628,7 @@ class extends Component { toggle = active else toggle = this.state.active ? false : true - + this.set_state({ active: toggle }) this.props.toggle(toggle) @@ -1639,7 +1643,7 @@ class extends Component { render ( ) { const { props, state } = this - + return !state.destroy ? ( h("div", { class: "frappe-chat-popper" }, @@ -1680,7 +1684,7 @@ frappe.Chat.Widget.ActionBar class extends Component { constructor (props) { super (props) - + this.change = this.change.bind(this) this.submit = this.submit.bind(this) @@ -1699,7 +1703,7 @@ class extends Component { submit (e) { const { props, state } = this - + e.preventDefault() props.submit(state.query) @@ -1707,7 +1711,7 @@ class extends Component { on_mounted ( ) { - $(document).ready(function (e) + $(document).ready(function (e) { // if ( e.keyCode === frappe.ui.keycode.CTRL ) }) @@ -1937,7 +1941,7 @@ class extends Component { icon: "file", label: "File", on_click: ( ) => { - + } } ]) @@ -1990,7 +1994,7 @@ class extends Component { const { props } = this const item = { } - + if ( props.type === "Group" ) { item.route = `Form/Chat Room/${props.name}` @@ -2017,7 +2021,7 @@ class extends Component { } const popper = props.layout === frappe.Chat.Layout.POPPER || frappe._.is_mobile() - + return ( h("div", { class: "panel-heading", style: { "height": "50px" } }, // sorry. :( h("div", { class: "level" }, @@ -2045,7 +2049,7 @@ class extends Component { /** * @description ChatList Component - * + * * @prop {array} messages - ChatMessage(s) */ frappe.chat.component.ChatList @@ -2071,7 +2075,7 @@ class extends Component { messages.push(message) } - + return ( h("div",{class:"chat-list list-group"}, !frappe._.is_empty(messages) ? @@ -2083,14 +2087,14 @@ class extends Component { /** * @description ChatList.Item Component - * + * * @prop {string} name - ChatMessage name * @prop {string} user - ChatMessage user * @prop {string} room - ChatMessage room * @prop {string} room_type - ChatMessage room_type ("Direct", "Group" or "Visitor") * @prop {string} content - ChatMessage content * @prop {frappe.datetime.datetime} creation - ChatMessage creation - * + * * @prop {boolean} groupable - Whether the ChatMessage is groupable. */ frappe.chat.component.ChatList.Item @@ -2109,7 +2113,7 @@ class extends Component { props.content ) ) - : + : h("div",{class:`${me ? "text-right" : ""}`}, props.room_type === "Group" && !me ? h(frappe.components.Avatar, { @@ -2125,14 +2129,14 @@ class extends Component { /** * @description ChatBubble Component - * + * * @prop {string} name - ChatMessage name * @prop {string} user - ChatMessage user * @prop {string} room - ChatMessage room * @prop {string} room_type - ChatMessage room_type ("Direct", "Group" or "Visitor") * @prop {string} content - ChatMessage content * @prop {frappe.datetime.datetime} creation - ChatMessage creation - * + * * @prop {boolean} groupable - Whether the ChatMessage is groupable. */ frappe.chat.component.ChatBubble @@ -2142,7 +2146,7 @@ class extends Component { const { props } = this const creation = props.creation.format('hh:mm A') - + const me = props.user === frappe.session.user const read = !frappe._.is_empty(props.seen) && !props.seen.includes(frappe.session.user) @@ -2179,7 +2183,7 @@ frappe.chat.component.ChatForm class extends Component { constructor (props) { super (props) - + this.on_change = this.on_change.bind(this) this.on_submit = this.on_submit.bind(this) @@ -2213,7 +2217,7 @@ class extends Component { if ( token ) { props.hint = frappe._.as_array(props.hint) const hint = props.hint.find(hint => hint.match.test(token)) - + if ( hint ) { hint.search(token, items => { const hints = items.map(item => { @@ -2224,7 +2228,7 @@ class extends Component { return item }).slice(0, hint.max || 5) - + this.set_state({ hints }) }) } @@ -2314,7 +2318,7 @@ frappe.chat.component.ChatForm.defaultState /** * @description EmojiPicker Component - * + * * @todo Under Development */ frappe.chat.component.EmojiPicker @@ -2345,7 +2349,7 @@ class extends Component { return ( h("div", { class: "list-group" }, - + ) ) } @@ -2388,7 +2392,7 @@ frappe.notify = (string, options) => { frappe.log = frappe.Logger.get('frappe.notify') - const OPTIONS = + const OPTIONS = { icon: frappe.assets.image('favicon.png', 'frappe'), lang: frappe.boot.lang || "en" @@ -2397,7 +2401,7 @@ frappe.notify = (string, options) => if ( !frappe.browser.Notification ) frappe.log.error('ERROR: This browser does not support desktop notifications.') - + Notification.requestPermission(status => { if ( status === "granted" ) diff --git a/frappe/public/js/frappe/class.js b/frappe/public/js/frappe/class.js index 591b70f72a..4f6dd0dc97 100644 --- a/frappe/public/js/frappe/class.js +++ b/frappe/public/js/frappe/class.js @@ -13,72 +13,71 @@ To subclass, use: }) */ +// https://stackoverflow.com/a/15052240/5353542 -/* Simple JavaScript Inheritance - * By John Resig http://ejohn.org/ +/* Simple JavaScript Inheritance for ES 5.1 + * based on http://ejohn.org/blog/simple-javascript-inheritance/ + * (inspired by base2 and Prototype) * MIT Licensed. */ -// Inspired by base2 and Prototype +(function(global) { + "use strict"; + var fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/; -; /* otherwise causes a concat bug? */ - -(function(){ - var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/; // The base Class implementation (does nothing) - this.Class = function(){}; - - // Create a new Class that inherits from this class - Class.extend = function(prop) { - var _super = this.prototype; - - // Instantiate a base class (but only create the instance, - // don't run the init constructor) - initializing = true; - var prototype = new this(); - initializing = false; - - // Copy the properties over onto the new prototype - for (var name in prop) { - // Check if we're overwriting an existing function - prototype[name] = typeof prop[name] == "function" && - typeof _super[name] == "function" && fnTest.test(prop[name]) ? - (function(name, fn){ - return function() { - var tmp = this._super; - - // Add a new ._super() method that is the same method - // but on the super-class - this._super = _super[name]; - - // The method only need to be bound temporarily, so we - // remove it when we're done executing - var ret = fn.apply(this, arguments); - this._super = tmp; - - return ret; - }; - })(name, prop[name]) : - prop[name]; - } - - // The dummy class constructor - function Class() { - // All construction is actually done in the init method - this._type = "instance"; - if ( !initializing && this.init ) - this.init.apply(this, arguments); - } - - // Populate our constructed prototype object - Class.prototype = prototype; - Class._type = "class"; - - // Enforce the constructor to be what we expect - Class.prototype.constructor = Class; + function Class(){} - // And make this class extendable - Class.extend = arguments.callee; - - return Class; + // Create a new Class that inherits from this class + Class.extend = function(props) { + var _super = this.prototype; + + // Set up the prototype to inherit from the base class + // (but without running the init constructor) + var proto = Object.create(_super); + + // Copy the properties over onto the new prototype + for (var name in props) { + // Check if we're overwriting an existing function + proto[name] = typeof props[name] === "function" && + typeof _super[name] == "function" && fnTest.test(props[name]) + ? (function(name, fn){ + return function() { + var tmp = this._super; + + // Add a new ._super() method that is the same method + // but on the super-class + this._super = _super[name]; + + // The method only need to be bound temporarily, so we + // remove it when we're done executing + var ret = fn.apply(this, arguments); + this._super = tmp; + + return ret; + }; + })(name, props[name]) + : props[name]; + } + + // The new constructor + var newClass = typeof proto.init === "function" + ? proto.hasOwnProperty("init") + ? proto.init // All construction is actually done in the init method + : function SubClass(){ _super.init.apply(this, arguments); } + : function EmptyClass(){}; + + // Populate our constructed prototype object + newClass.prototype = proto; + + // Enforce the constructor to be what we expect + proto.constructor = newClass; + + // And make this class extendable + newClass.extend = Class.extend; + + return newClass; }; -})(); + + // export + global.Class = Class; + })(this); \ No newline at end of file diff --git a/frappe/public/js/frappe/desk.js b/frappe/public/js/frappe/desk.js index f6b99434a6..63d39712d6 100644 --- a/frappe/public/js/frappe/desk.js +++ b/frappe/public/js/frappe/desk.js @@ -1,5 +1,6 @@ // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // MIT License. See license.txt +/* eslint-disable no-console */ frappe.start_app = function() { if(!frappe.Application) @@ -7,7 +8,7 @@ frappe.start_app = function() { frappe.assets.check(); frappe.provide('frappe.app'); frappe.app = new frappe.Application(); -} +}; $(document).ready(function() { if(!frappe.utils.supportsES6) { @@ -35,7 +36,7 @@ frappe.Application = Class.extend({ this.startup(); }, startup: function() { - frappe.socketio.init() + frappe.socketio.init(); frappe.model.init(); if(frappe.boot.status==='failed') { @@ -43,7 +44,7 @@ frappe.Application = Class.extend({ message: frappe.boot.error, title: __('Session Start Failed'), indicator: 'red', - }) + }); throw 'boot failed'; } @@ -109,20 +110,20 @@ frappe.Application = Class.extend({ var email_list = frappe.sys_defaults.email_user_password.split(','); for (var u in email_list) { if (email_list[u]===frappe.user.name){ - this.set_password(email_list[u]) + this.set_password(email_list[u]); } } } }, - set_password: function (user) { - var me=this + set_password: function(user) { + var me=this; frappe.call({ method: 'frappe.core.doctype.user.user.get_email_awaiting', args: { "user": user }, - callback: function (email_account) { + callback: function(email_account) { email_account = email_account["message"]; if (email_account) { var i = 0; @@ -135,7 +136,7 @@ frappe.Application = Class.extend({ }, email_password_prompt: function(email_account,user,i) { - var me = this + var me = this; var d = new frappe.ui.Dialog({ title: __('Email Account setup please enter your password for: '+email_account[i]["email_id"]), fields: [ @@ -160,7 +161,7 @@ frappe.Application = Class.extend({ "fieldname": "checking" }] }); - s.fields_dict.checking.$wrapper.html('') + s.fields_dict.checking.$wrapper.html(''); s.show(); frappe.call({ method: 'frappe.core.doctype.user.user.set_email_password', @@ -169,21 +170,16 @@ frappe.Application = Class.extend({ "user": user, "password": d.get_value("password") }, - callback: function (passed) - { + callback: function(passed) { s.hide(); d.hide();//hide waiting indication - if (!passed["message"]) - { + if (!passed["message"]) { frappe.show_alert("Login Failed please try again", 5); - me.email_password_prompt(email_account, user, i) - } - else - { - if (i + 1 < email_account.length) - { + me.email_password_prompt(email_account, user, i); + } else { + if (i + 1 < email_account.length) { i = i + 1; - me.email_password_prompt(email_account, user, i) + me.email_password_prompt(email_account, user, i); } } @@ -195,7 +191,9 @@ frappe.Application = Class.extend({ load_bootinfo: function() { if(frappe.boot) { frappe.modules = {}; - frappe.boot.desktop_icons.forEach(function(m) { frappe.modules[m.module_name]=m; }); + frappe.boot.desktop_icons.forEach(function(m) { + frappe.modules[m.module_name]=m; + }); frappe.model.sync(frappe.boot.docs); $.extend(frappe._messages, frappe.boot.__messages); this.check_metadata_cache_status(); @@ -234,7 +232,7 @@ frappe.Application = Class.extend({ // refresh notifications if user is back after sometime $(document).on("session_alive", function() { me.refresh_notifications(); - }) + }); }, refresh_notifications: function() { @@ -377,7 +375,7 @@ frappe.Application = Class.extend({ } me.redirect_to_login(); } - }) + }); }, handle_session_expired: function() { if(!frappe.app.session_expired_dialog) { @@ -439,7 +437,7 @@ frappe.Application = Class.extend({ }, trigger_primary_action: function() { - if(cur_dialog && cur_dialog.display) { + if(window.cur_dialog && cur_dialog.display) { // trigger primary cur_dialog.get_primary_btn().trigger("click"); } else if(cur_frm && cur_frm.page.btn_primary.is(':visible')) { @@ -449,13 +447,13 @@ frappe.Application = Class.extend({ } }, - set_rtl: function () { + set_rtl: function() { if (["ar", "he", "fa"].indexOf(frappe.boot.lang) >= 0) { var ls = document.createElement('link'); ls.rel="stylesheet"; ls.href= "assets/css/frappe-rtl.css"; document.getElementsByTagName('head')[0].appendChild(ls); - $('body').addClass('frappe-rtl') + $('body').addClass('frappe-rtl'); } }, @@ -509,9 +507,9 @@ frappe.Application = Class.extend({ // next note me.show_notes(); - } + }; } - }) + }); } }, }); @@ -567,17 +565,17 @@ frappe.get_desktop_icons = function(show_hidden, show_global) { var out = []; var add_to_out = function(module) { - var module = frappe.get_module(module.module_name, module); + module = frappe.get_module(module.module_name, module); module.app_icon = frappe.ui.app_icon.get_html(module); out.push(module); - } + }; var show_module = function(m) { var out = true; if(m.type==="page") { out = m.link in frappe.boot.page_info; } else if(m._report) { - out = m._report in frappe.boot.user.all_reports + out = m._report in frappe.boot.user.all_reports; } else if(m._doctype) { //out = frappe.model.can_read(m._doctype); out = frappe.boot.user.can_read.includes(m._doctype); @@ -588,7 +586,7 @@ frappe.get_desktop_icons = function(show_hidden, show_global) { } else if(m.module_name==='Setup' && frappe.user.has_role('System Manager')) { out = true; } else { - out = frappe.boot.user.allow_modules.indexOf(m.module_name) !== -1 + out = frappe.boot.user.allow_modules.indexOf(m.module_name) !== -1; } } if(m.hidden && !show_hidden) { @@ -598,22 +596,23 @@ frappe.get_desktop_icons = function(show_hidden, show_global) { out = false; } return out; - } + }; + let m; for (var i=0, l=frappe.boot.desktop_icons.length; i < l; i++) { - var m = frappe.boot.desktop_icons[i]; + m = frappe.boot.desktop_icons[i]; if ((['Setup', 'Core'].indexOf(m.module_name) === -1) && show_module(m)) { add_to_out(m); } } if(frappe.user_roles.includes('System Manager')) { - var m = frappe.get_module('Setup'); + m = frappe.get_module('Setup'); if(show_module(m)) add_to_out(m); } if(frappe.user_roles.includes('Administrator')) { - var m = frappe.get_module('Core'); + m = frappe.get_module('Core'); if(show_module(m)) add_to_out(m); } @@ -636,4 +635,4 @@ frappe.add_to_desktop = function(label, doctype, report) { } } }); -} +}; diff --git a/frappe/public/js/frappe/list/list_factory.js b/frappe/public/js/frappe/list/list_factory.js index 921be5c568..453b96a316 100644 --- a/frappe/public/js/frappe/list/list_factory.js +++ b/frappe/public/js/frappe/list/list_factory.js @@ -3,7 +3,7 @@ frappe.provide('frappe.views.list_view'); -cur_list = null; +window.cur_list = null; frappe.views.ListFactory = frappe.views.Factory.extend({ make: function (route) { var me = this; @@ -89,7 +89,7 @@ frappe.views.ListFactory = frappe.views.Factory.extend({ cur_list = frappe.views.list_view[page_name]; if (cur_list && cur_list.doctype !== route[1]) { // changing... - cur_list = null; + window.cur_list = null; } } }); diff --git a/frappe/public/js/frappe/misc/common.js b/frappe/public/js/frappe/misc/common.js index 771c468593..989dc6fb76 100644 --- a/frappe/public/js/frappe/misc/common.js +++ b/frappe/public/js/frappe/misc/common.js @@ -94,7 +94,7 @@ frappe.get_gravatar = function(email_id, size = 0) { // string commons -function repl(s, dict) { +window.repl =function repl(s, dict) { if(s==null)return ''; for(var key in dict) { s = s.split("%("+key+")s").join(dict[key]); @@ -102,15 +102,15 @@ function repl(s, dict) { return s; } -function replace_all(s, t1, t2) { +window.replace_all = function(s, t1, t2) { return s.split(t1).join(t2); } -function strip_html(txt) { +window.strip_html = function(txt) { return txt.replace(/<[^>]*>/g, ""); } -var strip = function(s, chars) { +window.strip = function(s, chars) { if (s) { var s= lstrip(s, chars) s = rstrip(s, chars); @@ -118,7 +118,7 @@ var strip = function(s, chars) { } } -var lstrip = function(s, chars) { +window.lstrip = function lstrip(s, chars) { if(!chars) chars = ['\n', '\t', ' ']; // strip left var first_char = s.substr(0,1); @@ -129,7 +129,7 @@ var lstrip = function(s, chars) { return s; } -var rstrip = function(s, chars) { +window.rstrip = function(s, chars) { if(!chars) chars = ['\n', '\t', ' ']; var last_char = s.substr(s.length-1); while(in_list(chars, last_char)) { @@ -139,13 +139,11 @@ var rstrip = function(s, chars) { return s; } -function getCookie(name) { - return getCookies()[name]; +frappe.get_cookie = function getCookie(name) { + return frappe.get_cookies()[name]; } -frappe.get_cookie = getCookie; - -function getCookies() { +frappe.get_cookies = function getCookies() { var c = document.cookie, v = 0, cookies = {}; if (document.cookie.match(/^\s*\$Version=(?:"1"|1);\s*(.*)/)) { c = RegExp.$1; diff --git a/frappe/public/js/frappe/misc/number_format.js b/frappe/public/js/frappe/misc/number_format.js index df4925d4fd..ab415a8727 100644 --- a/frappe/public/js/frappe/misc/number_format.js +++ b/frappe/public/js/frappe/misc/number_format.js @@ -240,3 +240,19 @@ function round_based_on_smallest_currency_fraction(value, currency, precision) { } return value; } + +Object.assign(window, { + flt, + cint, + strip_number_groups, + format_currency, + get_currency_symbol, + get_number_format, + get_number_format_info, + _round, + roundNumber, + precision, + remainder, + round_based_on_smallest_currency_fraction, + in_list +}); \ No newline at end of file diff --git a/frappe/public/js/frappe/misc/pretty_date.js b/frappe/public/js/frappe/misc/pretty_date.js index faeb22f01b..fc89e2dad6 100644 --- a/frappe/public/js/frappe/misc/pretty_date.js +++ b/frappe/public/js/frappe/misc/pretty_date.js @@ -5,10 +5,11 @@ function prettyDate(time, mini) { time = new Date(); } if (moment) { + let ret; if (frappe.sys_defaults && frappe.sys_defaults.time_zone) { - var ret = moment.tz(time, frappe.sys_defaults.time_zone).locale(frappe.boot.lang).fromNow(mini); + ret = moment.tz(time, frappe.sys_defaults.time_zone).locale(frappe.boot.lang).fromNow(mini); } else { - var ret = moment(time).locale(frappe.boot.lang).fromNow(mini); + ret = moment(time).locale(frappe.boot.lang).fromNow(mini); } if (mini) { if (ret === moment().locale(frappe.boot.lang).fromNow(mini)) { @@ -30,7 +31,7 @@ function prettyDate(time, mini) { } return ret; } else { - if (!time) return '' + if (!time) return ''; var date = time; if (typeof (time) == "string") date = new Date((time || "").replace(/-/g, "/").replace(/[TZ]/g, " ").replace(/\.[0-9]*/, "")); @@ -58,7 +59,7 @@ function prettyDate(time, mini) { } -var comment_when = function (datetime, mini) { +window.comment_when = function(datetime, mini) { var timestamp = frappe.datetime.str_to_user ? frappe.datetime.str_to_user(datetime) : datetime; return ' 1) { - var query_params = get_query_params(parts[1]); + var query_params = frappe.utils.get_query_params(parts[1]); frappe.route_options = $.extend(frappe.route_options || {}, query_params); } @@ -133,6 +133,7 @@ frappe.set_route = function() { frappe.route_options = a; return null; } else { + a = String(a); if (a && a.match(/[%'"]/)) { // if special chars, then encode a = encodeURIComponent(a); @@ -170,7 +171,7 @@ $(window).on('hashchange', function() { return; // hide open dialog - if(cur_dialog && cur_dialog.hide_on_page_refresh) { + if(window.cur_dialog && cur_dialog.hide_on_page_refresh) { cur_dialog.hide(); } diff --git a/frappe/public/js/frappe/ui/dialog.js b/frappe/public/js/frappe/ui/dialog.js index 7c80df76b0..8d06058579 100644 --- a/frappe/public/js/frappe/ui/dialog.js +++ b/frappe/public/js/frappe/ui/dialog.js @@ -3,7 +3,7 @@ frappe.provide('frappe.ui'); -var cur_dialog; +window.cur_dialog = null; frappe.ui.open_dialogs = []; frappe.ui.Dialog = frappe.ui.FieldGroup.extend({ @@ -49,9 +49,9 @@ frappe.ui.Dialog = frappe.ui.FieldGroup.extend({ if(frappe.ui.open_dialogs[frappe.ui.open_dialogs.length-1]===me) { frappe.ui.open_dialogs.pop(); if(frappe.ui.open_dialogs.length) { - cur_dialog = frappe.ui.open_dialogs[frappe.ui.open_dialogs.length-1]; + window.cur_dialog = frappe.ui.open_dialogs[frappe.ui.open_dialogs.length-1]; } else { - cur_dialog = null; + window.cur_dialog = null; } } me.onhide && me.onhide(); @@ -60,7 +60,7 @@ frappe.ui.Dialog = frappe.ui.FieldGroup.extend({ .on("shown.bs.modal", function() { // focus on first input me.display = true; - cur_dialog = me; + window.cur_dialog = me; frappe.ui.open_dialogs.push(me); me.focus_on_first_input(); me.on_page_show && me.on_page_show(); @@ -100,7 +100,6 @@ frappe.ui.Dialog = frappe.ui.FieldGroup.extend({ this.get_primary_btn().removeClass('disabled'); }, make_head: function() { - var me = this; this.set_title(this.title); }, set_title: function(t) { @@ -109,15 +108,15 @@ frappe.ui.Dialog = frappe.ui.FieldGroup.extend({ show: function() { // show it if ( this.animate ) { - this.$wrapper.addClass('fade') + this.$wrapper.addClass('fade'); } else { - this.$wrapper.removeClass('fade') + this.$wrapper.removeClass('fade'); } this.$wrapper.modal("show"); this.primary_action_fulfilled = false; this.is_visible = true; }, - hide: function(from_event) { + hide: function() { this.$wrapper.modal("hide"); this.is_visible = false; }, diff --git a/frappe/public/js/frappe/ui/keyboard.js b/frappe/public/js/frappe/ui/keyboard.js index aa042e7a7a..b5d8d3c501 100644 --- a/frappe/public/js/frappe/ui/keyboard.js +++ b/frappe/public/js/frappe/ui/keyboard.js @@ -69,7 +69,7 @@ frappe.ui.keys.on('esc', function(e) { }); frappe.ui.keys.on('enter', function(e) { - if(cur_dialog && cur_dialog.confirm_dialog) { + if(window.cur_dialog && cur_dialog.confirm_dialog) { cur_dialog.get_primary_btn().trigger('click'); } }); diff --git a/frappe/public/js/frappe/views/container.js b/frappe/public/js/frappe/views/container.js index 72a74d5564..30f9a147db 100644 --- a/frappe/public/js/frappe/views/container.js +++ b/frappe/public/js/frappe/views/container.js @@ -5,7 +5,7 @@ frappe.provide('frappe.pages'); frappe.provide('frappe.views'); -var cur_page = null; +window.cur_page = null; frappe.views.Container = Class.extend({ _intro: "Container contains pages inside `#container` and manages \ page creation, switching", @@ -59,7 +59,7 @@ frappe.views.Container = Class.extend({ } // hide dialog - if(cur_dialog && cur_dialog.display && !cur_dialog.keep_open) { + if(window.cur_dialog && cur_dialog.display && !cur_dialog.keep_open) { cur_dialog.hide(); } diff --git a/frappe/public/js/frappe/views/pageview.js b/frappe/public/js/frappe/views/pageview.js index 7f3f42b4ce..87b78185bd 100644 --- a/frappe/public/js/frappe/views/pageview.js +++ b/frappe/public/js/frappe/views/pageview.js @@ -52,10 +52,10 @@ frappe.views.pageview = { }); }); } -} +}; frappe.views.Page = Class.extend({ - init: function(name, wrapper) { + init: function(name) { this.name = name; var me = this; // web home page @@ -85,7 +85,7 @@ frappe.views.Page = Class.extend({ // set events $(this.wrapper).on('show', function() { - cur_frm = null; + window.cur_frm = null; me.trigger_page_event('on_page_show'); me.trigger_page_event('refresh'); }); @@ -96,7 +96,7 @@ frappe.views.Page = Class.extend({ me.wrapper[eventname](me.wrapper); } } -}) +}); frappe.show_not_found = function(page_name) { frappe.show_message_page({ @@ -104,7 +104,7 @@ frappe.show_not_found = function(page_name) { message: __("Sorry! I could not find what you were looking for."), img: "/assets/frappe/images/ui/bubble-tea-sorry.svg" }); -} +}; frappe.show_not_permitted = function(page_name) { frappe.show_message_page({ @@ -113,7 +113,7 @@ frappe.show_not_permitted = function(page_name) { img: "/assets/frappe/images/ui/bubble-tea-sorry.svg", // icon: "octicon octicon-circle-slash" }); -} +}; frappe.show_message_page = function(opts) { // opts can include `page_name`, `message`, `icon` or `img` @@ -136,11 +136,11 @@ frappe.show_message_page = function(opts) { %(home)s\ \ ', { - img: opts.img || "", - message: opts.message || "", - home: __("Home") - }) + img: opts.img || "", + message: opts.message || "", + home: __("Home") + }) ); frappe.container.change_to(opts.page_name); -} +}; diff --git a/frappe/public/js/frappe/views/treeview.js b/frappe/public/js/frappe/views/treeview.js index 6b5d6444da..fcd4ce6e84 100644 --- a/frappe/public/js/frappe/views/treeview.js +++ b/frappe/public/js/frappe/views/treeview.js @@ -3,7 +3,7 @@ frappe.provide("frappe.treeview_settings"); frappe.provide('frappe.views.trees'); -cur_tree = null; +window.cur_tree = null; frappe.views.TreeFactory = frappe.views.Factory.extend({ make: function(route) { diff --git a/frappe/public/js/legacy/client_script_helpers.js b/frappe/public/js/legacy/client_script_helpers.js index 930479c03e..40e2f34e11 100644 --- a/frappe/public/js/legacy/client_script_helpers.js +++ b/frappe/public/js/legacy/client_script_helpers.js @@ -1,33 +1,34 @@ // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // MIT License. See license.txt +/* eslint-disable no-console */ window.get_server_fields = function(method, arg, table_field, doc, dt, dn, allow_edit, call_back) { console.warn("This function 'get_server_fields' has been deprecated and will be removed soon."); frappe.dom.freeze(); if($.isPlainObject(arg)) arg = JSON.stringify(arg); return $c('runserverobj', {'method': method, 'docs': JSON.stringify(doc), 'arg': arg }, - function(r, rt) { - frappe.dom.unfreeze(); - if (r.message) { - var d = locals[dt][dn]; - var field_dict = r.message; - for(var key in field_dict) { - d[key] = field_dict[key]; - if (table_field) - refresh_field(key, d.name, table_field); - else - refresh_field(key); + function(r) { + frappe.dom.unfreeze(); + if (r.message) { + var d = locals[dt][dn]; + var field_dict = r.message; + for(var key in field_dict) { + d[key] = field_dict[key]; + if (table_field) + refresh_field(key, d.name, table_field); + else + refresh_field(key); + } } - } - if(call_back){ - doc = locals[doc.doctype][doc.name]; - call_back(doc, dt, dn); - } - }); -} + if(call_back){ + doc = locals[doc.doctype][doc.name]; + call_back(doc, dt, dn); + } + }); +}; -window.set_multiple = function (dt, dn, dict, table_field) { +window.set_multiple = function(dt, dn, dict, table_field) { var d = locals[dt][dn]; for(var key in dict) { d[key] = dict[key]; @@ -36,16 +37,16 @@ window.set_multiple = function (dt, dn, dict, table_field) { else refresh_field(key); } -} +}; -window.refresh_many = function (flist, dn, table_field) { +window.refresh_many = function(flist, dn, table_field) { for(var i in flist) { if (table_field) refresh_field(flist[i], dn, table_field); else refresh_field(flist[i]); } -} +}; window.set_field_tip = function(n,txt) { var df = frappe.meta.get_docfield(cur_frm.doctype, n, cur_frm.docname); @@ -53,13 +54,13 @@ window.set_field_tip = function(n,txt) { if(cur_frm && cur_frm.fields_dict) { if(cur_frm.fields_dict[n]) - cur_frm.fields_dict[n].comment_area.innerHTML = replace_newlines(txt); + cur_frm.fields_dict[n].comment_area.innerHTML = window.replace_newlines(txt); else console.log('[set_field_tip] Unable to set field tip: ' + n); } -} +}; -refresh_field = function(n, docname, table_field) { +window.refresh_field = function(n, docname, table_field) { // multiple if(typeof n==typeof []) refresh_many(n, docname, table_field); @@ -78,50 +79,53 @@ refresh_field = function(n, docname, table_field) { } } } else if(cur_frm) { - cur_frm.refresh_field(n) + cur_frm.refresh_field(n); } -} +}; window.set_field_options = function(n, txt) { - cur_frm.set_df_property(n, 'options', txt) -} + cur_frm.set_df_property(n, 'options', txt); +}; window.set_field_permlevel = function(n, level) { - cur_frm.set_df_property(n, 'permlevel', level) -} + cur_frm.set_df_property(n, 'permlevel', level); +}; -toggle_field = function(n, hidden) { +window.toggle_field = function(n, hidden) { var df = frappe.meta.get_docfield(cur_frm.doctype, n, cur_frm.docname); if(df) { df.hidden = hidden; refresh_field(n); - } - else { + } else { console.log((hidden ? "hide_field" : "unhide_field") + " cannot find field " + n); } -} +}; -hide_field = function(n) { +window.hide_field = function(n) { if(cur_frm) { if(n.substr) toggle_field(n, 1); - else { for(var i in n) toggle_field(n[i], 1) } + else { + for(var i in n) toggle_field(n[i], 1); + } } -} +}; -unhide_field = function(n) { +window.unhide_field = function(n) { if(cur_frm) { if(n.substr) toggle_field(n, 0); - else { for(var i in n) toggle_field(n[i], 0) } + else { + for(var i in n) toggle_field(n[i], 0); + } } -} +}; -get_field_obj = function(fn) { +window.get_field_obj = function(fn) { return cur_frm.fields_dict[fn]; -} +}; _f.Frm.prototype.get_doc = function() { return locals[this.doctype][this.docname]; -} +}; _f.Frm.prototype.set_currency_labels = function(fields_list, currency, parentfield) { // To set the currency in the label @@ -129,13 +133,13 @@ _f.Frm.prototype.set_currency_labels = function(fields_list, currency, parentfie var me = this; var doctype = parentfield ? this.fields_dict[parentfield].grid.doctype : this.doc.doctype; - var field_label_map = {} - var grid_field_label_map = {} + var field_label_map = {}; + var grid_field_label_map = {}; $.each(fields_list, function(i, fname) { var docfield = frappe.meta.docfield_map[doctype][fname]; if(docfield) { - var label = __(docfield.label || "").replace(/\([^\)]*\)/g, ""); + var label = __(docfield.label || "").replace(/\([^\)]*\)/g, ""); // eslint-disable-line if(parentfield) { grid_field_label_map[doctype + "-" + fname] = label.trim() + " (" + __(currency) + ")"; @@ -154,7 +158,7 @@ _f.Frm.prototype.set_currency_labels = function(fields_list, currency, parentfie var df = frappe.meta.get_docfield(fname[0], fname[1], me.doc.name); if(df) df.label = label; }); -} +}; _f.Frm.prototype.field_map = function(fnames, fn) { if(typeof fnames==='string') { @@ -172,7 +176,7 @@ _f.Frm.prototype.field_map = function(fnames, fn) { this.refresh_field(fieldname); } } -} +}; _f.Frm.prototype.get_docfield = function(fieldname1, fieldname2) { if(fieldname2) { @@ -183,45 +187,51 @@ _f.Frm.prototype.get_docfield = function(fieldname1, fieldname2) { // for parent return frappe.meta.get_docfield(this.doctype, fieldname1, this.docname); } -} +}; _f.Frm.prototype.set_df_property = function(fieldname, property, value, docname, table_field) { + var df; if (!docname && !table_field){ - var df = this.get_docfield(fieldname); + df = this.get_docfield(fieldname); } else { var grid = this.fields_dict[table_field].grid, fname = frappe.utils.filter_dict(grid.docfields, {'fieldname': fieldname}); if (fname && fname.length) - var df = frappe.meta.get_docfield(fname[0].parent, fieldname, docname); + df = frappe.meta.get_docfield(fname[0].parent, fieldname, docname); } if(df && df[property] != value) { df[property] = value; refresh_field(fieldname, table_field); } -} +}; _f.Frm.prototype.toggle_enable = function(fnames, enable) { this.field_map(fnames, function(field) { - field.read_only = enable ? 0 : 1; }); -} + field.read_only = enable ? 0 : 1; + }); +}; _f.Frm.prototype.toggle_reqd = function(fnames, mandatory) { - this.field_map(fnames, function(field) { field.reqd = mandatory ? true : false; }); -} + this.field_map(fnames, function(field) { + field.reqd = mandatory ? true : false; + }); +}; _f.Frm.prototype.toggle_display = function(fnames, show) { - this.field_map(fnames, function(field) { field.hidden = show ? 0 : 1; }); -} + this.field_map(fnames, function(field) { + field.hidden = show ? 0 : 1; + }); +}; _f.Frm.prototype.call_server = function(method, args, callback) { return $c_obj(this.doc, method, args, callback); -} +}; _f.Frm.prototype.get_files = function() { return this.attachments ? frappe.utils.sort(this.attachments.get_attachments(), "file_name", "string") : [] ; -} +}; _f.Frm.prototype.set_query = function(fieldname, opt1, opt2) { if(opt2) { @@ -235,15 +245,15 @@ _f.Frm.prototype.set_query = function(fieldname, opt1, opt2) { this.fields_dict[fieldname].get_query = opt1; } } -} +}; _f.Frm.prototype.set_value_if_missing = function(field, value) { return this.set_value(field, value, true); -} +}; _f.Frm.prototype.clear_table = function(fieldname) { frappe.model.clear_table(this.doc, fieldname); -} +}; _f.Frm.prototype.add_child = function(fieldname, values) { var doc = frappe.model.add_child(this.doc, frappe.meta.get_docfield(this.doctype, fieldname).options, fieldname); @@ -261,7 +271,7 @@ _f.Frm.prototype.add_child = function(fieldname, values) { $.extend(doc, d); } return doc; -} +}; _f.Frm.prototype.set_value = function(field, value, if_missing) { var me = this; @@ -290,10 +300,10 @@ _f.Frm.prototype.set_value = function(field, value, if_missing) { frappe.msgprint(__("Field {0} not found.",[f])); throw "frm.set_value"; } - } + }; if(typeof field=="string") { - return _set(field, value) + return _set(field, value); } else if($.isPlainObject(field)) { let tasks = []; for (let f in field) { @@ -304,7 +314,7 @@ _f.Frm.prototype.set_value = function(field, value, if_missing) { } return frappe.run_serially(tasks); } -} +}; _f.Frm.prototype.call = function(opts, args, callback) { var me = this; @@ -341,18 +351,18 @@ _f.Frm.prototype.call = function(opts, args, callback) { } } opts.original_callback && opts.original_callback(r); - } + }; } else { opts.original_callback = opts.callback; opts.callback = function(r) { if(!r.exc) me.refresh_fields(); opts.original_callback && opts.original_callback(r); - } + }; } return frappe.call(opts); -} +}; _f.Frm.prototype.get_field = function(field) { return this.fields_dict[field]; @@ -367,7 +377,7 @@ _f.Frm.prototype.set_read_only = function() { perm[p.permlevel || 0] = {read:1, print:1, cancel:1}; } this.perm = perm; -} +}; _f.Frm.prototype.trigger = function(event) { return this.script_manager.trigger(event); @@ -377,15 +387,15 @@ _f.Frm.prototype.get_formatted = function(fieldname) { return frappe.format(this.doc[fieldname], frappe.meta.get_docfield(this.doctype, fieldname, this.docname), {no_icon:true}, this.doc); -} +}; _f.Frm.prototype.open_grid_row = function() { return frappe.ui.form.get_open_grid_form(); -} +}; _f.Frm.prototype.is_new = function() { return this.doc.__islocal; -} +}; _f.Frm.prototype.get_title = function() { if(this.meta.title_field) { @@ -393,7 +403,7 @@ _f.Frm.prototype.get_title = function() { } else { return this.doc.name; } -} +}; _f.Frm.prototype.get_selected = function() { // returns list of children that are selected. returns [parentfield, name] for each @@ -405,7 +415,7 @@ _f.Frm.prototype.get_selected = function() { } }); return selected; -} +}; _f.Frm.prototype.has_mapper = function() { // hackalert! @@ -415,7 +425,7 @@ _f.Frm.prototype.has_mapper = function() { true: false; } return this._has_mapper; -} +}; _f.Frm.prototype.set_indicator_formatter = function(fieldname, get_color, get_text) { // get doctype from parent @@ -430,7 +440,7 @@ _f.Frm.prototype.set_indicator_formatter = function(fieldname, get_color, get_te } else { return true; } - }) + }); } frappe.meta.docfield_map[doctype][fieldname].formatter = @@ -446,7 +456,7 @@ _f.Frm.prototype.set_indicator_formatter = function(fieldname, get_color, get_te return ''; } }; -} +}; _f.Frm.prototype.can_create = function(doctype) { // return true or false if the user can make a particlar doctype @@ -472,7 +482,7 @@ _f.Frm.prototype.can_create = function(doctype) { return true; } } -} +}; _f.Frm.prototype.make_new = function(doctype) { // make new doctype from the current form @@ -498,7 +508,7 @@ _f.Frm.prototype.make_new = function(doctype) { // frappe.set_route('Form', doctype, new_doc.name); }); } -} +}; _f.Frm.prototype.update_in_all_rows = function(table_fieldname, fieldname, value) { // update the child value in all tables where it is missing @@ -508,4 +518,4 @@ _f.Frm.prototype.update_in_all_rows = function(table_fieldname, fieldname, value if(!cl[i][fieldname]) cl[i][fieldname] = value; } refresh_field("items"); -} +}; diff --git a/frappe/public/js/legacy/datatype.js b/frappe/public/js/legacy/datatype.js index eb6f6b6760..a3d2258a67 100644 --- a/frappe/public/js/legacy/datatype.js +++ b/frappe/public/js/legacy/datatype.js @@ -108,3 +108,22 @@ function remove_from_list(list, val) { } return list } + +Object.assign(window, { + fmt_money, + toTitle, + is_null, + set_value_in, + copy_dict, + replace_newlines, + validate_email, + validate_spl_chars, + cstr, + nth, + esc_quotes, + has_words, + has_common, + add_lists, + docstring, + remove_from_list, +}); \ No newline at end of file diff --git a/frappe/public/js/legacy/globals.js b/frappe/public/js/legacy/globals.js index 46a4a4327e..8e03a9ecea 100644 --- a/frappe/public/js/legacy/globals.js +++ b/frappe/public/js/legacy/globals.js @@ -18,10 +18,10 @@ frappe.provide("frappe.listview_parent_route"); frappe.settings.no_history = 1; // constants -var NEWLINE = '\n'; -var TAB = 9; -var UP_ARROW = 38; -var DOWN_ARROW = 40; +window.NEWLINE = '\n'; +window.TAB = 9; +window.UP_ARROW = 38; +window.DOWN_ARROW = 40; // proxy for user globals defined in desk.js @@ -29,10 +29,10 @@ var DOWN_ARROW = 40; // ============ // form -var _f = {}; -var _p = {}; -var _r = {}; +window._f = {}; +window._p = {}; +window._r = {}; // API globals -var frms={}; -var cur_frm=null; +window.frms={}; +window.cur_frm=null; diff --git a/frappe/public/js/legacy/handler.js b/frappe/public/js/legacy/handler.js index c35a21fdd0..b8bbbefbdf 100644 --- a/frappe/public/js/legacy/handler.js +++ b/frappe/public/js/legacy/handler.js @@ -1,5 +1,6 @@ // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // MIT License. See license.txt +/* eslint-disable no-console */ function $c(command, args, callback, error, no_spinner, freeze_msg, btn) { console.warn("This function '$c' has been deprecated and will be removed soon."); @@ -11,7 +12,7 @@ function $c(command, args, callback, error, no_spinner, freeze_msg, btn) { btn: btn, freeze: freeze_msg, show_spinner: !no_spinner - }) + }); } // For calling an object @@ -29,7 +30,7 @@ function $c_obj(doc, method, arg, callback, no_spinner, freeze_msg, btn) { if(typeof doc=='string') { args.doctype = doc; } else { - args.docs = doc + args.docs = doc; } return frappe.request.call({ @@ -47,7 +48,7 @@ function $c_obj_csv(doc, method, arg) { console.warn("This function '$c_obj_csv' has been deprecated and will be removed soon."); // single - var args = {} + var args = {}; args.cmd = 'runserverobj'; args.as_csv = 1; args.method = method; @@ -62,7 +63,7 @@ function $c_obj_csv(doc, method, arg) { open_url_post(frappe.request.url, args); } -function open_url_post(URL, PARAMS, new_window) { +window.open_url_post = function open_url_post(URL, PARAMS, new_window) { if (window.cordova) { let url = URL + 'api/method/' + PARAMS.cmd + frappe.utils.make_query_string(PARAMS, false); window.location.href = url; @@ -70,7 +71,7 @@ function open_url_post(URL, PARAMS, new_window) { // call a url as POST _open_url_post(URL, PARAMS, new_window); } -} +}; function _open_url_post(URL, PARAMS, new_window) { var temp=document.createElement("form"); @@ -94,3 +95,7 @@ function _open_url_post(URL, PARAMS, new_window) { temp.submit(); return temp; } + +Object.assign(window, { + $c, $c_obj, $c_obj_csv +}); \ No newline at end of file diff --git a/frappe/public/js/legacy/layout.js b/frappe/public/js/legacy/layout.js index c68e0c916c..d8c279851b 100644 --- a/frappe/public/js/legacy/layout.js +++ b/frappe/public/js/legacy/layout.js @@ -14,7 +14,7 @@ + subrows */ -function Layout(parent, width) { +window.Layout = function Layout(parent, width) { if(parent&&parent.substr) { parent = $i(parent); } this.wrapper = $a(parent, 'div', '', {display:'none'}); diff --git a/frappe/public/js/lib/microtemplate.js b/frappe/public/js/lib/microtemplate.js index d1339f178c..6aa85c1947 100644 --- a/frappe/public/js/lib/microtemplate.js +++ b/frappe/public/js/lib/microtemplate.js @@ -39,7 +39,7 @@ frappe.template.compile = function(str, name) { // {% endif %} --> {% } %} str = str.replace(/{%\s?endfor\s?%}/g, "{% }; %}"); - fn_str = "var _p=[],print=function(){_p.push.apply(_p,arguments)};" + + var fn_str = "var _p=[],print=function(){_p.push.apply(_p,arguments)};" + // Introduce the data as local variables using with(){} "with(obj){\n_p.push('" + diff --git a/frappe/public/js/lib/slickgrid/slick-default-theme.css b/frappe/public/js/lib/slickgrid/slick-default-theme.css index c1e80502c5..572f184406 100644 --- a/frappe/public/js/lib/slickgrid/slick-default-theme.css +++ b/frappe/public/js/lib/slickgrid/slick-default-theme.css @@ -96,7 +96,7 @@ classes should alter those! .slick-row.loading { opacity: 0.5; - filter: alpha(opacity = 50); + /* filter: alpha(opacity = 50); */ } .slick-cell.invalid { diff --git a/frappe/public/js/lib/slickgrid/slick.grid.css b/frappe/public/js/lib/slickgrid/slick.grid.css index 6a416db1ef..440c1b89e4 100644 --- a/frappe/public/js/lib/slickgrid/slick.grid.css +++ b/frappe/public/js/lib/slickgrid/slick.grid.css @@ -138,7 +138,7 @@ classes should alter those! display: inline-block; background: blue; opacity: 0.15; - filter: alpha(opacity = 15); + /* filter: alpha(opacity = 15); */ cursor: move; } @@ -147,7 +147,7 @@ classes should alter those! height: 2px; background: blue; opacity: 0.7; - filter: alpha(opacity = 70); + /* filter: alpha(opacity = 70); */ } .slick-selection { diff --git a/frappe/templates/includes/comments/comments.html b/frappe/templates/includes/comments/comments.html index a5459229dc..7460b9d4a9 100644 --- a/frappe/templates/includes/comments/comments.html +++ b/frappe/templates/includes/comments/comments.html @@ -71,8 +71,8 @@ $("#comment-form").toggle(); var full_name = "", user_id = ""; if(frappe.is_user_logged_in()) { - full_name = getCookie("full_name"); - user_id = getCookie("user_id"); + full_name = frappe.get_cookie("full_name"); + user_id = frappe.get_cookie("user_id"); if(user_id != "Guest") { $("[name='comment_by']").val(user_id); $("[name='comment_by_fullname']").val(full_name); diff --git a/frappe/templates/includes/login/login.js b/frappe/templates/includes/login/login.js index c5639bacf0..c8d66d5875 100644 --- a/frappe/templates/includes/login/login.js +++ b/frappe/templates/includes/login/login.js @@ -33,7 +33,7 @@ login.bind_events = function() { var args = {}; args.cmd = "frappe.core.doctype.user.user.sign_up"; args.email = ($("#signup_email").val() || "").trim(); - args.redirect_to = get_url_arg("redirect-to") || ''; + args.redirect_to = frappe.utils.get_url_arg("redirect-to") || ''; args.full_name = ($("#signup_fullname").val() || "").trim(); if(!args.email || !valid_email(args.email) || !args.full_name) { login.set_indicator("{{ _("Valid email and name required") }}", 'red'); @@ -161,13 +161,13 @@ login.login_handlers = (function() { 200: function(data) { if(data.message == 'Logged In'){ login.set_indicator("{{ _("Success") }}", 'green'); - window.location.href = get_url_arg("redirect-to") || data.home_page; + window.location.href = frappe.utils.get_url_arg("redirect-to") || data.home_page; } else if(data.message=="No App") { login.set_indicator("{{ _("Success") }}", 'green'); if(localStorage) { var last_visited = localStorage.getItem("last_visited") - || get_url_arg("redirect-to"); + || frappe.utils.get_url_arg("redirect-to"); localStorage.removeItem("last_visited"); } diff --git a/frappe/templates/includes/search_box.html b/frappe/templates/includes/search_box.html index 0a1c51885e..079109a16a 100644 --- a/frappe/templates/includes/search_box.html +++ b/frappe/templates/includes/search_box.html @@ -14,8 +14,8 @@