diff --git a/.travis.yml b/.travis.yml index de8531b5d9..464256b1dd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,10 +6,15 @@ python: services: - mysql +before_install: + - "export DISPLAY=:99.0" + - "sh -e /etc/init.d/xvfb start" + install: - sudo apt-get purge -y mysql-common - wget https://raw.githubusercontent.com/frappe/bench/master/install_scripts/setup_frappe.sh - sudo bash setup_frappe.sh --skip-setup-bench --mysql-root-password travis + - sudo pip install --upgrade pip - sudo service redis-server start - rm $TRAVIS_BUILD_DIR/.git/shallow - cd ~/ && bench init frappe-bench --frappe-path $TRAVIS_BUILD_DIR @@ -23,7 +28,7 @@ script: - bench build-website - bench serve & - sleep 10 - - bench --verbose run-tests + - bench --verbose run-tests --driver Firefox before_script: - mysql -e 'create database test_frappe' diff --git a/frappe/__init__.py b/frappe/__init__.py index 8917faed7a..f5b5c29b64 100644 --- a/frappe/__init__.py +++ b/frappe/__init__.py @@ -116,6 +116,7 @@ def init(site, sites_path=None): local.module_app = None local.app_modules = None + local.system_settings = None local.user = None local.user_obj = None @@ -425,11 +426,19 @@ def has_website_permission(doctype, ptype="read", doc=None, user=None, verbose=F if not user: user = session.user - for method in (get_hooks("has_website_permission") or {}).get(doctype, []): - if not call(get_attr(method), doc=doc, ptype=ptype, user=user, verbose=verbose): - return False + hooks = (get_hooks("has_website_permission") or {}).get(doctype, []) + if hooks: + for method in hooks: + result = call(get_attr(method), doc=doc, ptype=ptype, user=user, verbose=verbose) + # if even a single permission check is Falsy + if not result: + return False - return True + # else it is Truthy + return True + + else: + return False def is_table(doctype): """Returns True if `istable` property (indicating child Table) is set for given DocType.""" @@ -529,9 +538,9 @@ def delete_doc_if_exists(doctype, name): if db.exists(doctype, name): delete_doc(doctype, name) -def reload_doctype(doctype): +def reload_doctype(doctype, force=False): """Reload DocType from model (`[module]/[doctype]/[name]/[name].json`) files.""" - reload_doc(scrub(db.get_value("DocType", doctype, "module")), "doctype", scrub(doctype)) + reload_doc(scrub(db.get_value("DocType", doctype, "module")), "doctype", scrub(doctype), force=force) def reload_doc(module, dt=None, dn=None, force=False): """Reload Document from model (`[module]/[doctype]/[name]/[name].json`) files. diff --git a/frappe/__version__.py b/frappe/__version__.py index 661ac4e319..3ef413303b 100644 --- a/frappe/__version__.py +++ b/frappe/__version__.py @@ -1,2 +1,2 @@ from __future__ import unicode_literals -__version__ = "5.0.9" +__version__ = "5.1.3" diff --git a/frappe/app.py b/frappe/app.py index 4a645fa746..d670cb8e56 100644 --- a/frappe/app.py +++ b/frappe/app.py @@ -70,6 +70,7 @@ def application(request): except Exception, e: http_status_code = getattr(e, "http_status_code", 500) + #print frappe.get_traceback() if (http_status_code==500 and isinstance(e, MySQLdb.OperationalError) diff --git a/frappe/auth.py b/frappe/auth.py index 4d6923d1bb..d58f22048e 100644 --- a/frappe/auth.py +++ b/frappe/auth.py @@ -57,14 +57,6 @@ class HTTPRequest: # run login triggers if frappe.form_dict.get('cmd')=='login': frappe.local.login_manager.run_trigger('on_session_creation') - self.clear_active_sessions() - - def clear_active_sessions(self): - if not frappe.conf.get("deny_multiple_sessions"): - return - - if frappe.session.user != "Guest": - clear_sessions(frappe.session.user, keep_current=True) def set_lang(self, lang_codes): @@ -90,7 +82,13 @@ class LoginManager: if frappe.local.form_dict.get('cmd')=='login' or frappe.local.request.path=="/api/method/login": self.login() else: - self.make_session(resume=True) + try: + self.make_session(resume=True) + self.set_user_info(resume=True) + except AttributeError: + self.user = "Guest" + self.make_session() + self.set_user_info() def login(self): # clear cache @@ -99,29 +97,34 @@ class LoginManager: self.post_login() def post_login(self): - self.info = frappe.db.get_value("User", self.user, - ["user_type", "first_name", "last_name", "user_image"], as_dict=1) - self.full_name = " ".join(filter(None, [self.info.first_name, self.info.last_name])) - self.user_type = self.info.user_type - self.run_trigger('on_login') self.validate_ip_address() self.validate_hour() self.make_session() self.set_user_info() - def set_user_info(self): + def set_user_info(self, resume=False): # set sid again frappe.local.cookie_manager.init_cookies() + self.info = frappe.db.get_value("User", self.user, + ["user_type", "first_name", "last_name", "user_image"], as_dict=1) + self.full_name = " ".join(filter(None, [self.info.first_name, + self.info.last_name])) + self.user_type = self.info.user_type + if self.info.user_type=="Website User": frappe.local.cookie_manager.set_cookie("system_user", "no") - frappe.local.response["message"] = "No App" + if not resume: + frappe.local.response["message"] = "No App" else: frappe.local.cookie_manager.set_cookie("system_user", "yes") - frappe.local.response['message'] = 'Logged In' + if not resume: + frappe.local.response['message'] = 'Logged In' + + if not resume: + frappe.response["full_name"] = self.full_name - frappe.response["full_name"] = self.full_name frappe.local.cookie_manager.set_cookie("full_name", self.full_name) frappe.local.cookie_manager.set_cookie("user_id", self.user) frappe.local.cookie_manager.set_cookie("user_image", self.info.user_image or "") @@ -134,6 +137,14 @@ class LoginManager: # reset user if changed to Guest self.user = frappe.local.session_obj.user frappe.local.session = frappe.local.session_obj.data + self.clear_active_sessions() + + def clear_active_sessions(self): + if not frappe.conf.get("deny_multiple_sessions"): + return + + if frappe.session.user != "Guest": + clear_sessions(frappe.session.user, keep_current=True) def authenticate(self, user=None, pwd=None): if not (user and pwd): @@ -192,7 +203,7 @@ class LoginManager: return from frappe.utils import now_datetime - current_hour = int(now_datetime(user=frappe.form_dict.get('usr')).strftime('%H')) + current_hour = int(now_datetime().strftime('%H')) if login_before and current_hour > login_before: frappe.throw(_("Login not allowed at this time"), frappe.AuthenticationError) diff --git a/frappe/boot.py b/frappe/boot.py index 44e7c6391b..78a498801d 100644 --- a/frappe/boot.py +++ b/frappe/boot.py @@ -70,6 +70,7 @@ def get_bootinfo(): bootinfo.error_report_email = frappe.get_hooks("error_report_email") bootinfo.default_background_image = get_url("/assets/frappe/images/ui/into-the-dawn.jpg") + bootinfo.calendars = sorted(frappe.get_hooks("calendars")) return bootinfo @@ -104,9 +105,16 @@ def get_allowed_pages(): def load_translations(bootinfo): if frappe.local.lang != 'en': - bootinfo["__messages"] = frappe.get_lang_dict("boot") + messages = frappe.get_lang_dict("boot") + bootinfo["lang"] = frappe.lang + # load translated report names + for name in bootinfo.user.all_reports: + messages[name] = frappe._(name) + + bootinfo["__messages"] = messages + def get_fullnames(): """map of user fullnames""" ret = frappe.db.sql("""select name, @@ -142,14 +150,10 @@ def add_home_page(bootinfo, docs): docs.append(page) def add_timezone_info(bootinfo): - user = bootinfo.user.get("time_zone") system = bootinfo.sysdefaults.get("time_zone") - if user and user != system: - import frappe.utils.momentjs - bootinfo.timezone_info = {"zones":{}, "rules":{}, "links":{}} - - frappe.utils.momentjs.update(user, bootinfo.timezone_info) - frappe.utils.momentjs.update(system, bootinfo.timezone_info) + import frappe.utils.momentjs + bootinfo.timezone_info = {"zones":{}, "rules":{}, "links":{}} + frappe.utils.momentjs.update(system, bootinfo.timezone_info) def load_print(bootinfo, doclist): print_settings = frappe.db.get_singles_dict("Print Settings") @@ -158,4 +162,4 @@ def load_print(bootinfo, doclist): load_print_css(bootinfo, print_settings) def load_print_css(bootinfo, print_settings): - bootinfo.print_css = frappe.get_attr("frappe.templates.pages.print.get_print_style")(print_settings.print_style or "Modern") + bootinfo.print_css = frappe.get_attr("frappe.templates.pages.print.get_print_style")(print_settings.print_style or "Modern", for_legacy=True) diff --git a/frappe/build.py b/frappe/build.py index 0d27d75f53..42136f59fa 100644 --- a/frappe/build.py +++ b/frappe/build.py @@ -153,13 +153,13 @@ def pack(target, sources, no_compress, verbose): def html_to_js_template(path, content): # remove whitespace to a single space - content = re.sub("\s+", " ", content).replace("'", "\'") + content = re.sub("\s+", " ", content) # strip comments content = re.sub("()", "", content) return """frappe.templates["{key}"] = '{content}';\n""".format(\ - key=path.rsplit("/", 1)[-1][:-5], content=content) + key=path.rsplit("/", 1)[-1][:-5], content=content.replace("'", "\'")) def files_dirty(): for target, sources in get_build_maps().iteritems(): diff --git a/frappe/change_log/current/if_owner.md b/frappe/change_log/current/if_owner.md new file mode 100644 index 0000000000..e1f6019797 --- /dev/null +++ b/frappe/change_log/current/if_owner.md @@ -0,0 +1 @@ +- Ability to set permissions based on owner by checking **If Owner** in Role Permissions Manager diff --git a/frappe/change_log/current/readme.md b/frappe/change_log/current/readme.md new file mode 100644 index 0000000000..e93bb75396 --- /dev/null +++ b/frappe/change_log/current/readme.md @@ -0,0 +1,3 @@ +Leave change log files in this folder for user release notes. + +(this file is just a place holder, don't delete it) diff --git a/frappe/change_log/v5/v5_0_18.md b/frappe/change_log/v5/v5_0_18.md new file mode 100644 index 0000000000..95e07f30e8 --- /dev/null +++ b/frappe/change_log/v5/v5_0_18.md @@ -0,0 +1,6 @@ +#### Updates to Web Forms + +- Web Forms list now is a standard portal list and includes paging and other extensions +- Section, Column Breaks in Web Forms +- Consistent User Interface +- Cleanup of Portal Pages diff --git a/frappe/change_log/v5/v5_0_20.md b/frappe/change_log/v5/v5_0_20.md new file mode 100644 index 0000000000..18e9f43b57 --- /dev/null +++ b/frappe/change_log/v5/v5_0_20.md @@ -0,0 +1 @@ +- Ability to send yourself a copy of the outgoing email added back. diff --git a/frappe/change_log/v5/v5_0_32.md b/frappe/change_log/v5/v5_0_32.md new file mode 100644 index 0000000000..17a7cb3283 --- /dev/null +++ b/frappe/change_log/v5/v5_0_32.md @@ -0,0 +1,5 @@ +- Reports are now searchable from awesome bar +- Show currect label for title in list views +- Datepicker now sets default value as Today +- Map child table as per meta, if not mentioned in table_map via mapper +- Re-enable save button on error \ No newline at end of file diff --git a/frappe/change_log/v5/v5_1_0.md b/frappe/change_log/v5/v5_1_0.md new file mode 100644 index 0000000000..3036acc826 --- /dev/null +++ b/frappe/change_log/v5/v5_1_0.md @@ -0,0 +1,3 @@ +- Change print font from Setup > Print Settings or set it for each Print Format. Font options are "Default", "Arial", "Helvetica", "Verdana", "Monospace". +- Print and full-page print preview in user's language +- Fixed inconsistent visibility of a logged-in user's image in website diff --git a/frappe/change_log/v5/v5_1_1.md b/frappe/change_log/v5/v5_1_1.md new file mode 100644 index 0000000000..befa5be85c --- /dev/null +++ b/frappe/change_log/v5/v5_1_1.md @@ -0,0 +1 @@ +- Ability to **Share with Everyone** (except Guest) using **Share With** diff --git a/frappe/commands.py b/frappe/commands.py index d0fac47d07..4f5c316af6 100644 --- a/frappe/commands.py +++ b/frappe/commands.py @@ -4,7 +4,6 @@ from __future__ import unicode_literals, absolute_import import sys import os -import subprocess import json import click import hashlib @@ -140,7 +139,7 @@ def reinstall(context): frappe.clear_cache() installed = frappe.get_installed_apps() frappe.clear_cache() - except Exception, e: + except Exception: installed = [] finally: if frappe.db: @@ -191,8 +190,6 @@ def migrate(context, rebuild_website=False): import frappe.translate from frappe.desk.notifications import clear_notifications - verbose = context.verbose - for site in context.sites: print 'Migrating', site frappe.init(site=site) @@ -312,15 +309,16 @@ def destroy_all_sessions(context): frappe.destroy() @click.command('sync-www') +@click.option('--force', help='Rebuild all pages', is_flag=True, default=False) @pass_context -def sync_www(context): +def sync_www(context, force=False): "Sync files from static pages from www directory to Web Pages" from frappe.website import statics for site in context.sites: try: frappe.init(site=site) frappe.connect() - statics.sync_statics(rebuild=context.force) + statics.sync_statics(rebuild=force) frappe.db.commit() finally: frappe.destroy() @@ -341,32 +339,17 @@ def build_website(context): frappe.destroy() @click.command('setup-docs') -@click.argument('app') -@click.argument('docs-app') -@click.argument('path') @pass_context -def setup_docs(context,app, docs_app, path): +def setup_docs(context): "Setup docs in target folder of target app" from frappe.utils.setup_docs import setup_docs + from frappe.website import statics for site in context.sites: try: frappe.init(site=site) frappe.connect() - setup_docs(app, docs_app, path) - finally: - frappe.destroy() - -@click.command('build-docs') -@click.argument('app') -@pass_context -def build_docs(context, app): - "Build docs from /src to /www folder in app" - from frappe.utils.autodoc import build - frappe.destroy() - for site in context.sites: - try: - frappe.init(site=site) - build(app) + setup_docs() + statics.sync_statics(rebuild=True) finally: frappe.destroy() @@ -483,7 +466,7 @@ def export_json(context, doctype, name, path): try: frappe.init(site=site) frappe.connect() - data_import_tool.export_json(doctype, name, path) + data_import_tool.export_json(doctype, path, name=name) finally: frappe.destroy() @@ -613,6 +596,7 @@ def console(context): site = get_single_site(context) frappe.init(site=site) frappe.connect() + frappe.local.lang = frappe.db.get_default("lang") import IPython IPython.embed() @@ -825,7 +809,6 @@ commands = [ sync_www, build_website, setup_docs, - build_docs, reset_perms, execute, celery, diff --git a/frappe/config/setup.py b/frappe/config/setup.py index 0d8a3caf3f..0e5fe02046 100644 --- a/frappe/config/setup.py +++ b/frappe/config/setup.py @@ -208,15 +208,6 @@ def get_data(): "description": _("Install Applications."), "icon": "icon-download" }, - { - "type": "doctype", - "name": "Backup Manager", - "label": _("Download Backup"), - "onclick": "frappe.ui.toolbar.download_backup", - "icon": "icon-download-alt", - "description": _("Send download link of a recent backup to System Managers"), - "hide_count": True - }, { "type": "doctype", "name": "Backup Manager", diff --git a/frappe/core/doctype/comment/comment.json b/frappe/core/doctype/comment/comment.json index 07b4fdfa40..ed68eca7e0 100644 --- a/frappe/core/doctype/comment/comment.json +++ b/frappe/core/doctype/comment/comment.json @@ -103,12 +103,31 @@ "fieldtype": "Check", "label": "Unsubscribed", "permlevel": 0 + }, + { + "fieldname": "reference_doctype", + "fieldtype": "Link", + "label": "Reference DocType", + "options": "DocType", + "permlevel": 0, + "precision": "", + "read_only": 1 + }, + { + "description": "Reference DocType and Reference Name are used to render a comment as a link (href) to a Doc.", + "fieldname": "reference_name", + "fieldtype": "Dynamic Link", + "label": "Reference Name", + "options": "reference_doctype", + "permlevel": 0, + "precision": "", + "read_only": 1 } ], "icon": "icon-comments", "idx": 1, "issingle": 0, - "modified": "2015-02-11 15:32:45.807458", + "modified": "2015-06-08 12:31:15.122312", "modified_by": "Administrator", "module": "Core", "name": "Comment", diff --git a/frappe/core/doctype/comment/comment.py b/frappe/core/doctype/comment/comment.py index 76f7532a2b..eba36506be 100644 --- a/frappe/core/doctype/comment/comment.py +++ b/frappe/core/doctype/comment/comment.py @@ -7,10 +7,10 @@ from frappe import _ from frappe.website.render import clear_cache from frappe.model.document import Document from frappe.model.db_schema import add_column +from frappe.utils import get_fullname class Comment(Document): """Comments are added to Documents via forms or views like blogs etc.""" - __doclink__ = "https://frappe.io/docs/models/core/comment" no_feed_on_delete = True def get_feed(self): @@ -38,6 +38,9 @@ class Comment(Document): and comment_docname=%s""", (self.doctype, self.name))[0][0] >= 50: frappe.throw(_("Cannot add more than 50 comments")) + if not self.comment_by_fullname and self.comment_by: + self.comment_by_fullname = get_fullname(self.comment_by) + def on_update(self): """Updates `_comments` property in parent Document.""" self.update_comment_in_doc() @@ -97,7 +100,7 @@ class Comment(Document): """Updates `_comments` property in parent Document with given dict. :param _comments: Dict of comments.""" - if frappe.db.get_value("DocType", self.comment_doctype, "issingle"): + if not self.comment_doctype or frappe.db.get_value("DocType", self.comment_doctype, "issingle"): return # use sql, so that we do not mess with the timestamp @@ -130,4 +133,3 @@ def on_doctype_update(): frappe.db.commit() frappe.db.sql("""alter table `tabComment` add index comment_doctype_docname_index(comment_doctype, comment_docname)""") - diff --git a/frappe/core/doctype/communication/communication.py b/frappe/core/doctype/communication/communication.py index 1e3b6df602..5fbf556568 100644 --- a/frappe/core/doctype/communication/communication.py +++ b/frappe/core/doctype/communication/communication.py @@ -5,7 +5,7 @@ from __future__ import unicode_literals, absolute_import import frappe import json from email.utils import formataddr, parseaddr -from frappe.utils import get_url, get_formatted_email +from frappe.utils import get_url, get_formatted_email, cstr, cint from frappe.utils.file_manager import get_file import frappe.email.smtp from frappe import _ @@ -43,13 +43,15 @@ class Communication(Document): if to_status in status_field.options.splitlines(): frappe.db.set_value(parent.doctype, parent.name, "status", to_status) - def send(self, print_html=None, print_format=None, attachments=None): + def send(self, print_html=None, print_format=None, attachments=None, + send_me_a_copy=False, recipients=None): """Send communication via Email. :param print_html: Send given value as HTML attachment. :param print_format: Attach print format of parent document.""" - self.notify(print_html, print_format, attachments) + self.send_me_a_copy = send_me_a_copy + self.notify(print_html, print_format, attachments, recipients) def set_incoming_outgoing_accounts(self): self.incoming_email_account = self.outgoing_email_account = None @@ -59,17 +61,20 @@ class Communication(Document): {"append_to": self.reference_doctype, "enable_incoming": 1}, "email_id") self.outgoing_email_account = frappe.db.get_value("Email Account", - {"append_to": self.reference_doctype, "enable_outgoing": 1}, "email_id") + {"append_to": self.reference_doctype, "enable_outgoing": 1}, + ["email_id", "always_use_account_email_id_as_sender"], as_dict=True) if not self.incoming_email_account: self.incoming_email_account = frappe.db.get_value("Email Account", {"default_incoming": 1}, "email_id") if not self.outgoing_email_account: - self.outgoing_email_account = frappe.db.get_value("Email Account", {"default_outgoing": 1}, "email_id") + self.outgoing_email_account = frappe.db.get_value("Email Account", {"default_outgoing": 1}, + ["email_id", "always_use_account_email_id_as_sender"], as_dict=True) or frappe._dict() - def notify(self, print_html=None, print_format=None, attachments=None, except_recipient=False): + def notify(self, print_html=None, print_format=None, attachments=None, recipients=None, except_recipient=False): self.prepare_to_notify(print_html, print_format, attachments) - recipients = self.get_recipients(except_recipient=except_recipient) + if not recipients: + recipients = self.get_recipients(except_recipient=except_recipient) frappe.sendmail( recipients=recipients, @@ -96,8 +101,8 @@ class Communication(Document): self.set_incoming_outgoing_accounts() - if not self.sender: - self.sender = formataddr([frappe.session.data.full_name or "Notification", self.outgoing_email_account]) + if not self.sender or cint(self.outgoing_email_account.always_use_account_email_id_as_sender): + self.sender = formataddr([frappe.session.data.full_name or "Notification", self.outgoing_email_account.email_id]) self.attachments = [] @@ -122,7 +127,8 @@ class Communication(Document): def get_recipients(self, except_recipient=False): """Build a list of users to which this email should go to""" - original_recipients = [s.strip() for s in self.recipients.split(",")] + # [EDGE CASE] self.recipients can be None when an email is sent as BCC + original_recipients = [s.strip() for s in cstr(self.recipients).split(",")] recipients = original_recipients[:] if self.reference_doctype and self.reference_name: @@ -153,6 +159,9 @@ class Communication(Document): if e not in filtered and email_id not in filtered: filtered.append(e) + if getattr(self, "send_me_a_copy", False): + filtered.append(self.sender) + return filtered def get_starrers(self): @@ -198,7 +207,8 @@ def on_doctype_update(): @frappe.whitelist() def make(doctype=None, name=None, content=None, subject=None, sent_or_received = "Sent", sender=None, recipients=None, communication_medium="Email", send_email=False, - print_html=None, print_format=None, attachments='[]', ignore_doctype_permissions=False): + print_html=None, print_format=None, attachments='[]', ignore_doctype_permissions=False, + send_me_a_copy=False): """Make a new communication. :param doctype: Reference DocType. @@ -212,7 +222,9 @@ def make(doctype=None, name=None, content=None, subject=None, sent_or_received = :param send_mail: Send via email (default **False**). :param print_html: HTML Print format to be sent as attachment. :param print_format: Print Format name of parent document to be sent as attachment. - :param attachments: List of attachments as list of files or JSON string.""" + :param attachments: List of attachments as list of files or JSON string. + :param send_me_a_copy: Send a copy to the sender (default **False**). + """ is_error_report = (doctype=="User" and name==frappe.session.user and subject=="Error Report") @@ -235,11 +247,17 @@ def make(doctype=None, name=None, content=None, subject=None, sent_or_received = "reference_name": name }) comm.insert(ignore_permissions=True) - + + recipients = None if send_email: - comm.send(print_html, print_format, attachments) + comm.send_me_a_copy = send_me_a_copy + recipients = comm.get_recipients() + comm.send(print_html, print_format, attachments, send_me_a_copy=send_me_a_copy, recipients=recipients) - return comm.name + return { + "name": comm.name, + "recipients": ", ".join(recipients) if recipients else None + } @frappe.whitelist() def get_convert_to(): diff --git a/frappe/core/doctype/docfield/docfield.py b/frappe/core/doctype/docfield/docfield.py index 9dae3aea53..6b53be3288 100644 --- a/frappe/core/doctype/docfield/docfield.py +++ b/frappe/core/doctype/docfield/docfield.py @@ -6,5 +6,4 @@ from __future__ import unicode_literals from frappe.model.document import Document class DocField(Document): - __doclink__ = "https://frappe.io/docs/models/core/docfield" pass diff --git a/frappe/core/doctype/docperm/docperm.json b/frappe/core/doctype/docperm/docperm.json index 04f8b0c19e..971f50911e 100644 --- a/frappe/core/doctype/docperm/docperm.json +++ b/frappe/core/doctype/docperm/docperm.json @@ -33,6 +33,14 @@ "label": "Apply User Permissions", "permlevel": 0 }, + { + "description": "Apply this rule if the User is the Owner", + "fieldname": "if_owner", + "fieldtype": "Check", + "label": "If user is the owner", + "permlevel": 0, + "precision": "" + }, { "fieldname": "column_break_2", "fieldtype": "Column Break", @@ -232,7 +240,7 @@ "idx": 1, "issingle": 0, "istable": 1, - "modified": "2015-03-18 06:09:58.928014", + "modified": "2015-07-22 07:39:40.471092", "modified_by": "Administrator", "module": "Core", "name": "DocPerm", diff --git a/frappe/core/doctype/docperm/docperm.py b/frappe/core/doctype/docperm/docperm.py index 919ed1179e..36ed9acbe6 100644 --- a/frappe/core/doctype/docperm/docperm.py +++ b/frappe/core/doctype/docperm/docperm.py @@ -7,5 +7,4 @@ import frappe from frappe.model.document import Document class DocPerm(Document): - __doclink__ = "https://frappe.io/docs/models/v5.x/core/docperm" pass diff --git a/frappe/core/doctype/docshare/docshare.json b/frappe/core/doctype/docshare/docshare.json index 68ebe45c7b..ed649f2930 100644 --- a/frappe/core/doctype/docshare/docshare.json +++ b/frappe/core/doctype/docshare/docshare.json @@ -26,7 +26,7 @@ "print_hide": 0, "read_only": 0, "report_hide": 0, - "reqd": 1, + "reqd": 0, "search_index": 1, "set_only_once": 0 }, @@ -129,6 +129,13 @@ "reqd": 0, "search_index": 0, "set_only_once": 0 + }, + { + "fieldname": "everyone", + "fieldtype": "Check", + "label": "Everyone", + "permlevel": 0, + "precision": "" } ], "hide_heading": 0, @@ -138,7 +145,7 @@ "is_submittable": 0, "issingle": 0, "istable": 0, - "modified": "2015-02-12 11:30:52.968078", + "modified": "2015-07-17 07:02:10.632582", "modified_by": "Administrator", "module": "Core", "name": "DocShare", diff --git a/frappe/core/doctype/docshare/docshare.py b/frappe/core/doctype/docshare/docshare.py index cf79e0531c..5f2b3ae1bd 100644 --- a/frappe/core/doctype/docshare/docshare.py +++ b/frappe/core/doctype/docshare/docshare.py @@ -11,6 +11,7 @@ class DocShare(Document): no_feed_on_delete = True def validate(self): + self.validate_user() self.check_share_permission() self.cascade_permissions_downwards() self.get_doc().run_method("validate_share", self) @@ -26,6 +27,12 @@ class DocShare(Document): self._doc = frappe.get_doc(self.share_doctype, self.share_name) return self._doc + def validate_user(self): + if self.everyone: + self.user = None + elif not self.user: + frappe.throw(_("User is mandatory for Share"), frappe.MandatoryError) + def check_share_permission(self): if (not self.flags.ignore_share_permission and not frappe.has_permission(self.share_doctype, "share", self.get_doc())): diff --git a/frappe/core/doctype/docshare/test_docshare.py b/frappe/core/doctype/docshare/test_docshare.py index 4fb522e267..e4a41ac0d2 100644 --- a/frappe/core/doctype/docshare/test_docshare.py +++ b/frappe/core/doctype/docshare/test_docshare.py @@ -78,3 +78,15 @@ class TestDocShare(unittest.TestCase): frappe.set_user(self.user) self.assertFalse(self.event.has_permission("share")) + def test_share_with_everyone(self): + self.assertTrue(self.event.name not in frappe.share.get_shared("Event", self.user)) + + frappe.share.set_permission("Event", self.event.name, None, "read", everyone=1) + self.assertTrue(self.event.name in frappe.share.get_shared("Event", self.user)) + self.assertTrue(self.event.name in frappe.share.get_shared("Event", "test1@example.com")) + self.assertTrue(self.event.name not in frappe.share.get_shared("Event", "Guest")) + + frappe.share.set_permission("Event", self.event.name, None, "read", value=0, everyone=1) + self.assertTrue(self.event.name not in frappe.share.get_shared("Event", self.user)) + self.assertTrue(self.event.name not in frappe.share.get_shared("Event", "test1@example.com")) + self.assertTrue(self.event.name not in frappe.share.get_shared("Event", "Guest")) diff --git a/frappe/core/doctype/doctype/doctype.py b/frappe/core/doctype/doctype/doctype.py index 386770e359..c0145e4bec 100644 --- a/frappe/core/doctype/doctype/doctype.py +++ b/frappe/core/doctype/doctype/doctype.py @@ -18,7 +18,6 @@ form_grid_templates = { } class DocType(Document): - __doclink__ = "https://frappe.io/docs/models/core/doctype" def get_feed(self): return self.name @@ -315,6 +314,7 @@ def validate_fields(meta): if not d.permlevel: d.permlevel = 0 if not d.fieldname: frappe.throw(_("Fieldname is required in row {0}").format(d.idx)) + d.fieldname = d.fieldname.lower() check_illegal_characters(d.fieldname) check_unique_fieldname(d.fieldname) check_illegal_mandatory(d) @@ -362,14 +362,21 @@ def validate_permissions(doctype, for_remove=False): def check_double(d): has_similar = False + similar_because_of = "" for p in permissions: - if (p.role==d.role and p.permlevel==d.permlevel - and p.apply_user_permissions==d.apply_user_permissions and p!=d): - has_similar = True - break + if p.role==d.role and p.permlevel==d.permlevel and p!=d: + if p.apply_user_permissions==d.apply_user_permissions: + has_similar = True + similar_because_of = _("Apply User Permissions") + break + elif p.if_owner==d.if_owner: + similar_because_of = _("If Owner") + has_similar = True + break if has_similar: - frappe.throw(_("{0}: Only one rule allowed with the same Role, Level and Apply User Permissions").format(get_txt(d))) + frappe.throw(_("{0}: Only one rule allowed with the same Role, Level and {1}")\ + .format(get_txt(d), similar_because_of)) def check_level_zero_is_set(d): if cint(d.permlevel) > 0 and d.role != 'All': @@ -382,8 +389,8 @@ def validate_permissions(doctype, for_remove=False): if not has_zero_perm: frappe.throw(_("{0}: Permission at level 0 must be set before higher levels are set").format(get_txt(d))) - if d.create or d.submit or d.cancel or d.amend: - frappe.throw(_("{0}: Create, Submit, Cancel and Amend only valid at level 0").format(get_txt(d))) + for invalid in ("create", "submit", "cancel", "amend"): + if d.get(invalid): d.set(invalid, 0) def check_permission_dependency(d): if d.cancel and not d.submit: @@ -466,4 +473,3 @@ def init_list(doctype): doc = frappe.get_meta(doctype) make_boilerplate("controller_list.js", doc) make_boilerplate("controller_list.html", doc) - diff --git a/frappe/core/doctype/module_def/module_def.py b/frappe/core/doctype/module_def/module_def.py index 75b7e14825..44df59cb52 100644 --- a/frappe/core/doctype/module_def/module_def.py +++ b/frappe/core/doctype/module_def/module_def.py @@ -7,7 +7,6 @@ import frappe, os from frappe.model.document import Document class ModuleDef(Document): - __doclink__ = "https://frappe.io/docs/models/core/module_def" def on_update(self): """If in `developer_mode`, create folder for module and add in `modules.txt` of app if missing.""" @@ -39,7 +38,3 @@ class ModuleDef(Document): frappe.clear_cache() frappe.setup_module_map() - - - - diff --git a/frappe/core/doctype/page/page.json b/frappe/core/doctype/page/page.json index 75a2fc003d..1786c11967 100644 --- a/frappe/core/doctype/page/page.json +++ b/frappe/core/doctype/page/page.json @@ -87,7 +87,7 @@ "idx": 1, "issingle": 0, "istable": 0, - "modified": "2015-02-05 05:11:41.982758", + "modified": "2015-07-13 04:45:55.942795", "modified_by": "Administrator", "module": "Core", "name": "Page", @@ -122,14 +122,6 @@ "share": 1, "submit": 0, "write": 1 - }, - { - "apply_user_permissions": 1, - "email": 1, - "permlevel": 0, - "print": 1, - "read": 1, - "role": "All" } ], "read_only": 0 diff --git a/frappe/core/doctype/page/page.py b/frappe/core/doctype/page/page.py index 1e961dbf06..9c4059d792 100644 --- a/frappe/core/doctype/page/page.py +++ b/frappe/core/doctype/page/page.py @@ -5,6 +5,7 @@ from __future__ import unicode_literals import frappe from frappe.model.document import Document from frappe.build import html_to_js_template +from frappe import conf class Page(Document): def autoname(self): @@ -26,13 +27,16 @@ class Page(Document): cnt = 1 self.name += '-' + str(cnt) + def validate(self): + if not getattr(conf,'developer_mode', 0): + frappe.throw(_("Not in Developer Mode")) + # export def on_update(self): """ Writes the .txt for this page and if write_content is checked, it will write out a .html file """ - from frappe import conf from frappe.core.doctype.doctype.doctype import make_module_and_roles make_module_and_roles(self, "roles") @@ -62,6 +66,21 @@ class Page(Document): d[key] = self.get(key) return d + def is_permitted(self): + """Returns true if Page Role is not set or the user is allowed.""" + from frappe.utils import has_common + + allowed = [d.role for d in frappe.get_all("Page Role", fields=["role"], + filters={"parent": self.name})] + + if not allowed: + return True + + roles = frappe.get_roles() + + if has_common(roles, allowed): + return True + def load_assets(self): from frappe.modules import get_module_path, scrub import os diff --git a/frappe/core/doctype/scheduler_log/scheduler_log.json b/frappe/core/doctype/scheduler_log/scheduler_log.json index 0d747223c0..cd87f27920 100644 --- a/frappe/core/doctype/scheduler_log/scheduler_log.json +++ b/frappe/core/doctype/scheduler_log/scheduler_log.json @@ -6,6 +6,15 @@ "doctype": "DocType", "document_type": "System", "fields": [ + { + "default": "0", + "fieldname": "seen", + "fieldtype": "Check", + "hidden": 1, + "label": "Seen", + "permlevel": 0, + "precision": "" + }, { "fieldname": "method", "fieldtype": "Data", @@ -22,7 +31,7 @@ ], "icon": "icon-warning-sign", "idx": 1, - "modified": "2015-02-05 05:11:46.339879", + "modified": "2015-05-28 02:49:12.819934", "modified_by": "Administrator", "module": "Core", "name": "Scheduler Log", diff --git a/frappe/core/doctype/scheduler_log/scheduler_log.py b/frappe/core/doctype/scheduler_log/scheduler_log.py index a52d0efa2c..bb841405bd 100644 --- a/frappe/core/doctype/scheduler_log/scheduler_log.py +++ b/frappe/core/doctype/scheduler_log/scheduler_log.py @@ -9,4 +9,11 @@ import frappe from frappe.model.document import Document class SchedulerLog(Document): - pass \ No newline at end of file + def onload(self): + if not self.seen: + self.seen = 1 + self.save() + +def set_old_logs_as_seen(): + frappe.db.sql("""update `tabScheduler Log` set seen=1 + where ifnull(seen, 0)=0 and datediff(curdate(), creation) > 7""") diff --git a/frappe/core/doctype/scheduler_log/scheduler_log_list.js b/frappe/core/doctype/scheduler_log/scheduler_log_list.js new file mode 100644 index 0000000000..bb37614d78 --- /dev/null +++ b/frappe/core/doctype/scheduler_log/scheduler_log_list.js @@ -0,0 +1,11 @@ +frappe.listview_settings['Scheduler Log'] = { + add_fields: ["seen"], + get_indicator: function(doc) { + if(cint(doc.seen)) { + return [__("Seen"), "green", "seen,=,1"]; + } else { + return [__("Not Seen"), "red", "seen,=,0"]; + } + }, + order_by: "seen asc, modified desc", +}; diff --git a/frappe/core/doctype/scheduler_log/test_scheduler_log.py b/frappe/core/doctype/scheduler_log/test_scheduler_log.py new file mode 100644 index 0000000000..39594cdd95 --- /dev/null +++ b/frappe/core/doctype/scheduler_log/test_scheduler_log.py @@ -0,0 +1,12 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors +# See license.txt +from __future__ import unicode_literals + +import frappe +import unittest + +# test_records = frappe.get_test_records('Scheduler Log') + +class TestSchedulerLog(unittest.TestCase): + pass diff --git a/frappe/core/doctype/system_settings/system_settings.json b/frappe/core/doctype/system_settings/system_settings.json index 49c3a06edf..82ffb370d2 100644 --- a/frappe/core/doctype/system_settings/system_settings.json +++ b/frappe/core/doctype/system_settings/system_settings.json @@ -7,7 +7,7 @@ { "fieldname": "localization", "fieldtype": "Section Break", - "label": "Localization", + "label": "", "permlevel": 0 }, { @@ -20,6 +20,12 @@ "reqd": 1, "search_index": 0 }, + { + "fieldname": "column_break_3", + "fieldtype": "Column Break", + "permlevel": 0, + "precision": "" + }, { "fieldname": "time_zone", "fieldtype": "Select", @@ -30,7 +36,7 @@ { "fieldname": "date_and_number_format", "fieldtype": "Section Break", - "label": "Date and Number Format", + "label": "", "permlevel": 0 }, { @@ -41,6 +47,12 @@ "permlevel": 0, "reqd": 1 }, + { + "fieldname": "column_break_7", + "fieldtype": "Column Break", + "permlevel": 0, + "precision": "" + }, { "fieldname": "number_format", "fieldtype": "Select", @@ -80,6 +92,12 @@ "permlevel": 0, "precision": "" }, + { + "fieldname": "column_break_13", + "fieldtype": "Column Break", + "permlevel": 0, + "precision": "" + }, { "description": "Run scheduled jobs only if checked", "fieldname": "enable_scheduler", @@ -96,11 +114,39 @@ "permlevel": 0, "precision": "", "report_hide": 1 + }, + { + "fieldname": "email", + "fieldtype": "Section Break", + "label": "EMail", + "permlevel": 0, + "precision": "" + }, + { + "description": "Your organization name and address for the email footer.", + "fieldname": "email_footer_address", + "fieldtype": "Small Text", + "label": "Email Footer Address", + "permlevel": 0, + "precision": "" + }, + { + "fieldname": "column_break_18", + "fieldtype": "Column Break", + "permlevel": 0, + "precision": "" + }, + { + "fieldname": "disable_standard_email_footer", + "fieldtype": "Check", + "label": "Disable Standard Email Footer", + "permlevel": 0, + "precision": "" } ], "icon": "icon-cog", "issingle": 1, - "modified": "2015-05-18 05:11:38.759688", + "modified": "2015-05-21 07:15:55.682132", "modified_by": "Administrator", "module": "Core", "name": "System Settings", diff --git a/frappe/core/doctype/system_settings/system_settings.py b/frappe/core/doctype/system_settings/system_settings.py index 0e26b8edd5..443b820104 100644 --- a/frappe/core/doctype/system_settings/system_settings.py +++ b/frappe/core/doctype/system_settings/system_settings.py @@ -5,6 +5,7 @@ from __future__ import unicode_literals import frappe from frappe import _ from frappe.model.document import Document +from frappe.model import no_value_fields from frappe.translate import get_lang_dict, set_default_language from frappe.utils import cint from frappe.utils.momentjs import get_all_timezones @@ -19,7 +20,7 @@ class SystemSettings(Document): def on_update(self): for df in self.meta.get("fields"): - if df.fieldtype in ("Select", "Data", "Check"): + if df.fieldtype not in no_value_fields: frappe.db.set_default(df.fieldname, self.get(df.fieldname)) if self.language: diff --git a/frappe/core/doctype/user/user.js b/frappe/core/doctype/user/user.js index b96d591fc8..9e6afe4d41 100644 --- a/frappe/core/doctype/user/user.js +++ b/frappe/core/doctype/user/user.js @@ -46,9 +46,7 @@ cur_frm.cscript.refresh = function(doc) { window.location.reload(); } - cur_frm.toggle_display('change_password', !doc.__islocal); - - cur_frm.toggle_display(['sb1', 'sb3'], false); + cur_frm.toggle_display(['sb1', 'sb3', 'modules_access'], false); if(!doc.__islocal){ cur_frm.add_custom_button(__("Set User Permissions"), function() { @@ -59,7 +57,7 @@ cur_frm.cscript.refresh = function(doc) { }, null, "btn-default") if(has_common(user_roles, ["Administrator", "System Manager"])) { - cur_frm.toggle_display(['sb1', 'sb3'], true); + cur_frm.toggle_display(['sb1', 'sb3', 'modules_access'], true); } cur_frm.cscript.enabled(doc); @@ -77,7 +75,7 @@ cur_frm.cscript.refresh = function(doc) { cur_frm.cscript.enabled = function(doc) { if(!doc.__islocal && has_common(user_roles, ["Administrator", "System Manager"])) { - cur_frm.toggle_display(['sb1', 'sb3'], doc.enabled); + cur_frm.toggle_display(['sb1', 'sb3', 'modules_access'], doc.enabled); cur_frm.toggle_enable('*', doc.enabled); cur_frm.set_df_property('enabled', 'read_only', 0); } diff --git a/frappe/core/doctype/user/user.json b/frappe/core/doctype/user/user.json index 22e99cf76b..51fc55df99 100644 --- a/frappe/core/doctype/user/user.json +++ b/frappe/core/doctype/user/user.json @@ -115,6 +115,7 @@ "permlevel": 0 }, { + "depends_on": "eval:!doc.__islocal", "fieldname": "change_password", "fieldtype": "Section Break", "label": "", @@ -127,6 +128,14 @@ "no_copy": 1, "permlevel": 0 }, + { + "depends_on": "", + "fieldname": "send_password_update_notification", + "fieldtype": "Check", + "label": "Send Password Update Notification", + "permlevel": 0, + "precision": "" + }, { "fieldname": "reset_password_key", "fieldtype": "Data", @@ -473,7 +482,7 @@ "issingle": 0, "istable": 0, "max_attachments": 5, - "modified": "2015-04-24 14:37:26.430454", + "modified": "2015-06-01 01:00:32.901851", "modified_by": "Administrator", "module": "Core", "name": "User", diff --git a/frappe/core/doctype/user/user.py b/frappe/core/doctype/user/user.py index 2982e461bb..415a6c71ac 100644 --- a/frappe/core/doctype/user/user.py +++ b/frappe/core/doctype/user/user.py @@ -76,8 +76,9 @@ class User(Document): if new_password and not self.in_insert: _update_password(self.name, new_password) - self.password_update_mail(new_password) - frappe.msgprint(_("New password emailed")) + if self.send_password_update_notification: + self.password_update_mail(new_password) + frappe.msgprint(_("New password emailed")) def on_update(self): # clear new password @@ -324,12 +325,16 @@ def get_perm_info(arg=None): and docstatus<2 order by parent, permlevel""", (frappe.form_dict['role'],), as_dict=1) @frappe.whitelist(allow_guest=True) -def update_password(new_password, key=None): +def update_password(new_password, key=None, old_password=None): # verify old password if key: user = frappe.db.get_value("User", {"reset_password_key":key}) if not user: return _("Cannot Update: Incorrect / Expired Link.") + elif old_password: + # verify old password + frappe.local.login_manager.check_password(frappe.session.user, old_password) + user = frappe.session.user _update_password(user, new_password) @@ -342,6 +347,10 @@ def update_password(new_password, key=None): else: return "/" +@frappe.whitelist() +def verify_password(password): + frappe.local.login_manager.check_password(frappe.session.user, password) + @frappe.whitelist(allow_guest=True) def sign_up(email, full_name): user = frappe.db.get("User", {"email": email}) diff --git a/frappe/core/doctype/user/user_list.js b/frappe/core/doctype/user/user_list.js index 6256a52b24..227f84ee70 100644 --- a/frappe/core/doctype/user/user_list.js +++ b/frappe/core/doctype/user/user_list.js @@ -15,3 +15,5 @@ frappe.listview_settings['User'] = { } } }; + +frappe.help.youtube_id["User"] = "fnBoRhBrwR4"; diff --git a/frappe/core/notifications.py b/frappe/core/notifications.py index e1bf27da52..96ce779f25 100644 --- a/frappe/core/notifications.py +++ b/frappe/core/notifications.py @@ -6,6 +6,9 @@ import frappe def get_notification_config(): return { + "for_doctype": { + "Scheduler Log": {"seen": 0}, + }, "for_module_doctypes": { "ToDo": "To Do", "Event": "Calendar", diff --git a/frappe/core/page/data_import_tool/data_import_tool.js b/frappe/core/page/data_import_tool/data_import_tool.js index 142299d6e6..5e349f7d6d 100644 --- a/frappe/core/page/data_import_tool/data_import_tool.js +++ b/frappe/core/page/data_import_tool/data_import_tool.js @@ -7,16 +7,25 @@ frappe.DataImportTool = Class.extend({ title: __("Data Import Tool"), single_column: true }); + this.page.add_inner_button(__("Help"), function() { + frappe.help.show_video("6wiriRKPhmg"); + }); this.make(); this.make_upload(); }, set_route_options: function() { - if(frappe.route_options - && frappe.route_options.doctype - && in_list(frappe.boot.user.can_import, frappe.route_options.doctype)) { - this.select.val(frappe.route_options.doctype).change(); - frappe.route_options = null; + var doctype = null; + if(frappe.get_route()[1]) { + doctype = frappe.get_route()[1]; + } else if(frappe.route_options && frappe.route_options.doctype) { + doctype = frappe.route_options.doctype; } + + if(in_list(frappe.boot.user.can_import, doctype)) { + this.select.val(doctype).change(); + } + + frappe.route_options = null; }, make: function() { var me = this; diff --git a/frappe/core/page/data_import_tool/data_import_tool.py b/frappe/core/page/data_import_tool/data_import_tool.py index 9a1ebe2b44..6b3ec60f72 100644 --- a/frappe/core/page/data_import_tool/data_import_tool.py +++ b/frappe/core/page/data_import_tool/data_import_tool.py @@ -3,7 +3,7 @@ from __future__ import unicode_literals -import frappe, json, os +import frappe, os from frappe import _ import frappe.modules.import_file @@ -30,12 +30,13 @@ def get_doctype_options(): doctype = frappe.form_dict['doctype'] return [doctype] + [d.options for d in frappe.get_meta(doctype).get_table_fields()] -def import_file_by_path(path, ignore_links=False, overwrite=False, submit=False): +def import_file_by_path(path, ignore_links=False, overwrite=False, submit=False, pre_process=None): from frappe.utils.csvutils import read_csv_content from frappe.core.page.data_import_tool.importer import upload print "Importing " + path with open(path, "r") as infile: - upload(rows = read_csv_content(infile.read()), ignore_links=ignore_links, overwrite=overwrite, submit_after_import=submit) + upload(rows = read_csv_content(infile.read()), ignore_links=ignore_links, overwrite=overwrite, + submit_after_import=submit, pre_process=pre_process) def export_csv(doctype, path): from frappe.core.page.data_import_tool.exporter import get_template @@ -43,7 +44,7 @@ def export_csv(doctype, path): get_template(doctype=doctype, all_doctypes="Yes", with_data="Yes") csvfile.write(frappe.response.result.encode("utf-8")) -def export_json(doctype, path, filters=None): +def export_json(doctype, path, filters=None, name=None): def post_process(out): del_keys = ('parent', 'parentfield', 'parenttype', 'modified_by', 'creation', 'owner', 'idx') for doc in out: @@ -57,9 +58,10 @@ def export_json(doctype, path, filters=None): if key in child: del child[key] - from frappe.utils.response import json_handler out = [] - if frappe.db.get_value("DocType", doctype, "issingle"): + if name: + out.append(frappe.get_doc(doctype, name).as_dict()) + elif frappe.db.get_value("DocType", doctype, "issingle"): out.append(frappe.get_doc(doctype).as_dict()) else: for doc in frappe.get_all(doctype, fields=["name"], filters=filters, limit_page_length=0, order_by="creation asc"): @@ -79,18 +81,18 @@ def export_fixture(doctype, app): export_json(doctype, frappe.get_app_path(app, "fixtures", frappe.scrub(doctype) + ".json")) -def import_doc(path, overwrite=False, ignore_links=False, ignore_insert=False, insert=False, submit=False): +def import_doc(path, overwrite=False, ignore_links=False, ignore_insert=False, + insert=False, submit=False, pre_process=None): if os.path.isdir(path): files = [os.path.join(path, f) for f in os.listdir(path)] else: files = [path] - for f in files: if f.endswith(".json"): frappe.flags.mute_emails = True - frappe.modules.import_file.import_file_by_path(f, data_import=True) + frappe.modules.import_file.import_file_by_path(f, data_import=True, force=True, pre_process=pre_process) frappe.flags.mute_emails = False elif f.endswith(".csv"): - import_file_by_path(f, ignore_links=ignore_links, overwrite=overwrite, submit=submit) + import_file_by_path(f, ignore_links=ignore_links, overwrite=overwrite, submit=submit, pre_process=pre_process) frappe.db.commit() diff --git a/frappe/core/page/data_import_tool/exporter.py b/frappe/core/page/data_import_tool/exporter.py index 19168e12c8..96922e8d8f 100644 --- a/frappe/core/page/data_import_tool/exporter.py +++ b/frappe/core/page/data_import_tool/exporter.py @@ -8,7 +8,7 @@ from frappe import _ import frappe.permissions import re from frappe.utils.csvutils import UnicodeWriter -from frappe.utils import cstr, cint, flt +from frappe.utils import cstr, cint, flt, formatdate, format_datetime from frappe.core.page.data_import_tool.data_import_tool import get_data_keys reflags = { @@ -31,7 +31,7 @@ def get_template(doctype=None, parent_doctype=None, all_doctypes="No", with_data if len(doctype) > 1: docs_to_export = doctype[1] doctype = doctype[0] - + if not parent_doctype: parent_doctype = doctype @@ -46,7 +46,7 @@ def get_template(doctype=None, parent_doctype=None, all_doctypes="No", with_data def get_data_keys_definition(): return get_data_keys() - + def add_main_header(): w.writerow([_('Data Import Template')]) w.writerow([get_data_keys_definition().main_table, doctype]) @@ -155,6 +155,7 @@ def get_template(doctype=None, parent_doctype=None, all_doctypes="No", with_data def add_data(): def add_data_row(row_group, dt, doc, rowidx): d = doc.copy() + meta = frappe.get_meta(dt) if all_doctypes: d.name = '"'+ d.name+'"' @@ -162,7 +163,16 @@ def get_template(doctype=None, parent_doctype=None, all_doctypes="No", with_data row_group.append([""] * (len(columns) + 1)) row = row_group[rowidx] for i, c in enumerate(columns[column_start_end[dt].start:column_start_end[dt].end]): - row[column_start_end[dt].start + i + 1] = d.get(c, "") + df = meta.get_field(c) + fieldtype = df.fieldtype if df else "Data" + value = d.get(c, "") + if value: + if fieldtype == "Date": + value = formatdate(value) + elif fieldtype == "Datetime": + value = format_datetime(value) + + row[column_start_end[dt].start + i + 1] = value if with_data=='Yes': frappe.permissions.can_export(parent_doctype, raise_exception=True) @@ -172,7 +182,7 @@ def get_template(doctype=None, parent_doctype=None, all_doctypes="No", with_data for doc in data: op = docs_to_export.get("op") names = docs_to_export.get("name") - + if names and op: if op == '=' and doc.name not in names: continue @@ -184,7 +194,7 @@ def get_template(doctype=None, parent_doctype=None, all_doctypes="No", with_data flags = 0 for a in re.split('\W+',sflags): flags = flags | reflags.get(a,0) - + c = re.compile(names, flags) m = c.match(doc.name) if not m: diff --git a/frappe/core/page/data_import_tool/importer.py b/frappe/core/page/data_import_tool/importer.py index 1ad6256b27..f05a7638f4 100644 --- a/frappe/core/page/data_import_tool/importer.py +++ b/frappe/core/page/data_import_tool/importer.py @@ -15,7 +15,8 @@ from frappe.utils import cint, cstr, flt from frappe.core.page.data_import_tool.data_import_tool import get_data_keys @frappe.whitelist() -def upload(rows = None, submit_after_import=None, ignore_encoding_errors=False, overwrite=None, ignore_links=False): +def upload(rows = None, submit_after_import=None, ignore_encoding_errors=False, overwrite=None, + ignore_links=False, pre_process=None): """upload data""" frappe.flags.mute_emails = True # extra input params @@ -200,6 +201,9 @@ def upload(rows = None, submit_after_import=None, ignore_encoding_errors=False, doc = None doc = get_doc(row_idx) + if pre_process: + pre_process(doc) + try: frappe.local.message_log = [] if parentfield: diff --git a/frappe/core/page/permission_manager/permission_manager.js b/frappe/core/page/permission_manager/permission_manager.js index b9264833ff..d2dbe1a6f1 100644 --- a/frappe/core/page/permission_manager/permission_manager.js +++ b/frappe/core/page/permission_manager/permission_manager.js @@ -191,6 +191,7 @@ frappe.PermissionEngine = Class.extend({ if (d.permlevel===0) { me.setup_user_permissions(d, role_cell); + me.setup_if_owner(d, role_cell); } var cell = me.add_cell(row, d, "permlevel"); @@ -269,6 +270,12 @@ frappe.PermissionEngine = Class.extend({ d.help = ""; }, + setup_if_owner: function(d, role_cell) { + var checkbox = this.add_check(role_cell, d, "if_owner") + .removeClass("col-md-4") + .css({"margin-top": "15px"}); + }, + rights: ["read", "write", "create", "delete", "submit", "cancel", "amend", "print", "email", "report", "import", "export", "set_user_permissions"], diff --git a/frappe/core/page/permission_manager/permission_manager.py b/frappe/core/page/permission_manager/permission_manager.py index 0dfd3f222a..4960e5aacf 100644 --- a/frappe/core/page/permission_manager/permission_manager.py +++ b/frappe/core/page/permission_manager/permission_manager.py @@ -19,7 +19,7 @@ def get_roles_and_doctypes(): name not in ('DocType') and exists(select * from `tabDocField` where parent=dt.name)""")], "roles": [d[0] for d in frappe.db.sql("""select name from tabRole where name not in - ('Guest', 'Administrator')""")] + ('Administrator')""")] } @frappe.whitelist() diff --git a/frappe/core/page/user_permissions/user_permissions.js b/frappe/core/page/user_permissions/user_permissions.js index 2a529d97ee..2828b0ab1a 100644 --- a/frappe/core/page/user_permissions/user_permissions.js +++ b/frappe/core/page/user_permissions/user_permissions.js @@ -243,7 +243,7 @@ frappe.UserPermissions = Class.extend({ +__("These restrictions will apply for Document Types where 'Apply User Permissions' is checked for the permission rule and a field with this value is present.") +'

').appendTo(this.body); - $.each([[__("Allow User If"), 150], [__("Document Type"), 150], [__("Is"),150], ["", 50]], + $.each([[__("Allow User"), 150], [__("If Document Type"), 150], [__("Is"),150], ["", 50]], function(i, col) { $("").html(col[0]).css("width", col[1]+"px") .appendTo(me.table.find("thead tr")); @@ -300,9 +300,9 @@ frappe.UserPermissions = Class.extend({ var d = new frappe.ui.Dialog({ title: __("Add A New Restriction"), fields: [ - {fieldtype:"Select", label:__("Allow User If"), + {fieldtype:"Select", label:__("Allow User"), options:me.options.users, reqd:1, fieldname:"user"}, - {fieldtype:"Select", label: __("Select Document Type"), fieldname:"defkey", + {fieldtype:"Select", label: __("If Document Type"), fieldname:"defkey", options:me.get_link_names(), reqd:1}, {fieldtype:"Link", label:__("Is"), fieldname:"defvalue", options:'[Select]', reqd:1}, diff --git a/frappe/custom/doctype/customize_form/customize_form.py b/frappe/custom/doctype/customize_form/customize_form.py index 9c91c6a0f7..234dea8971 100644 --- a/frappe/custom/doctype/customize_form/customize_form.py +++ b/frappe/custom/doctype/customize_form/customize_form.py @@ -102,7 +102,7 @@ class CustomizeForm(Document): meta = frappe.get_meta(self.doc_type) # doctype property setters for property in self.doctype_properties: - if property != "idx" and self.get(property) != meta.get(property): + if self.get(property) != meta.get(property): self.make_property_setter(property=property, value=self.get(property), property_type=self.doctype_properties[property]) @@ -117,7 +117,7 @@ class CustomizeForm(Document): continue for property in self.docfield_properties: - if df.get(property) != meta_df[0].get(property): + if property != "idx" and df.get(property) != meta_df[0].get(property): if property == "fieldtype": self.validate_fieldtype_change(df, meta_df[0].get(property), df.get(property)) @@ -260,4 +260,3 @@ class CustomizeForm(Document): and ifnull(field_name, '')!='naming_series'""", self.doc_type) frappe.clear_cache(doctype=self.doc_type) self.fetch_to_customize() - diff --git a/frappe/data/conf.py b/frappe/data/conf.py deleted file mode 100644 index bce5d009a9..0000000000 --- a/frappe/data/conf.py +++ /dev/null @@ -1,52 +0,0 @@ -# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors -# MIT License. See license.txt - -# DEPRECATED only for reference - -from __future__ import unicode_literals -# app configuration - -# database config -db_name = '%(db_name)s' -db_password = '%(db_password)s' - -# user attachments stored in -files_path = 'public/files' -public_path = 'public' - -# max file attachment size (default 1MB) -max_file_size = 1000000 - -# max email size in bytes -max_email_size = 0 - -# total pop session timeout in seconds -pop_timeout = 0 - -# generate schema (.txt files) -developer_mode = 0 - -# clear cache on refresh -auto_cache_clear = 0 - -# email logs to admin (beta) -admin_email_notification = 0 - -# user timezone -user_timezone = 'Asia/Calcutta' - -# outgoing mail settings -mail_server = None -mail_login = None -mail_password = None -mail_port = None -use_ssl = None -auto_email_id = None - -# logging settings -log_file_name = 'logs/error_log.txt' -debug_log_dbs = [] -log_level = 'logging.INFO' -log_file_size = 5000 -log_file_backup_count = 5 - diff --git a/frappe/data/languages.txt b/frappe/data/languages.txt index 616c444e77..638dcd44cc 100644 --- a/frappe/data/languages.txt +++ b/frappe/data/languages.txt @@ -2,7 +2,7 @@ ar العربية bg bǎlgarski bs bosanski ca català -cz česky +cs česky da dansk de deutsch el ελληνικά diff --git a/frappe/database.py b/frappe/database.py index 2d572cecbd..6fd3d5712d 100644 --- a/frappe/database.py +++ b/frappe/database.py @@ -511,6 +511,10 @@ class Database: tabSingles where doctype=%s and field=%s""", (doctype, fieldname)) return val[0][0] if val else None + def get_singles_value(self, *args, **kwargs): + """Alias for get_single_value""" + return self.get_single_value(*args, **kwargs) + def _get_values_from_table(self, fields, filters, doctype, as_dict, debug, order_by=None, update=None): fl = [] if isinstance(fields, (list, tuple)): diff --git a/frappe/desk/desk_page.py b/frappe/desk/desk_page.py index 4ba22aa5d2..0138c56a19 100644 --- a/frappe/desk/desk_page.py +++ b/frappe/desk/desk_page.py @@ -11,7 +11,7 @@ def get(name): Return the :term:`doclist` of the `Page` specified by `name` """ page = frappe.get_doc('Page', name) - if has_permission(page): + if page.is_permitted(): page.load_assets() return page else: diff --git a/frappe/desk/doctype/event/event.py b/frappe/desk/doctype/event/event.py index 29f964315c..ba18cb506e 100644 --- a/frappe/desk/doctype/event/event.py +++ b/frappe/desk/doctype/event/event.py @@ -11,6 +11,10 @@ from frappe.utils.user import get_enabled_system_users weekdays = ["monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"] class Event(Document): + def get_route(self): + """for test-case""" + return "/Event/" + self.name + def validate(self): if self.starts_on and self.ends_on and self.starts_on > self.ends_on: frappe.msgprint(frappe._("Event end must be after start"), raise_exception=True) diff --git a/frappe/desk/doctype/todo/todo.json b/frappe/desk/doctype/todo/todo.json index bc15fd397e..ce1e17cf72 100644 --- a/frappe/desk/doctype/todo/todo.json +++ b/frappe/desk/doctype/todo/todo.json @@ -86,7 +86,7 @@ "fieldtype": "Link", "ignore_user_permissions": 1, "in_list_view": 0, - "label": "Assigned To", + "label": "Allocated To", "options": "User", "permlevel": 0, "reqd": 1 @@ -178,7 +178,7 @@ "in_dialog": 0, "issingle": 0, "max_attachments": 0, - "modified": "2015-05-04 07:44:46.567785", + "modified": "2015-06-11 16:06:34.561469", "modified_by": "Administrator", "module": "Desk", "name": "ToDo", diff --git a/frappe/desk/doctype/todo/todo.py b/frappe/desk/doctype/todo/todo.py index 1a62f3b851..f3c6647988 100644 --- a/frappe/desk/doctype/todo/todo.py +++ b/frappe/desk/doctype/todo/todo.py @@ -14,10 +14,10 @@ sender_field = "sender" class ToDo(Document): def validate(self): if self.is_new(): - self.add_assign_comment(frappe._("Assigned to {0}").format(get_fullname(self.owner)), "Assigned") + self.add_assign_comment(frappe._("Assigned to {0}: {1}").format(get_fullname(self.owner), self.description), "Assigned") else: - cur_status = frappe.db.get_value("ToDo", self.name, "status") - if cur_status != self.status: + # NOTE the previous value is only available in validate method + if self.get_db_value("status") != self.status: self.add_assign_comment(frappe._("Assignment closed by {0}".format(get_fullname(frappe.session.user))), "Assignment Completed") @@ -25,20 +25,29 @@ class ToDo(Document): self.update_in_reference() def on_trash(self): + # unlink assignment comment + frappe.db.sql("""update `tabComment` set reference_doctype=null and reference_name=null + where reference_doctype='ToDo' and reference_name=%s""", self.name) + self.update_in_reference() def add_assign_comment(self, text, comment_type): if not self.reference_type and self.reference_name: return - frappe.get_doc({ + comment = frappe.get_doc({ "doctype":"Comment", "comment_by": frappe.session.user, "comment_type": comment_type, "comment_doctype": self.reference_type, "comment_docname": self.reference_name, - "comment": """{text}""".format(text=text) - }).insert(ignore_permissions=True) + "comment": """{text}""".format(text=text), + "reference_doctype": self.doctype, + "reference_name": self.name + }) + comment.flags.ignore_permissions = True + comment.flags.ignore_links = True + comment.insert() def update_in_reference(self): if not (self.reference_type and self.reference_name): diff --git a/frappe/desk/form/load.py b/frappe/desk/form/load.py index 88947f3fe5..1cab39bed2 100644 --- a/frappe/desk/form/load.py +++ b/frappe/desk/form/load.py @@ -89,7 +89,7 @@ def get_docinfo(doc=None, doctype=None, name=None): "assignments": get_assignments(doc.doctype, doc.name), "permissions": get_doc_permissions(doc), "shared": frappe.share.get_users(doc.doctype, doc.name, - fields=["user", "read", "write", "share"]) + fields=["user", "read", "write", "share", "everyone"]) } def get_user_permissions(meta): @@ -105,7 +105,8 @@ def get_attachments(dt, dn): def get_comments(dt, dn, limit=100): comments = frappe.db.sql("""select name, comment, comment_by, creation, - comment_type, "Comment" as doctype from `tabComment` + reference_doctype, reference_name, comment_type, "Comment" as doctype + from `tabComment` where comment_doctype=%s and comment_docname=%s order by creation desc limit %s""" % ('%s','%s', limit), (dt, dn), as_dict=1) diff --git a/frappe/desk/form/meta.py b/frappe/desk/form/meta.py index 7018d15b87..c993dce046 100644 --- a/frappe/desk/form/meta.py +++ b/frappe/desk/form/meta.py @@ -11,6 +11,7 @@ from frappe.model.workflow import get_workflow_name from frappe.utils import get_html_format from frappe.translate import make_dict_from_messages, extract_messages_from_code from frappe.utils.jinja import render_include +from frappe.build import html_to_js_template ###### @@ -70,12 +71,25 @@ class FormMeta(Meta): self.add_code_via_hook("doctype_js", "__js") self.add_code_via_hook("doctype_list_js", "__list_js") self.add_custom_script() + self.add_html_templates(path) def _add_code(self, path, fieldname): js = frappe.read_file(path) if js: self.set(fieldname, (self.get(fieldname) or "") + "\n\n" + render_include(js)) + def add_html_templates(self, path): + if self.custom: + return + js = "" + for fname in os.listdir(path): + if fname.endswith(".html"): + with open(os.path.join(path, fname), 'r') as f: + template = unicode(f.read(), "utf-8") + js += html_to_js_template(fname, template) + + self.set("__js", (self.get("__js") or "") + js) + def add_code_via_hook(self, hook, fieldname): for app_name in frappe.get_installed_apps(): code_hook = frappe.get_hooks(hook, default={}, app_name=app_name) diff --git a/frappe/desk/form/utils.py b/frappe/desk/form/utils.py index b199417f0f..75e0248fb8 100644 --- a/frappe/desk/form/utils.py +++ b/frappe/desk/form/utils.py @@ -144,6 +144,7 @@ def get_linked_docs(doctype, name, metadata_loaded=None, no_metadata=False): filters=[[dt, link.get("fieldname"), '=', name]]) except frappe.PermissionError: + frappe.local.message_log.pop() continue if ret: diff --git a/frappe/desk/moduleview.py b/frappe/desk/moduleview.py index 97785b305d..7c6e83c164 100644 --- a/frappe/desk/moduleview.py +++ b/frappe/desk/moduleview.py @@ -137,7 +137,8 @@ def apply_permissions(data): if ((item.type=="doctype" and item.name in user.can_read) or (item.type=="page" and item.name in allowed_pages) - or (item.type=="report" and item.doctype in user.can_get_report)): + or (item.type=="report" and item.doctype in user.can_get_report) + or item.type=="help"): new_items.append(item) diff --git a/frappe/desk/query_report.py b/frappe/desk/query_report.py index fe4d59df8d..18416fad6b 100644 --- a/frappe/desk/query_report.py +++ b/frappe/desk/query_report.py @@ -11,6 +11,7 @@ from frappe.modules import scrub, get_module_path from frappe.utils import flt, cint, get_html_format from frappe.translate import send_translations import frappe.desk.reportview +from frappe.permissions import get_role_permissions def get_report_doc(report_name): doc = frappe.get_doc("Report", report_name) @@ -144,20 +145,35 @@ def get_filtered_data(ref_doctype, columns, data): linked_doctypes = get_linked_doctypes(columns, data) match_filters_per_doctype = get_user_match_filters(linked_doctypes, ref_doctype) shared = frappe.share.get_shared(ref_doctype) + columns_dict = get_columns_dict(columns) + + role_permissions = get_role_permissions(frappe.get_meta(ref_doctype)) + if_owner = role_permissions.get("if_owner", {}).get("report") if match_filters_per_doctype: for row in data: if shared and row[linked_doctypes[ref_doctype]] in shared: result.append(row) - elif has_match(row, linked_doctypes, match_filters_per_doctype): + elif has_match(row, linked_doctypes, match_filters_per_doctype, ref_doctype, if_owner, columns_dict): result.append(row) else: result = list(data) return result -def has_match(row, linked_doctypes, doctype_match_filters): +def has_match(row, linked_doctypes, doctype_match_filters, ref_doctype, if_owner, columns_dict): + """Returns True if after evaluating permissions for each linked doctype + - There is an owner match for the ref_doctype + - `and` There is a user permission match for all linked doctypes + + Returns True if the row is empty + + Note: + Each doctype could have multiple conflicting user permission doctypes. + Hence even if one of the sets allows a match, it is true. + This behavior is equivalent to the trickling of user permissions of linked doctypes to the ref doctype. + """ resultant_match = True if not row: @@ -167,20 +183,33 @@ def has_match(row, linked_doctypes, doctype_match_filters): for doctype, filter_list in doctype_match_filters.items(): matched_for_doctype = False - for match_filters in filter_list: - match = True - for dt, idx in linked_doctypes.items(): - if dt in match_filters and row[idx] not in match_filters[dt]: - match = False + if doctype==ref_doctype and if_owner: + idx = linked_doctypes.get("User") + if (idx is not None + and row[idx]==frappe.session.user + and columns_dict[idx]==columns_dict.get("owner")): + # owner match is true + matched_for_doctype = True + + if not matched_for_doctype: + for match_filters in filter_list: + match = True + for dt, idx in linked_doctypes.items(): + # case handled above + if dt=="User" and columns_dict[idx]==columns_dict.get("owner"): + continue + + if dt in match_filters and row[idx] not in match_filters[dt]: + match = False + break + + # each doctype could have multiple conflicting user permission doctypes, hence using OR + # so that even if one of the sets allows a match, it is true + matched_for_doctype = matched_for_doctype or match + + if matched_for_doctype: break - # each doctype could have multiple conflicting user permission doctypes, hence using OR - # so that even if one of the sets allows a match, it is true - matched_for_doctype = matched_for_doctype or match - - if matched_for_doctype: - break - # each doctype's user permissions should match the row! hence using AND resultant_match = resultant_match and matched_for_doctype @@ -192,16 +221,16 @@ def has_match(row, linked_doctypes, doctype_match_filters): def get_linked_doctypes(columns, data): linked_doctypes = {} - for idx, col in enumerate(columns): - if isinstance(col, basestring): - col = col.split(":") - if len(col) > 1 and col[1].startswith("Link"): - link_dt = col[1].split("/")[1] - linked_doctypes[link_dt] = idx + columns_dict = get_columns_dict(columns) - # dict - elif col.get("fieldtype")=="Link" and col.get("options"): - linked_doctypes[col["options"]] = col["fieldname"] + for idx, col in enumerate(columns): + df = columns_dict[idx] + if df.get("fieldtype")=="Link": + if isinstance(col, basestring): + linked_doctypes[df["options"]] = idx + else: + # dict + linked_doctypes[df["options"]] = df["fieldname"] # remove doctype if column is empty for doctype, key in linked_doctypes.items(): @@ -210,6 +239,35 @@ def get_linked_doctypes(columns, data): return linked_doctypes +def get_columns_dict(columns): + """Returns a dict with column docfield values as dict + The keys for the dict are both idx and fieldname, + so either index or fieldname can be used to search for a column's docfield properties + """ + columns_dict = {} + for idx, col in enumerate(columns): + col_dict = {} + + # string + if isinstance(col, basestring): + col = col.split(":") + if len(col) > 1: + if "/" in col[1]: + col_dict["fieldtype"], col_dict["options"] = col[1].split("/") + else: + col_dict["fieldtype"] = col[1] + + col_dict["fieldname"] = col[0].lower() + + # dict + else: + col_dict.update(col) + + columns_dict[idx] = col_dict + columns_dict[col_dict["fieldname"]] = col_dict + + return columns_dict + def get_user_match_filters(doctypes, ref_doctype): match_filters = {} diff --git a/frappe/email/bulk.py b/frappe/email/bulk.py index 0575d15d3b..280e2d6d60 100644 --- a/frappe/email/bulk.py +++ b/frappe/email/bulk.py @@ -72,13 +72,13 @@ def send(recipients=None, sender=None, subject=None, message=None, reference_doc unsubscribe_method, unsubscribe_params) # add to queue - email_content = add_unsubscribe_link(email_content, email, reference_doctype, reference_name, - unsubscribe_url, unsubscribe_message) + email_content = add_unsubscribe_link(email_content, email, reference_doctype, + reference_name, unsubscribe_url, unsubscribe_message) - email_text_context += "\n" + _("Unsubscribe link: {0}").format(unsubscribe_url) + email_text_context += "\n" + _("This email was sent to {0}. To unsubscribe click on this link: {1}").format(email, unsubscribe_url) - add(email, sender, subject, email_content, email_text_context, reference_doctype, reference_name, attachments, reply_to, - cc, message_id, send_after) + add(email, sender, subject, email_content, email_text_context, reference_doctype, + reference_name, attachments, reply_to, cc, message_id, send_after) def add(email, sender, subject, formatted, text_content=None, reference_doctype=None, reference_name=None, attachments=None, reply_to=None, @@ -112,7 +112,8 @@ def check_bulk_limit(recipients): # No limit for own email settings smtp_server = SMTPServer() - if smtp_server.email_account and not getattr(smtp_server.email_account, + + if smtp_server.email_account and getattr(smtp_server.email_account, "from_site_config", False) or frappe.flags.in_test: monthly_bulk_mail_limit = frappe.conf.get('monthly_bulk_mail_limit') or 500 @@ -121,11 +122,12 @@ def check_bulk_limit(recipients): BulkLimitCrossedError) def add_unsubscribe_link(message, email, reference_doctype, reference_name, unsubscribe_url, unsubscribe_message): - unsubscribe_link = """
- - {unsubscribe_message} + unsubscribe_link = """
+ {email}. {unsubscribe_message}.
""".format(unsubscribe_url = unsubscribe_url, + email= _("This email was sent to {0}").format(email), unsubscribe_message = unsubscribe_message or _("Unsubscribe from this list")) message = message.replace("", unsubscribe_link) @@ -164,7 +166,7 @@ def unsubscribe(doctype, name, email): return_unsubscribed_page(email, doctype, name) def return_unsubscribed_page(email, doctype, name): - frappe.respond_as_web_page(_("Unsubscribed"), _("{0} has has left the conversation in {1} {2}").format(email, _(doctype), name)) + frappe.respond_as_web_page(_("Unsubscribed"), _("{0} has left the conversation in {1} {2}").format(email, _(doctype), name)) def flush(from_test=False): """flush email queue, every time: called from scheduler""" @@ -176,6 +178,9 @@ def flush(from_test=False): msgprint(_("Emails are muted")) from_test = True + frappe.db.sql("""update `tabBulk Email` set status='Expired' + where datediff(curdate(), creation) > 3""", auto_commit=auto_commit) + for i in xrange(500): email = frappe.db.sql("""select * from `tabBulk Email` where status='Not Sent' and ifnull(send_after, "2000-01-01 00:00:00") < %s diff --git a/frappe/email/doctype/bulk_email/bulk_email.json b/frappe/email/doctype/bulk_email/bulk_email.json index bff64320cd..e4807eba64 100644 --- a/frappe/email/doctype/bulk_email/bulk_email.json +++ b/frappe/email/doctype/bulk_email/bulk_email.json @@ -73,13 +73,14 @@ "icon": "icon-envelope", "idx": 1, "in_create": 1, - "modified": "2015-04-01 10:00:20.892939", + "modified": "2015-05-21 07:26:13.627637", "modified_by": "Administrator", "module": "Email", "name": "Bulk Email", "owner": "Administrator", "permissions": [ { + "delete": 1, "email": 1, "permlevel": 0, "print": 1, diff --git a/frappe/email/doctype/email_account/email_account.js b/frappe/email/doctype/email_account/email_account.js index ae4ba30e58..ad369befe1 100644 --- a/frappe/email/doctype/email_account/email_account.js +++ b/frappe/email/doctype/email_account/email_account.js @@ -38,9 +38,15 @@ frappe.ui.form.on("Email Account", { + toTitle(frm.doc.email_id.split("@")[0].replace(/[._]/g, " "))); } }, + enable_incoming: function(frm) { + frm.set_df_property("append_to", "reqd", frm.doc.enable_incoming); + }, onload: function(frm) { frm.set_df_property("append_to", "only_select", true); frm.set_query("append_to", "frappe.email.doctype.email_account.email_account.get_append_to"); + }, + refresh: function(frm) { + frm.set_df_property("append_to", "reqd", frm.doc.enable_incoming); } }); diff --git a/frappe/email/doctype/email_account/email_account.json b/frappe/email/doctype/email_account/email_account.json index a03fa043ba..3e0e666bc0 100644 --- a/frappe/email/doctype/email_account/email_account.json +++ b/frappe/email/doctype/email_account/email_account.json @@ -44,6 +44,21 @@ "search_index": 0, "set_only_once": 0 }, + { + "fieldname": "login_id_is_different", + "fieldtype": "Check", + "label": "Login Id is Different", + "permlevel": 0, + "precision": "" + }, + { + "depends_on": "login_id_is_different", + "fieldname": "login_id", + "fieldtype": "Data", + "label": "Login Id", + "permlevel": 0, + "precision": "" + }, { "allow_on_submit": 0, "fieldname": "password", @@ -276,6 +291,15 @@ "permlevel": 0, "precision": "" }, + { + "depends_on": "enable_outgoing", + "description": "Uses the Email ID mentioned in this Account as the Sender for all emails sent using this Account. ", + "fieldname": "always_use_account_email_id_as_sender", + "fieldtype": "Check", + "label": "Always use Account's Email ID as Sender", + "permlevel": 0, + "precision": "" + }, { "allow_on_submit": 0, "fieldname": "signature_section", @@ -364,6 +388,7 @@ { "allow_on_submit": 0, "depends_on": "enable_auto_reply", + "description": "ProTip: Add Reference: {{ reference_doctype }} {{ reference_name }} to send document reference", "fieldname": "auto_reply_message", "fieldtype": "Text Editor", "hidden": 0, @@ -404,7 +429,7 @@ "is_submittable": 0, "issingle": 0, "istable": 0, - "modified": "2015-04-21 15:31:02.269145", + "modified": "2015-07-16 10:11:06.466258", "modified_by": "Administrator", "module": "Email", "name": "Email Account", diff --git a/frappe/email/doctype/email_account/email_account.py b/frappe/email/doctype/email_account/email_account.py index d3f681d71e..2ed930386a 100644 --- a/frappe/email/doctype/email_account/email_account.py +++ b/frappe/email/doctype/email_account/email_account.py @@ -5,7 +5,9 @@ from __future__ import unicode_literals import frappe from frappe import _ from frappe.model.document import Document -from frappe.utils import validate_email_add, cint, get_datetime, DATE_FORMAT +from frappe.utils import validate_email_add, cint, get_datetime, DATE_FORMAT, strip, comma_or +from frappe.utils.user import is_system_user +from frappe.utils.jinja import render_template from frappe.email.smtp import SMTPServer from frappe.email.receive import POP3Server, Email from poplib import error_proto @@ -30,9 +32,18 @@ class EmailAccount(Document): if self.email_id: validate_email_add(self.email_id, True) + if self.login_id_is_different: + if not self.login_id: + frappe.throw(_("Login Id is required")) + else: + self.login_id = None + if frappe.local.flags.in_patch or frappe.local.flags.in_test: return + if self.enable_incoming and not self.append_to: + frappe.throw(_("Append To is mandatory for incoming mails")) + if not frappe.local.flags.in_install and not frappe.local.flags.in_patch: if self.enable_incoming: self.get_pop3() @@ -44,6 +55,11 @@ class EmailAccount(Document): for e in self.get_unreplied_notification_emails(): validate_email_add(e, True) + if self.enable_incoming and self.append_to: + valid_doctypes = [d[0] for d in get_append_to()] + if self.append_to not in valid_doctypes: + frappe.throw(_("Append To can be one of {0}").format(comma_or(valid_doctypes))) + def on_update(self): """Check there is only one default of each type.""" self.there_must_be_only_one_default() @@ -67,7 +83,8 @@ class EmailAccount(Document): if not self.smtp_server: frappe.throw(_("{0} is required").format("SMTP Server")) - server = SMTPServer(login = self.email_id, + server = SMTPServer(login = getattr(self, "login_id", None) \ + or self.email_id, password = self.password, server = self.smtp_server, port = cint(self.smtp_port), @@ -80,7 +97,7 @@ class EmailAccount(Document): args = { "host": self.pop3_server, "use_ssl": self.use_ssl, - "username": self.email_id, + "username": getattr(self, "login_id", None) or self.email_id, "password": self.password } @@ -171,36 +188,39 @@ class EmailAccount(Document): sender_field = None if in_reply_to: - if "@" in in_reply_to: + if "@{0}".format(frappe.local.site) in in_reply_to: # reply to a communication sent from the system - in_reply_to = in_reply_to.split("@", 1)[0] + in_reply_to, domain = in_reply_to.split("@", 1) + if frappe.db.exists("Communication", in_reply_to): parent = frappe.get_doc("Communication", in_reply_to) if parent.reference_name: - if self.append_to: - # parent must reference only if name matches - if parent.reference_doctype==self.append_to: - # parent same as parent of last communication - parent = frappe.get_doc(parent.reference_doctype, - parent.reference_name) - else: - parent = frappe.get_doc(parent.reference_doctype, - parent.reference_name) + parent = frappe.get_doc(parent.reference_doctype, + parent.reference_name) - if not parent and self.append_to and subject_field and sender_field: - # try and match by subject and sender - # if sent by same sender with same subject, - # append it to old coversation + if not parent and self.append_to and sender_field: + if subject_field: + # try and match by subject and sender + # if sent by same sender with same subject, + # append it to old coversation + subject = strip(re.sub("^\s*(Re|RE)[^:]*:\s*", "", email.subject)) - subject = re.sub("Re[^:]*:\s*", "", email.subject) + parent = frappe.db.get_all(self.append_to, filters={ + sender_field: email.from_email, + subject_field: ("like", "%{0}%".format(subject)), + "creation": (">", (get_datetime() - relativedelta(days=10)).strftime(DATE_FORMAT)) + }, fields="name") - parent = frappe.db.get_all(self.append_to, filters={ - sender_field: email.from_email, - subject_field: ("like", "%{0}%".format(subject)), - "creation": (">", (get_datetime() - relativedelta(days=10)).strftime(DATE_FORMAT)) - }, fields="name") + # match only subject field + # when the from_email is of a user in the system + # and subject is atleast 10 chars long + if not parent and len(subject) > 10 and is_system_user(email.from_email): + parent = frappe.db.get_all(self.append_to, filters={ + subject_field: ("like", "%{0}%".format(subject)), + "creation": (">", (get_datetime() - relativedelta(days=10)).strftime(DATE_FORMAT)) + }, fields="name") if parent: parent = frappe.get_doc(self.append_to, parent[0].name) @@ -218,8 +238,17 @@ class EmailAccount(Document): parent.flags.ignore_mandatory = True - parent.insert(ignore_permissions=True) + try: + parent.insert(ignore_permissions=True) + except frappe.DuplicateEntryError: + # try and find matching parent + parent_name = frappe.db.get_value(self.append_to, {sender_field: email.from_email}) + if parent_name: + parent.name = parent_name + else: + parent = None + # NOTE if parent isn't found and there's no subject match, it is likely that it is a new conversation thread and hence is_first = True communication.is_first = True if parent: @@ -228,14 +257,14 @@ class EmailAccount(Document): def send_auto_reply(self, communication, email): """Send auto reply if set.""" - if self.auto_reply_message: + if self.enable_auto_reply: communication.set_incoming_outgoing_accounts() frappe.sendmail(recipients = [email.from_email], sender = self.email_id, reply_to = communication.incoming_email_account, subject = _("Re: ") + communication.subject, - content = self.auto_reply_message or \ + content = render_template(self.auto_reply_message or "", communication.as_dict()) or \ frappe.get_template("templates/emails/auto_reply.html").render(communication.as_dict()), reference_doctype = communication.reference_doctype, reference_name = communication.reference_name, @@ -254,7 +283,7 @@ class EmailAccount(Document): frappe.db.sql("update `tabCommunication` set email_account='' where email_account=%s", self.name) @frappe.whitelist() -def get_append_to(doctype, txt, searchfield, start, page_len, filters): +def get_append_to(doctype=None, txt=None, searchfield=None, start=None, page_len=None, filters=None): if not txt: txt = "" return [[d] for d in frappe.get_hooks("email_append_to") if txt in d] diff --git a/frappe/email/doctype/email_account/email_account_list.js b/frappe/email/doctype/email_account/email_account_list.js index 2eb5cbe550..f3bbd99e9b 100644 --- a/frappe/email/doctype/email_account/email_account_list.js +++ b/frappe/email/doctype/email_account/email_account_list.js @@ -19,3 +19,5 @@ frappe.listview_settings["Email Account"] = { } } } + +frappe.help.youtube_id["Email Account"] = "YFYe0DrB95o"; diff --git a/frappe/email/doctype/email_account/test_email_account.py b/frappe/email/doctype/email_account/test_email_account.py index f09ae9a0bd..c8c8839e19 100644 --- a/frappe/email/doctype/email_account/test_email_account.py +++ b/frappe/email/doctype/email_account/test_email_account.py @@ -90,7 +90,7 @@ class TestEmailAccount(unittest.TestCase): # send sent_name = make(subject = "Test", content="test content", recipients="test_receiver@example.com", sender="test@example.com", - send_email=True) + send_email=True)["name"] sent_mail = email.message_from_string(frappe.get_last_doc("Bulk Email").message) with open(os.path.join(os.path.dirname(__file__), "test_mails", "reply-1.raw"), "r") as f: diff --git a/frappe/email/doctype/email_alert/email_alert.json b/frappe/email/doctype/email_alert/email_alert.json index bc60787f95..ed9cc746bc 100644 --- a/frappe/email/doctype/email_alert/email_alert.json +++ b/frappe/email/doctype/email_alert/email_alert.json @@ -129,7 +129,7 @@ "fieldname": "message_examples", "fieldtype": "HTML", "label": "Message Examples", - "options": "
Message Example (Markdown)
\n
Transaction {{ doc.name }} has exceeded Due Date. Please take relevant action\n\n#### Details\n\nCustomer: {{ doc.customer }}\nAmount: {{ doc.total_amount }}
", + "options": "
Message Example
\n\n
\n

Order Overdue

\n\n

Transaction {{ doc.name }} has exceeded Due Date. Please take necessary action.

\n\n

Details

\n\n\n
", "permlevel": 0 }, { @@ -141,7 +141,7 @@ } ], "icon": "icon-envelope", - "modified": "2015-03-25 06:20:07.472953", + "modified": "2015-07-09 00:27:00.169741", "modified_by": "Administrator", "module": "Email", "name": "Email Alert", diff --git a/frappe/email/email_body.py b/frappe/email/email_body.py index 1ee0135e8d..c178cc21ff 100644 --- a/frappe/email/email_body.py +++ b/frappe/email/email_body.py @@ -5,7 +5,7 @@ from __future__ import unicode_literals import frappe from frappe.utils.pdf import get_pdf from frappe.email.smtp import get_outgoing_email_account -from frappe.utils.data import get_url, scrub_urls, strip, expand_relative_urls +from frappe.utils import get_url, scrub_urls, strip, expand_relative_urls, cint import email.utils from markdown2 import markdown @@ -211,9 +211,11 @@ def get_formatted_html(subject, message, footer=None, print_html=None): # imported here to avoid cyclic import message = scrub_urls(message) + email_account = get_outgoing_email_account(False) rendered_email = frappe.get_template("templates/emails/standard.html").render({ "content": message, - "footer": get_footer(footer), + "signature": get_signature(email_account), + "footer": get_footer(email_account, footer), "title": subject, "print_html": print_html, "subject": subject @@ -221,21 +223,29 @@ def get_formatted_html(subject, message, footer=None, print_html=None): return rendered_email -def get_footer(footer=None): +def get_signature(email_account): + if email_account and email_account.add_signature and email_account.signature: + return "

" + email_account.signature + else: + return "" + +def get_footer(email_account, footer=None): """append a footer (signature)""" footer = footer or "" - email_account = get_outgoing_email_account(False) - - if email_account and email_account.add_signature and email_account.signature: - footer += email_account.signature - if email_account and email_account.footer: footer += email_account.footer - else: - for default_mail_footer in frappe.get_hooks("default_mail_footer"): - footer += default_mail_footer footer += "" + company_address = frappe.db.get_default("email_footer_address") + + if company_address: + footer += '
{0}
'\ + .format(company_address.replace("\n", "
")) + + if not cint(frappe.db.get_default("disable_standard_email_footer")): + for default_mail_footer in frappe.get_hooks("default_mail_footer"): + footer += default_mail_footer + return footer diff --git a/frappe/email/receive.py b/frappe/email/receive.py index 0bf5880458..5078cfeea9 100644 --- a/frappe/email/receive.py +++ b/frappe/email/receive.py @@ -44,28 +44,37 @@ class POP3Server: self.pop.user(self.settings.username) self.pop.pass_(self.settings.password) + + # connection established! + return True + except _socket.error: # Invalid mail server -- due to refusing connection frappe.msgprint(_('Invalid Mail Server. Please rectify and try again.')) raise + except poplib.error_proto, e: - if not "SYS/TEMP" in str(e): + if self.is_temporary_system_problem(e): + return False + + else: frappe.msgprint(_('Invalid User Name or Support Password. Please rectify and try again.')) - raise + raise def get_messages(self): """Returns new email messages in a list.""" if not self.check_mails(): return # nothing to do - self.latest_messages = [] - frappe.db.commit() - self.connect() + + if not self.connect(): + return [] try: # track if errors arised self.errors = False + self.latest_messages = [] pop_list = self.pop.list()[1] num = num_copy = len(pop_list) @@ -138,6 +147,16 @@ class POP3Server: def has_login_limit_exceeded(self, e): return "-ERR Exceeded the login limit" in strip(cstr(e.message)) + def is_temporary_system_problem(self, e): + messages = ( + "-ERR [SYS/TEMP] Temporary system problem. Please try again later.", + "Connection timed out", + ) + for message in messages: + if message in strip(cstr(e.message)): + return True + return False + def validate_pop(self, pop_meta): # throttle based on email size if not self.max_email_size: diff --git a/frappe/email/smtp.py b/frappe/email/smtp.py index cfda49a26f..714d64423d 100644 --- a/frappe/email/smtp.py +++ b/frappe/email/smtp.py @@ -21,8 +21,8 @@ def send(email, append_to=None): try: smtpserver = SMTPServer(append_to=append_to) - if hasattr(smtpserver, "always_use_login_id_as_sender") and \ - cint(smtpserver.always_use_login_id_as_sender) and smtpserver.login: + if hasattr(smtpserver, "always_use_account_email_id_as_sender") and \ + cint(smtpserver.always_use_account_email_id_as_sender) and smtpserver.login: if not email.reply_to: email.reply_to = email.sender email.sender = smtpserver.login @@ -55,7 +55,8 @@ def get_outgoing_email_account(raise_exception_not_set=True, append_to=None): email_account = get_default_outgoing_email_account(raise_exception_not_set=raise_exception_not_set) if not email_account and raise_exception_not_set: - frappe.throw(_("Please setup default Email Account from Setup > Email > Email Account")) + frappe.throw(_("Please setup default Email Account from Setup > Email > Email Account"), + frappe.OutgoingEmailError) frappe.local.outgoing_email_account[append_to or "default"] = email_account @@ -114,11 +115,13 @@ class SMTPServer: self.email_account = get_outgoing_email_account(raise_exception_not_set=False, append_to=append_to) if self.email_account: self.server = self.email_account.smtp_server - self.login = self.email_account.email_id + self.login = getattr(self.email_account, "login_id", None) \ + or self.email_account.email_id self.password = self.email_account.password self.port = self.email_account.smtp_port self.use_ssl = self.email_account.use_tls self.sender = self.email_account.email_id + self.always_use_account_email_id_as_sender = self.email_account.get("always_use_account_email_id_as_sender") @property def sess(self): diff --git a/frappe/geo/doctype/currency/currency.json b/frappe/geo/doctype/currency/currency.json index 48bb30ac26..e9a4dffad0 100644 --- a/frappe/geo/doctype/currency/currency.json +++ b/frappe/geo/doctype/currency/currency.json @@ -58,7 +58,7 @@ "icon": "icon-bitcoin", "idx": 1, "in_create": 0, - "modified": "2015-02-05 05:11:36.294972", + "modified": "2015-07-13 05:01:14.014983", "modified_by": "Administrator", "module": "Geo", "name": "Currency", @@ -81,12 +81,38 @@ { "apply_user_permissions": 1, "delete": 0, - "email": 1, + "email": 0, "permlevel": 0, - "print": 1, + "print": 0, "read": 1, - "report": 1, - "role": "All" + "report": 0, + "role": "Accounts User" + }, + { + "create": 0, + "delete": 0, + "email": 0, + "export": 0, + "permlevel": 0, + "print": 0, + "read": 1, + "report": 0, + "role": "Sales User", + "share": 0, + "write": 0 + }, + { + "create": 0, + "delete": 0, + "email": 0, + "export": 0, + "permlevel": 0, + "print": 0, + "read": 1, + "report": 0, + "role": "Purchase User", + "share": 0, + "write": 0 } ], "read_only": 0 diff --git a/frappe/handler.py b/frappe/handler.py index 821d7cc591..25e28a063d 100755 --- a/frappe/handler.py +++ b/frappe/handler.py @@ -31,8 +31,7 @@ def logout(): def web_logout(): frappe.local.login_manager.logout() frappe.db.commit() - frappe.respond_as_web_page("Logged Out", """

You have been logged out.

-

Back to Home

""") + frappe.respond_as_web_page("Logged Out", """

Back to Home

""") @frappe.whitelist(allow_guest=True) def run_custom_method(doctype, name, custom_method): diff --git a/frappe/hooks.py b/frappe/hooks.py index b0177cb1ce..a5c27a9962 100644 --- a/frappe/hooks.py +++ b/frappe/hooks.py @@ -2,12 +2,35 @@ from __future__ import unicode_literals app_name = "frappe" app_title = "Frappe Framework" app_publisher = "Frappe Technologies Pvt. Ltd." -app_description = "Full Stack Web Application Framework in Python" -app_icon = "octicon octicon-circuit-board" -app_version = "5.0.9" -app_color = "orange" +app_description = """## Frappe Framework -app_email = "support@frappe.io" +Frappe is a full stack web application framework written in Python, +Javascript, HTML/CSS with MySQL as the backend. It was built for ERPNext +but is pretty generic and can be used to build database driven apps. + +The key differece in Frappe compared to other frameworks is that Frappe +is that meta-data is also treated as data and is used to build front-ends +very easily. Frappe comes with a full blown admin UI called the **Desk** +that handles forms, navigation, lists, menus, permissions, file attachment +and much more out of the box. + +Frappe also has a plug-in architecture that can be used to build plugins +to ERPNext. + +### Links: + +- Project Home: [https://frappe.io](https://frappe.io) +- Tutorial: [https://frappe.io/tutorial](https://frappe.io/tutorial) +- GitHub: [https://github.com/frappe/frappe](https://github.com/frappe/frappe) +- Forum: [https://discuss.erpnext.com](https://discuss.erpnext.com) +""" + +app_icon = "octicon octicon-circuit-board" +app_version = "5.1.3" +app_color = "orange" +github_link = "https://github.com/frappe/frappe" + +app_email = "info@frappe.io" before_install = "frappe.utils.install.before_install" after_install = "frappe.utils.install.after_install" @@ -35,8 +58,7 @@ web_include_js = [ bootstrap = "assets/frappe/css/bootstrap.css" web_include_css = [ - "assets/css/frappe-web.css", - "website_theme.css" + "assets/css/frappe-web.css" ] website_route_rules = [ {"from_route": "/blog", "to_route": "Blog Post"}, @@ -59,6 +81,8 @@ website_generators = ["Web Page", "Blog Post", "Blog Category", "Web Form"] email_append_to = ["Event", "ToDo", "Communication"] +calendars = ["Event"] + # login on_session_creation = [ @@ -119,6 +143,7 @@ scheduler_events = { "daily": [ "frappe.email.bulk.clear_outbox", "frappe.desk.notifications.clear_notifications", + "frappe.core.doctype.scheduler_log.scheduler_log.set_old_logs_as_seen", "frappe.desk.doctype.event.event.send_event_digest", "frappe.sessions.clear_expired_sessions", "frappe.email.doctype.email_alert.email_alert.trigger_daily_alerts", diff --git a/frappe/installer.py b/frappe/installer.py index 95282ee54f..4c3c10e538 100755 --- a/frappe/installer.py +++ b/frappe/installer.py @@ -231,11 +231,12 @@ def add_module_defs(app): def remove_missing_apps(): apps = ('frappe_subscription', 'shopping_cart') - installed_apps = frappe.get_installed_apps() + installed_apps = json.loads(frappe.db.get_global("installed_apps") or "[]") for app in apps: if app in installed_apps: try: importlib.import_module(app) + except ImportError: installed_apps.remove(app) frappe.db.set_global("installed_apps", json.dumps(installed_apps)) diff --git a/frappe/model/__init__.py b/frappe/model/__init__.py index 642952069c..0560043894 100644 --- a/frappe/model/__init__.py +++ b/frappe/model/__init__.py @@ -72,111 +72,3 @@ def delete_fields(args_dict, delete=0): ", ".join(["DROP COLUMN `%s`" % f for f in fields if f in existing_fields]) frappe.db.commit() frappe.db.sql(query) - -def rename_field(doctype, old_fieldname, new_fieldname): - """This functions assumes that doctype is already synced""" - - meta = frappe.get_meta(doctype, cached=False) - new_field = meta.get_field(new_fieldname) - if not new_field: - print "rename_field: " + (new_fieldname) + " not found in " + doctype - return - - if new_field.fieldtype == "Table": - # change parentfield of table mentioned in options - frappe.db.sql("""update `tab%s` set parentfield=%s - where parentfield=%s""" % (new_field.options.split("\n")[0], "%s", "%s"), - (new_fieldname, old_fieldname)) - elif new_field.fieldtype not in no_value_fields: - if meta.issingle: - frappe.db.sql("""update `tabSingles` set field=%s - where doctype=%s and field=%s""", - (new_fieldname, doctype, old_fieldname)) - else: - # copy field value - frappe.db.sql("""update `tab%s` set `%s`=`%s`""" % \ - (doctype, new_fieldname, old_fieldname)) - - update_reports(doctype, old_fieldname, new_fieldname) - update_users_report_view_settings(doctype, old_fieldname, new_fieldname) - - # update in property setter - frappe.db.sql("""update `tabProperty Setter` set field_name = %s - where doc_type=%s and field_name=%s""", (new_fieldname, doctype, old_fieldname)) - -def update_reports(doctype, old_fieldname, new_fieldname): - def _get_new_sort_by(report_dict, report, key): - sort_by = report_dict.get(key) or "" - if sort_by: - sort_by = sort_by.split(".") - if len(sort_by) > 1: - if sort_by[0]==doctype and sort_by[1]==old_fieldname: - sort_by = doctype + "." + new_fieldname - report_dict["updated"] = True - elif report.ref_doctype == doctype and sort_by[0]==old_fieldname: - sort_by = doctype + "." + new_fieldname - report_dict["updated"] = True - - if isinstance(sort_by, list): - sort_by = '.'.join(sort_by) - - return sort_by - - reports = frappe.db.sql("""select name, ref_doctype, json from tabReport - where report_type = 'Report Builder' and ifnull(is_standard, 'No') = 'No' - and json like %s and json like %s""", - ('%%%s%%' % old_fieldname , '%%%s%%' % doctype), as_dict=True) - - for r in reports: - report_dict = json.loads(r.json) - - # update filters - new_filters = [] - for f in report_dict.get("filters"): - if f[0] == doctype and f[1] == old_fieldname: - new_filters.append([doctype, new_fieldname, f[2], f[3]]) - report_dict["updated"] = True - else: - new_filters.append(f) - - # update columns - new_columns = [] - for c in report_dict.get("columns"): - if c[0] == old_fieldname and c[1] == doctype: - new_columns.append([new_fieldname, doctype]) - report_dict["updated"] = True - else: - new_columns.append(c) - - # update sort by - new_sort_by = _get_new_sort_by(report_dict, r, "sort_by") - new_sort_by_next = _get_new_sort_by(report_dict, r, "sort_by_next") - - if report_dict.get("updated"): - new_val = json.dumps({ - "filters": new_filters, - "columns": new_columns, - "sort_by": new_sort_by, - "sort_order": report_dict.get("sort_order"), - "sort_by_next": new_sort_by_next, - "sort_order_next": report_dict.get("sort_order_next") - }) - - frappe.db.sql("""update `tabReport` set `json`=%s where name=%s""", (new_val, r.name)) - -def update_users_report_view_settings(doctype, ref_fieldname, new_fieldname): - user_report_cols = frappe.db.sql("""select defkey, defvalue from `tabDefaultValue` where - defkey like '_list_settings:%'""") - for key, value in user_report_cols: - new_columns = [] - columns_modified = False - for field, field_doctype in json.loads(value): - if field == ref_fieldname and field_doctype == doctype: - new_columns.append([new_fieldname, field_doctype]) - columns_modified=True - else: - new_columns.append([field, field_doctype]) - - if columns_modified: - frappe.db.sql("""update `tabDefaultValue` set defvalue=%s - where defkey=%s""" % ('%s', '%s'), (json.dumps(new_columns), key)) diff --git a/frappe/model/base_document.py b/frappe/model/base_document.py index ddb10f0e5f..8fddfe3a20 100644 --- a/frappe/model/base_document.py +++ b/frappe/model/base_document.py @@ -261,7 +261,7 @@ class BaseDocument(object): return type, value, traceback = sys.exc_info() frappe.msgprint(_("Duplicate name {0} {1}").format(self.doctype, self.name)) - raise frappe.NameError, (self.doctype, self.name, e), traceback + raise frappe.DuplicateEntryError, (self.doctype, self.name, e), traceback else: raise @@ -453,7 +453,7 @@ class BaseDocument(object): return self._precision[cache_key][fieldname] - def get_formatted(self, fieldname, doc=None, currency=None): + def get_formatted(self, fieldname, doc=None, currency=None, absolute_value=False): from frappe.utils.formatters import format_value df = self.meta.get_field(fieldname) @@ -461,7 +461,10 @@ class BaseDocument(object): from frappe.model.meta import get_default_df df = get_default_df(fieldname) - return format_value(self.get(fieldname), df=df, doc=doc or self, currency=currency) + val = self.get(fieldname) + if absolute_value and isinstance(val, (int, float)): + val = abs(self.get(fieldname)) + return format_value(val, df=df, doc=doc or self, currency=currency) def is_print_hide(self, fieldname, df=None, for_print=True): """Returns true if fieldname is to be hidden for print. @@ -524,7 +527,7 @@ class BaseDocument(object): def cast(self, val, df): if df.fieldtype in ("Currency", "Float", "Percent"): - val = flt(val, self.precision(df.fieldname)) + val = flt(val) elif df.fieldtype in ("Int", "Check"): val = cint(val) diff --git a/frappe/model/db_query.py b/frappe/model/db_query.py index 0d33ef5ffc..a1d21275dd 100644 --- a/frappe/model/db_query.py +++ b/frappe/model/db_query.py @@ -270,7 +270,6 @@ class DatabaseQuery(object): """add match conditions if applicable""" self.match_filters = [] self.match_conditions = [] - only_if_shared = False if not self.tables: self.extract_tables() @@ -283,7 +282,7 @@ class DatabaseQuery(object): if not meta.istable and not role_permissions.get("read") and not self.flags.ignore_permissions: only_if_shared = True if not self.shared: - frappe.throw(_("No permission to read {0}").format(self.doctype)) + frappe.throw(_("No permission to read {0}").format(self.doctype), frappe.PermissionError) else: self.conditions.append(self.get_share_condition()) @@ -295,9 +294,9 @@ class DatabaseQuery(object): self.add_user_permissions(user_permissions, user_permission_doctypes=role_permissions.get("user_permission_doctypes").get("read")) - # share is an OR condition, if there is a role permission - if not only_if_shared and self.shared: - self.or_conditions.append(self.get_share_condition()) + if role_permissions.get("if_owner", {}).get("read"): + self.match_conditions.append("`tab{0}`.owner = '{1}'".format(self.doctype, + frappe.db.escape(frappe.session.user))) if as_condition: conditions = "" @@ -309,6 +308,11 @@ class DatabaseQuery(object): if doctype_conditions: conditions += (' and ' + doctype_conditions) if conditions else doctype_conditions + # share is an OR condition, if there is a role permission + if not only_if_shared and self.shared and conditions: + conditions = "({conditions}) or ({shared_condition})".format( + conditions=conditions, shared_condition=self.get_share_condition()) + return conditions else: diff --git a/frappe/model/db_schema.py b/frappe/model/db_schema.py index e94eb7c586..196420e472 100644 --- a/frappe/model/db_schema.py +++ b/frappe/model/db_schema.py @@ -234,7 +234,14 @@ class DbTable: query.append('alter column `{}` set default {}'.format(col.fieldname, col_default)) if query: - frappe.db.sql("alter table `{}` {}".format(self.name, ", ".join(query))) + try: + frappe.db.sql("alter table `{}` {}".format(self.name, ", ".join(query))) + except Exception, e: + # sanitize + if e.args[0]==1060: + frappe.throw(str(e)) + else: + raise e class DbColumn: def __init__(self, table, fieldname, fieldtype, length, default, @@ -302,17 +309,34 @@ class DbColumn: def default_changed(self, current_def): if "decimal" in current_def['type']: - try: - if current_def['default'] in ("", None) and self.default in ("", None): - # both none, empty - return False - else: - return float(current_def['default'])!=float(self.default) - except TypeError: - return True + return self.default_changed_for_decimal(current_def) else: return current_def['default'] != self.default + def default_changed_for_decimal(self, current_def): + try: + if current_def['default'] in ("", None) and self.default in ("", None): + # both none, empty + return False + + elif current_def['default'] in ("", None): + try: + # check if new default value is valid + float(self.default) + return True + except ValueError: + return False + + elif self.default in ("", None): + # new default value is empty + return True + + else: + # NOTE float() raise ValueError when "" or None is passed + return float(current_def['default'])!=float(self.default) + except TypeError: + return True + class DbManager: """ Basically, a wrapper for oft-used mysql commands. like show tables,databases, variables etc... @@ -452,4 +476,3 @@ def add_column(doctype, column_name, fieldtype, precision=None): frappe.db.commit() frappe.db.sql("alter table `tab%s` add column %s %s" % (doctype, column_name, get_definition(fieldtype, precision))) - diff --git a/frappe/model/document.py b/frappe/model/document.py index 1cf8ce5703..547bdc6932 100644 --- a/frappe/model/document.py +++ b/frappe/model/document.py @@ -147,7 +147,9 @@ class Document(BaseDocument): def raise_no_permission_to(self, perm_type): """Raise `frappe.PermissionError`.""" - raise frappe.PermissionError("No permission to {} {} {}".format(perm_type, self.doctype, self.name or "")) + msg = _("No permission to {0} {1} {2}".format(perm_type, self.doctype, self.name or "")) + frappe.msgprint(msg) + raise frappe.PermissionError(msg) def insert(self, ignore_permissions=None): """Insert the document in the database (as a new document). @@ -560,11 +562,13 @@ class Document(BaseDocument): elif self._action=="submit": self.run_method("on_update") self.run_method("on_submit") - self.add_comment("Submitted") + if not self.flags.ignore_submit_comment: + self.add_comment("Submitted") elif self._action=="cancel": self.run_method("on_cancel") self.check_no_back_links_exist() - self.add_comment("Cancelled") + if not self.flags.ignore_submit_comment: + self.add_comment("Cancelled") elif self._action=="update_after_submit": self.run_method("on_update_after_submit") diff --git a/frappe/model/mapper.py b/frappe/model/mapper.py index 43c8d2bb8a..56677fb528 100644 --- a/frappe/model/mapper.py +++ b/frappe/model/mapper.py @@ -33,6 +33,17 @@ def get_mapped_doc(from_doctype, from_docname, table_maps, target_doc=None, for df in source_doc.meta.get_table_fields(): source_child_doctype = df.options table_map = table_maps.get(source_child_doctype) + + # if table_map isn't explicitly specified check if both source and target have the same fieldname and same table options and both of them don't have no_copy + if not table_map: + target_df = target_doc.meta.get_field(df.fieldname) + if target_df: + target_child_doctype = target_df.options + if target_df and target_child_doctype==source_child_doctype and not df.no_copy and not target_df.no_copy: + table_map = { + "doctype": target_child_doctype + } + if table_map: for source_d in source_doc.get(df.fieldname): if "condition" in table_map: diff --git a/frappe/model/meta.py b/frappe/model/meta.py index f58b290fa0..025dbd21a3 100644 --- a/frappe/model/meta.py +++ b/frappe/model/meta.py @@ -114,6 +114,9 @@ class Meta(Document): list_fields.append(self.title_field) return list_fields + def get_title_field(self): + return self.title_field or "name" + def process(self): # don't process for special doctypes # prevent's circular dependency diff --git a/frappe/model/naming.py b/frappe/model/naming.py index 3a7a4a7cb6..c23bd3d633 100644 --- a/frappe/model/naming.py +++ b/frappe/model/naming.py @@ -177,7 +177,7 @@ def append_number_if_name_exists(doc): if frappe.db.exists(doc.doctype, doc.name): last = frappe.db.sql("""select name from `tab{}` where name regexp '{}-[[:digit:]]+' - order by name desc limit 1""".format(doc.doctype, doc.name)) + order by length(name) desc, name desc limit 1""".format(doc.doctype, doc.name)) if last: count = str(cint(last[0][0].rsplit("-", 1)[1]) + 1) diff --git a/frappe/model/utils.py b/frappe/model/utils/__init__.py similarity index 100% rename from frappe/model/utils.py rename to frappe/model/utils/__init__.py diff --git a/frappe/model/utils/rename_field.py b/frappe/model/utils/rename_field.py new file mode 100644 index 0000000000..730f8c31a9 --- /dev/null +++ b/frappe/model/utils/rename_field.py @@ -0,0 +1,116 @@ +# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors +# MIT License. See license.txt + +from __future__ import unicode_literals + +import frappe +import json +from frappe.model import no_value_fields + +def rename_field(doctype, old_fieldname, new_fieldname): + """This functions assumes that doctype is already synced""" + + meta = frappe.get_meta(doctype, cached=False) + new_field = meta.get_field(new_fieldname) + if not new_field: + print "rename_field: " + (new_fieldname) + " not found in " + doctype + return + + if new_field.fieldtype == "Table": + # change parentfield of table mentioned in options + frappe.db.sql("""update `tab%s` set parentfield=%s + where parentfield=%s""" % (new_field.options.split("\n")[0], "%s", "%s"), + (new_fieldname, old_fieldname)) + elif new_field.fieldtype not in no_value_fields: + if meta.issingle: + frappe.db.sql("""update `tabSingles` set field=%s + where doctype=%s and field=%s""", + (new_fieldname, doctype, old_fieldname)) + else: + # copy field value + frappe.db.sql("""update `tab%s` set `%s`=`%s`""" % \ + (doctype, new_fieldname, old_fieldname)) + + update_reports(doctype, old_fieldname, new_fieldname) + update_users_report_view_settings(doctype, old_fieldname, new_fieldname) + + # update in property setter + frappe.db.sql("""update `tabProperty Setter` set field_name = %s + where doc_type=%s and field_name=%s""", (new_fieldname, doctype, old_fieldname)) + +def update_reports(doctype, old_fieldname, new_fieldname): + def _get_new_sort_by(report_dict, report, key): + sort_by = report_dict.get(key) or "" + if sort_by: + sort_by = sort_by.split(".") + if len(sort_by) > 1: + if sort_by[0]==doctype and sort_by[1]==old_fieldname: + sort_by = doctype + "." + new_fieldname + report_dict["updated"] = True + elif report.ref_doctype == doctype and sort_by[0]==old_fieldname: + sort_by = doctype + "." + new_fieldname + report_dict["updated"] = True + + if isinstance(sort_by, list): + sort_by = '.'.join(sort_by) + + return sort_by + + reports = frappe.db.sql("""select name, ref_doctype, json from tabReport + where report_type = 'Report Builder' and ifnull(is_standard, 'No') = 'No' + and json like %s and json like %s""", + ('%%%s%%' % old_fieldname , '%%%s%%' % doctype), as_dict=True) + + for r in reports: + report_dict = json.loads(r.json) + + # update filters + new_filters = [] + for f in report_dict.get("filters"): + if f and len(f) > 1 and f[0] == doctype and f[1] == old_fieldname: + new_filters.append([doctype, new_fieldname, f[2], f[3]]) + report_dict["updated"] = True + else: + new_filters.append(f) + + # update columns + new_columns = [] + for c in report_dict.get("columns"): + if c and len(c) > 1 and c[0] == old_fieldname and c[1] == doctype: + new_columns.append([new_fieldname, doctype]) + report_dict["updated"] = True + else: + new_columns.append(c) + + # update sort by + new_sort_by = _get_new_sort_by(report_dict, r, "sort_by") + new_sort_by_next = _get_new_sort_by(report_dict, r, "sort_by_next") + + if report_dict.get("updated"): + new_val = json.dumps({ + "filters": new_filters, + "columns": new_columns, + "sort_by": new_sort_by, + "sort_order": report_dict.get("sort_order"), + "sort_by_next": new_sort_by_next, + "sort_order_next": report_dict.get("sort_order_next") + }) + + frappe.db.sql("""update `tabReport` set `json`=%s where name=%s""", (new_val, r.name)) + +def update_users_report_view_settings(doctype, ref_fieldname, new_fieldname): + user_report_cols = frappe.db.sql("""select defkey, defvalue from `tabDefaultValue` where + defkey like '_list_settings:%'""") + for key, value in user_report_cols: + new_columns = [] + columns_modified = False + for field, field_doctype in json.loads(value): + if field == ref_fieldname and field_doctype == doctype: + new_columns.append([new_fieldname, field_doctype]) + columns_modified=True + else: + new_columns.append([field, field_doctype]) + + if columns_modified: + frappe.db.sql("""update `tabDefaultValue` set defvalue=%s + where defkey=%s""" % ('%s', '%s'), (json.dumps(new_columns), key)) diff --git a/frappe/modules/import_file.py b/frappe/modules/import_file.py index 2ecad22f28..0aea4fd2ca 100644 --- a/frappe/modules/import_file.py +++ b/frappe/modules/import_file.py @@ -7,19 +7,19 @@ import frappe, os, json from frappe.modules import get_module_path, scrub_dt_dn from frappe.utils import get_datetime_str -def import_files(module, dt=None, dn=None, force=False): +def import_files(module, dt=None, dn=None, force=False, pre_process=None): if type(module) is list: out = [] for m in module: - out.append(import_file(m[0], m[1], m[2], force=force)) + out.append(import_file(m[0], m[1], m[2], force=force, pre_process=pre_process)) return out else: - return import_file(module, dt, dn, force=force) + return import_file(module, dt, dn, force=force, pre_process=pre_process) -def import_file(module, dt, dn, force=False): +def import_file(module, dt, dn, force=False, pre_process=None): """Sync a file from txt if modifed, return false if not updated""" path = get_file_path(module, dt, dn) - ret = import_file_by_path(path, force) + ret = import_file_by_path(path, force, pre_process=pre_process) return ret def get_file_path(module, dt, dn): @@ -30,7 +30,7 @@ def get_file_path(module, dt, dn): return path -def import_file_by_path(path, force=False, data_import=False): +def import_file_by_path(path, force=False, data_import=False, pre_process=None): frappe.flags.in_import = True try: docs = read_doc_from_file(path) @@ -51,7 +51,7 @@ def import_file_by_path(path, force=False, data_import=False): original_modified = doc.get("modified") - import_doc(doc, force=force, data_import=data_import) + import_doc(doc, force=force, data_import=data_import, pre_process=pre_process) if original_modified: # since there is a new timestamp on the file, update timestamp in @@ -87,10 +87,12 @@ ignore_values = { ignore_doctypes = ["Page Role", "DocPerm"] -def import_doc(docdict, force=False, data_import=False): +def import_doc(docdict, force=False, data_import=False, pre_process=None): frappe.flags.in_import = True docdict["__islocal"] = 1 doc = frappe.get_doc(docdict) + if pre_process: + pre_process(doc) ignore = [] diff --git a/frappe/patches.txt b/frappe/patches.txt index cca44b24d9..535f0c8feb 100644 --- a/frappe/patches.txt +++ b/frappe/patches.txt @@ -2,7 +2,7 @@ execute:frappe.db.sql("""update `tabPatch Log` set patch=replace(patch, '.4_0.', frappe.patches.v5_0.convert_to_barracuda_and_utf8mb4 execute:frappe.reload_doc('core', 'doctype', 'doctype', force=True) #2014-01-24 execute:frappe.reload_doc('core', 'doctype', 'docfield', force=True) #2015-05-15 -execute:frappe.reload_doc('core', 'doctype', 'docperm') #2014-06-04 +execute:frappe.reload_doc('core', 'doctype', 'docperm') #2014-06-24 execute:frappe.reload_doc('core', 'doctype', 'page') #2013-13-26 execute:frappe.reload_doc('core', 'doctype', 'report') #2014-06-03 execute:frappe.reload_doc('core', 'doctype', 'version') #2014-02-21 @@ -66,6 +66,7 @@ frappe.patches.v5_0.clear_website_group_and_notifications execute:frappe.db.sql("""update tabComment set comment = substr(comment, 6, locate(":", comment)-6) where comment_type in ("Assigned", "Assignment Completed")""") frappe.patches.v5_0.fix_feed frappe.patches.v5_0.update_shared +execute:frappe.reload_doc("core", "doctype", "docshare") #2015-07-21 frappe.patches.v5_0.bookmarks_to_stars frappe.patches.v5_0.style_settings_to_website_theme frappe.patches.v5_0.rename_ref_type_fieldnames @@ -79,3 +80,6 @@ execute:frappe.db.sql("update tabUser set new_password='' where ifnull(new_passw frappe.patches.v5_0.fix_text_editor_file_urls execute:frappe.db.sql("update `tabComment` set comment_type='Comment' where comment_doctype='Blog Post' and ifnull(comment_type, '')=''") frappe.patches.v5_0.modify_session +frappe.patches.v5_0.expire_old_scheduler_logs +execute:frappe.permissions.reset_perms("DocType") +execute:frappe.db.sql("delete from `tabProperty Setter` where `property` = 'idx'") diff --git a/frappe/patches/v4_0/rename_profile_to_user.py b/frappe/patches/v4_0/rename_profile_to_user.py index 85b8f53c0b..48555ead9e 100644 --- a/frappe/patches/v4_0/rename_profile_to_user.py +++ b/frappe/patches/v4_0/rename_profile_to_user.py @@ -1,7 +1,7 @@ from __future__ import unicode_literals import frappe -from frappe.model import rename_field +from frappe.model.utils.rename_field import rename_field from frappe.model.meta import get_table_columns def execute(): diff --git a/frappe/patches/v4_0/rename_sitemap_to_route.py b/frappe/patches/v4_0/rename_sitemap_to_route.py index af75763343..4deca2f052 100644 --- a/frappe/patches/v4_0/rename_sitemap_to_route.py +++ b/frappe/patches/v4_0/rename_sitemap_to_route.py @@ -1,7 +1,7 @@ from __future__ import unicode_literals import frappe -from frappe.model import rename_field +from frappe.model.utils.rename_field import rename_field def execute(): tables = frappe.db.sql_list("show tables") diff --git a/frappe/patches/v5_0/bookmarks_to_stars.py b/frappe/patches/v5_0/bookmarks_to_stars.py index 6bddd43d96..4f25cf00f7 100644 --- a/frappe/patches/v5_0/bookmarks_to_stars.py +++ b/frappe/patches/v5_0/bookmarks_to_stars.py @@ -25,4 +25,8 @@ def execute(): continue if frappe.db.exists(doctype, docname): + if (doctype=="DocType" + or int(frappe.db.get_value("DocType", doctype, "issingle") or 0) + or not frappe.db.table_exists(doctype)): + continue _toggle_star(doctype, docname, add="Yes", user=username) diff --git a/frappe/patches/v5_0/expire_old_scheduler_logs.py b/frappe/patches/v5_0/expire_old_scheduler_logs.py new file mode 100644 index 0000000000..3c4b12a356 --- /dev/null +++ b/frappe/patches/v5_0/expire_old_scheduler_logs.py @@ -0,0 +1,7 @@ +import frappe + +def execute(): + frappe.reload_doctype("Scheduler Log") + + from frappe.core.doctype.scheduler_log.scheduler_log import set_old_logs_as_seen + set_old_logs_as_seen() diff --git a/frappe/patches/v5_0/modify_session.py b/frappe/patches/v5_0/modify_session.py index 122982da07..2aaf2da97b 100644 --- a/frappe/patches/v5_0/modify_session.py +++ b/frappe/patches/v5_0/modify_session.py @@ -1,4 +1,5 @@ import frappe def execute(): - frappe.db.sql("alter table tabSessions add column `device` varchar(255) default 'desktop'") + if "device" not in frappe.db.get_table_columns("Sessions"): + frappe.db.sql("alter table tabSessions add column `device` varchar(255) default 'desktop'") diff --git a/frappe/patches/v5_0/rename_table_fieldnames.py b/frappe/patches/v5_0/rename_table_fieldnames.py index ad426ef2f6..d2564e5ab0 100644 --- a/frappe/patches/v5_0/rename_table_fieldnames.py +++ b/frappe/patches/v5_0/rename_table_fieldnames.py @@ -2,7 +2,7 @@ # License: GNU General Public License v3. See license.txt import frappe -from frappe.model import rename_field +from frappe.model.utils.rename_field import rename_field from frappe.modules import scrub, get_doctype_module rename_map = { diff --git a/frappe/permissions.py b/frappe/permissions.py index 6465b79797..480a2ba2c3 100644 --- a/frappe/permissions.py +++ b/frappe/permissions.py @@ -17,7 +17,11 @@ def check_admin_or_system_manager(user=None): frappe.throw(_("Not permitted"), frappe.PermissionError) def has_permission(doctype, ptype="read", doc=None, verbose=False, user=None): - """check if user has permission""" + """Returns True if user has permission `ptype` for given `doctype`. + If `doc` is passed, it also checks user, share and owner permissions. + + Note: if Table DocType is passed, it always returns True. + """ if not user: user = frappe.session.user if frappe.is_table(doctype): @@ -39,13 +43,17 @@ def has_permission(doctype, ptype="read", doc=None, verbose=False, user=None): return True def false_if_not_shared(): - if ptype in ("read", "write", "share"): - shared = frappe.share.get_shared(doctype, user, [ptype]) + if ptype in ("read", "write", "share", "email", "print"): if doc: doc_name = doc if isinstance(doc, basestring) else doc.name + shared = frappe.share.get_shared(doctype, user, + ["read" if ptype in ("email", "print") else ptype]) + if doc_name in shared: if verbose: print "Shared" - return True + if ptype in ("read", "write", "share") or meta.permissions[0].get(ptype): + return True + else: if verbose: print "Has a shared document" return True @@ -61,6 +69,11 @@ def has_permission(doctype, ptype="read", doc=None, verbose=False, user=None): if isinstance(doc, basestring): doc = frappe.get_doc(meta.name, doc) + # if owner match, then return True + if doc.owner == frappe.session.user and role_permissions["if_owner"].get(ptype) and ptype!="create": + return True + + # check if user permission if role_permissions["apply_user_permissions"].get(ptype): if not user_has_permission(doc, verbose=verbose, user=user, user_permission_doctypes=role_permissions.get("user_permission_doctypes", {}).get(ptype) or []): @@ -76,6 +89,7 @@ def has_permission(doctype, ptype="read", doc=None, verbose=False, user=None): return True def get_doc_permissions(doc, verbose=False, user=None): + """Returns a dict of evaluated permissions for given `doc` like `{"read":1, "write":1}`""" if not user: user = frappe.session.user if frappe.is_table(doc.doctype): @@ -98,23 +112,62 @@ def get_doc_permissions(doc, verbose=False, user=None): user_permission_doctypes=role_permissions.get("user_permission_doctypes", {}).get(ptype) or []): role_permissions[ptype] = 0 - # update share permissions - role_permissions.update(frappe.db.get_value("DocShare", - {"share_doctype": doc.doctype, "share_name": doc.name, "user": user}, - ["read", "write", "share"], as_dict=True) or {}) + # apply owner permissions on top of existing permissions + if doc.owner == frappe.session.user: + role_permissions.update(role_permissions.if_owner) + + update_share_permissions(role_permissions, doc, user) return role_permissions +def update_share_permissions(role_permissions, doc, user): + """Updates share permissions on `role_permissions` for given doc, if shared""" + share_ptypes = ("read", "write", "share") + permissions_by_share = frappe.db.get_value("DocShare", + {"share_doctype": doc.doctype, "share_name": doc.name, "user": user}, + share_ptypes, as_dict=True) + + if permissions_by_share: + for ptype in share_ptypes: + if ptype: + role_permissions[ptype] = 1 + def get_role_permissions(meta, user=None, verbose=False): + """Returns dict of evaluated role permissions like `{"read": True, "write":False}` + + If user permissions are applicable, it adds a dict of user permissions like + + { + // user permissions will apply on these rights + "apply_user_permissions": {"read": 1, "write": 1}, + + // doctypes that will be applicable for each right + "user_permission_doctypes": { + "read": [ + // AND between "DocType 1" and "DocType 2" + ["DocType 1", "DocType 2"], + + // OR + + ["DocType 3"] + + ] + } + + "if_owner": {"read": 1, "write": 1} + } + """ if not user: user = frappe.session.user cache_key = (meta.name, user) if not frappe.local.role_permissions.get(cache_key): - perms = frappe._dict({ "apply_user_permissions": {}, "user_permission_doctypes": {} }) + perms = frappe._dict({ "apply_user_permissions": {}, "user_permission_doctypes": {}, "if_owner": {} }) user_roles = frappe.get_roles(user) for p in meta.permissions: if cint(p.permlevel)==0 and (p.role in user_roles): + # apply only for level 0 + for ptype in rights: perms[ptype] = perms.get(ptype, 0) or cint(p.get(ptype)) @@ -122,6 +175,10 @@ def get_role_permissions(meta, user=None, verbose=False): perms["apply_user_permissions"][ptype] = (perms["apply_user_permissions"].get(ptype, 1) and p.get("apply_user_permissions")) + # build if_owner dict if applicable for this right + if p.if_owner and p.get(ptype): + perms["if_owner"][ptype] = 1 + if p.apply_user_permissions: if p.user_permission_doctypes: # set user_permission_doctypes in perms diff --git a/frappe/print/doctype/print_format/print_format.json b/frappe/print/doctype/print_format/print_format.json index 73f426fa83..cd47d3bec0 100644 --- a/frappe/print/doctype/print_format/print_format.json +++ b/frappe/print/doctype/print_format/print_format.json @@ -19,12 +19,10 @@ "search_index": 0 }, { - "depends_on": "eval:!doc.custom_format", - "fieldname": "edit_format", - "fieldtype": "Button", - "label": "Edit Format", - "permlevel": 0, - "precision": "" + "fieldname": "disabled", + "fieldtype": "Check", + "label": "Disabled", + "permlevel": 0 }, { "fieldname": "column_break_3", @@ -51,17 +49,6 @@ "reqd": 1, "search_index": 1 }, - { - "fieldname": "disabled", - "fieldtype": "Check", - "label": "Disabled", - "permlevel": 0 - }, - { - "fieldname": "section_break_6", - "fieldtype": "Section Break", - "permlevel": 0 - }, { "fieldname": "custom_format", "fieldtype": "Check", @@ -69,6 +56,12 @@ "permlevel": 0, "precision": "" }, + { + "depends_on": "custom_format", + "fieldname": "section_break_6", + "fieldtype": "Section Break", + "permlevel": 0 + }, { "default": "Server", "depends_on": "custom_format", @@ -99,6 +92,44 @@ "reqd": 0, "search_index": 0 }, + { + "depends_on": "eval:!doc.custom_format", + "fieldname": "section_break_9", + "fieldtype": "Section Break", + "permlevel": 0, + "precision": "" + }, + { + "depends_on": "eval:!doc.custom_format", + "fieldname": "edit_format", + "fieldtype": "Button", + "label": "Edit Format", + "permlevel": 0, + "precision": "" + }, + { + "fieldname": "column_break_11", + "fieldtype": "Column Break", + "permlevel": 0, + "precision": "" + }, + { + "default": "Default", + "depends_on": "eval:!doc.custom_format", + "fieldname": "font", + "fieldtype": "Select", + "label": "Font", + "options": "Default\nArial\nHelvetica\nVerdana\nMonospace", + "permlevel": 0, + "precision": "" + }, + { + "depends_on": "custom_format", + "fieldname": "section_break_13", + "fieldtype": "Section Break", + "permlevel": 0, + "precision": "" + }, { "depends_on": "custom_format", "fieldname": "print_format_help", @@ -134,7 +165,7 @@ "issingle": 0, "istable": 0, "max_attachments": 0, - "modified": "2015-02-05 05:11:42.667447", + "modified": "2015-07-15 08:01:06.284031", "modified_by": "Administrator", "module": "Print", "name": "Print Format", diff --git a/frappe/print/doctype/print_settings/print_settings.json b/frappe/print/doctype/print_settings/print_settings.json index f549593eb2..23ffbaf350 100644 --- a/frappe/print/doctype/print_settings/print_settings.json +++ b/frappe/print/doctype/print_settings/print_settings.json @@ -42,9 +42,13 @@ "permlevel": 0 }, { - "fieldname": "column_break_6", - "fieldtype": "Column Break", - "permlevel": 0 + "default": "Default", + "fieldname": "font", + "fieldtype": "Select", + "label": "Font", + "options": "Default\nArial\nHelvetica\nVerdana\nMonospace", + "permlevel": 0, + "precision": "" }, { "description": "In points. Default is 9.", @@ -53,6 +57,11 @@ "label": "Font Size", "permlevel": 0 }, + { + "fieldname": "column_break_6", + "fieldtype": "Column Break", + "permlevel": 0 + }, { "default": "1", "description": "Print with Letterhead, unless unchecked in a particular Document", @@ -76,7 +85,7 @@ ], "icon": "icon-cog", "issingle": 1, - "modified": "2015-03-25 07:10:38.893958", + "modified": "2015-07-15 08:03:23.743143", "modified_by": "Administrator", "module": "Print", "name": "Print Settings", diff --git a/frappe/print/page/print_format_builder/print_format_builder.js b/frappe/print/page/print_format_builder/print_format_builder.js index ce1c2c3a6c..d4b2f0f32e 100644 --- a/frappe/print/page/print_format_builder/print_format_builder.js +++ b/frappe/print/page/print_format_builder/print_format_builder.js @@ -152,6 +152,7 @@ frappe.PrintFormatBuilder = Class.extend({ me.page.set_primary_action(__("Save"), function() { me.save_print_format(); }); + me.page.clear_menu(); me.page.add_menu_item(__("Start new Format"), function() { me.print_format = null; me.refresh(); diff --git a/frappe/public/build.json b/frappe/public/build.json index 8da0dd58bd..7d7cb8fa7a 100644 --- a/frappe/public/build.json +++ b/frappe/public/build.json @@ -47,8 +47,8 @@ "public/js/lib/notify.js", "public/js/lib/bootstrap.min.js", "public/js/lib/nprogress.js", - "public/js/lib/moment/moment.min.js", - "public/js/lib/moment/moment-timezone.min.js", + "public/js/lib/moment/moment-with-locales.min.js", + "public/js/lib/moment/moment-timezone-with-data.min.js", "public/js/frappe/provide.js", "public/js/frappe/class.js", @@ -95,6 +95,7 @@ "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/ui/upload.html", "public/js/frappe/upload.js", diff --git a/frappe/public/css/avatar.css b/frappe/public/css/avatar.css index 636cc1baf3..7bc44cacd9 100644 --- a/frappe/public/css/avatar.css +++ b/frappe/public/css/avatar.css @@ -12,6 +12,7 @@ } .avatar-empty { border: 1px dashed #d1d8dd; + border-radius: 4px; } .avatar-small { margin-right: 5px; diff --git a/frappe/public/css/desk.css b/frappe/public/css/desk.css index da3eea4f48..31f5791f0b 100644 --- a/frappe/public/css/desk.css +++ b/frappe/public/css/desk.css @@ -361,6 +361,11 @@ ul.linked-with-list li { padding: 7px; font-size: 12px; } +@media (min-width: 768px) { + .video-modal { + width: 700px; + } +} /* z-index hack */ @media (min-width: 768px) { .hidden-xs-inline { @@ -389,6 +394,18 @@ ul.linked-with-list li { .modal-title { margin-top: 5px; } +.form-control { + position: relative; +} +.link-field.ui-front { + z-index: inherit; +} +.modal .hasDatepicker { + z-index: 1140; +} +.modal .link-field .ui-autocomplete { + z-index: 1141; +} .form-group { margin-bottom: 7px; } diff --git a/frappe/public/css/form.css b/frappe/public/css/form.css index 7f3d649951..a85f9ae799 100644 --- a/frappe/public/css/form.css +++ b/frappe/public/css/form.css @@ -32,6 +32,9 @@ margin: 0px; padding: 15px; } +.form-section .form-section-heading { + margin: 25px 0px 15px 0px; +} .empty-section { display: none !important; } diff --git a/frappe/public/css/mobile.css b/frappe/public/css/mobile.css index 2d134bb032..a7c3b17702 100644 --- a/frappe/public/css/mobile.css +++ b/frappe/public/css/mobile.css @@ -315,7 +315,7 @@ body { } #navbar-breadcrumbs > li > a:before { content: "\f104"; - margin-right: 5px; + margin-right: 10px; color: #6c7680; } #navbar-breadcrumbs li:not(:nth-last-child(-n+1)) { @@ -448,7 +448,7 @@ body { position: relative; top: 3px; content: "\f104"; - margin-right: 5px; + margin-right: 10px; color: #6c7680; } body.no-breadcrumbs .navbar .navbar-home:hover:before, diff --git a/frappe/public/css/navbar.css b/frappe/public/css/navbar.css index 6115b387ed..22caee00b6 100644 --- a/frappe/public/css/navbar.css +++ b/frappe/public/css/navbar.css @@ -77,7 +77,7 @@ position: relative; top: 3px; content: "\f105"; - margin-right: 15px; + margin-right: 10px; color: #c0c9d2; } #navbar-breadcrumbs > li > a:hover:before, @@ -92,3 +92,9 @@ max-width: 200px; display: inline-block; } +.navbar-brand { + padding: 10px; +} +.navbar-brand > img { + display: inline-block; +} diff --git a/frappe/public/css/shepherd/shepherd-theme-arrows-plain-buttons.css b/frappe/public/css/shepherd/shepherd-theme-arrows-plain-buttons.css new file mode 100755 index 0000000000..4b07981756 --- /dev/null +++ b/frappe/public/css/shepherd/shepherd-theme-arrows-plain-buttons.css @@ -0,0 +1,185 @@ +.shepherd-element, .shepherd-element:after, .shepherd-element:before, .shepherd-element *, .shepherd-element *:after, .shepherd-element *:before { + -moz-box-sizing: border-box; + -webkit-box-sizing: border-box; + box-sizing: border-box; } + +.shepherd-element { + position: absolute; + display: none; } + .shepherd-element.shepherd-open { + display: block; } + +.shepherd-element.shepherd-theme-arrows-plain-buttons { + max-width: 100%; + max-height: 100%; } + .shepherd-element.shepherd-theme-arrows-plain-buttons .shepherd-content { + -moz-border-radius: 5px; + -webkit-border-radius: 5px; + border-radius: 5px; + position: relative; + font-family: inherit; + background: #fff; + color: #444; + padding: 1em; + font-size: 1.1em; + line-height: 1.5em; + -moz-transform: translateZ(0); + -ms-transform: translateZ(0); + -webkit-transform: translateZ(0); + transform: translateZ(0); + -webkit-filter: drop-shadow(0 1px 4px rgba(0, 0, 0, 0.2)); + filter: drop-shadow(0 1px 4px rgba(0, 0, 0, 0.2)); } + .shepherd-element.shepherd-theme-arrows-plain-buttons .shepherd-content:before { + content: ""; + display: block; + position: absolute; + width: 0; + height: 0; + border-color: transparent; + border-width: 16px; + border-style: solid; } + .shepherd-element.shepherd-theme-arrows-plain-buttons.shepherd-element-attached-bottom.shepherd-element-attached-center .shepherd-content { + margin-bottom: 16px; } + .shepherd-element.shepherd-theme-arrows-plain-buttons.shepherd-element-attached-bottom.shepherd-element-attached-center .shepherd-content:before { + top: 100%; + left: 50%; + margin-left: -16px; + border-top-color: #fff; } + .shepherd-element.shepherd-theme-arrows-plain-buttons.shepherd-element-attached-top.shepherd-element-attached-center .shepherd-content { + margin-top: 16px; } + .shepherd-element.shepherd-theme-arrows-plain-buttons.shepherd-element-attached-top.shepherd-element-attached-center .shepherd-content:before { + bottom: 100%; + left: 50%; + margin-left: -16px; + border-bottom-color: #fff; } + .shepherd-element.shepherd-theme-arrows-plain-buttons.shepherd-element-attached-right.shepherd-element-attached-middle .shepherd-content { + margin-right: 16px; } + .shepherd-element.shepherd-theme-arrows-plain-buttons.shepherd-element-attached-right.shepherd-element-attached-middle .shepherd-content:before { + left: 100%; + top: 50%; + margin-top: -16px; + border-left-color: #fff; } + .shepherd-element.shepherd-theme-arrows-plain-buttons.shepherd-element-attached-left.shepherd-element-attached-middle .shepherd-content { + margin-left: 16px; } + .shepherd-element.shepherd-theme-arrows-plain-buttons.shepherd-element-attached-left.shepherd-element-attached-middle .shepherd-content:before { + right: 100%; + top: 50%; + margin-top: -16px; + border-right-color: #fff; } + .shepherd-element.shepherd-theme-arrows-plain-buttons.shepherd-element-attached-top.shepherd-element-attached-left.shepherd-target-attached-bottom .shepherd-content { + margin-top: 16px; } + .shepherd-element.shepherd-theme-arrows-plain-buttons.shepherd-element-attached-top.shepherd-element-attached-left.shepherd-target-attached-bottom .shepherd-content:before { + bottom: 100%; + left: 16px; + border-bottom-color: #fff; } + .shepherd-element.shepherd-theme-arrows-plain-buttons.shepherd-element-attached-top.shepherd-element-attached-right.shepherd-target-attached-bottom .shepherd-content { + margin-top: 16px; } + .shepherd-element.shepherd-theme-arrows-plain-buttons.shepherd-element-attached-top.shepherd-element-attached-right.shepherd-target-attached-bottom .shepherd-content:before { + bottom: 100%; + right: 16px; + border-bottom-color: #fff; } + .shepherd-element.shepherd-theme-arrows-plain-buttons.shepherd-element-attached-bottom.shepherd-element-attached-left.shepherd-target-attached-top .shepherd-content { + margin-bottom: 16px; } + .shepherd-element.shepherd-theme-arrows-plain-buttons.shepherd-element-attached-bottom.shepherd-element-attached-left.shepherd-target-attached-top .shepherd-content:before { + top: 100%; + left: 16px; + border-top-color: #fff; } + .shepherd-element.shepherd-theme-arrows-plain-buttons.shepherd-element-attached-bottom.shepherd-element-attached-right.shepherd-target-attached-top .shepherd-content { + margin-bottom: 16px; } + .shepherd-element.shepherd-theme-arrows-plain-buttons.shepherd-element-attached-bottom.shepherd-element-attached-right.shepherd-target-attached-top .shepherd-content:before { + top: 100%; + right: 16px; + border-top-color: #fff; } + .shepherd-element.shepherd-theme-arrows-plain-buttons.shepherd-element-attached-top.shepherd-element-attached-right.shepherd-target-attached-left .shepherd-content { + margin-right: 16px; } + .shepherd-element.shepherd-theme-arrows-plain-buttons.shepherd-element-attached-top.shepherd-element-attached-right.shepherd-target-attached-left .shepherd-content:before { + top: 16px; + left: 100%; + border-left-color: #fff; } + .shepherd-element.shepherd-theme-arrows-plain-buttons.shepherd-element-attached-top.shepherd-element-attached-left.shepherd-target-attached-right .shepherd-content { + margin-left: 16px; } + .shepherd-element.shepherd-theme-arrows-plain-buttons.shepherd-element-attached-top.shepherd-element-attached-left.shepherd-target-attached-right .shepherd-content:before { + top: 16px; + right: 100%; + border-right-color: #fff; } + .shepherd-element.shepherd-theme-arrows-plain-buttons.shepherd-element-attached-bottom.shepherd-element-attached-right.shepherd-target-attached-left .shepherd-content { + margin-right: 16px; } + .shepherd-element.shepherd-theme-arrows-plain-buttons.shepherd-element-attached-bottom.shepherd-element-attached-right.shepherd-target-attached-left .shepherd-content:before { + bottom: 16px; + left: 100%; + border-left-color: #fff; } + .shepherd-element.shepherd-theme-arrows-plain-buttons.shepherd-element-attached-bottom.shepherd-element-attached-left.shepherd-target-attached-right .shepherd-content { + margin-left: 16px; } + .shepherd-element.shepherd-theme-arrows-plain-buttons.shepherd-element-attached-bottom.shepherd-element-attached-left.shepherd-target-attached-right .shepherd-content:before { + bottom: 16px; + right: 100%; + border-right-color: #fff; } + +.shepherd-element.shepherd-theme-arrows-plain-buttons.shepherd-element-attached-top.shepherd-element-attached-center.shepherd-has-title .shepherd-content:before, .shepherd-element.shepherd-theme-arrows-plain-buttons.shepherd-element-attached-top.shepherd-element-attached-right.shepherd-target-attached-bottom.shepherd-has-title .shepherd-content:before, .shepherd-element.shepherd-theme-arrows-plain-buttons.shepherd-element-attached-top.shepherd-element-attached-left.shepherd-target-attached-bottom.shepherd-has-title .shepherd-content:before { + border-bottom-color: #eee; } +.shepherd-element.shepherd-theme-arrows-plain-buttons.shepherd-has-title .shepherd-content header { + background: #eee; + padding: 1em; } + .shepherd-element.shepherd-theme-arrows-plain-buttons.shepherd-has-title .shepherd-content header a.shepherd-cancel-link { + padding: 0; + margin-bottom: 0; } +.shepherd-element.shepherd-theme-arrows-plain-buttons.shepherd-has-cancel-link .shepherd-content header h3 { + float: left; } +.shepherd-element.shepherd-theme-arrows-plain-buttons .shepherd-content { + padding: 0; } + .shepherd-element.shepherd-theme-arrows-plain-buttons .shepherd-content header { + *zoom: 1; + -moz-border-radius: 5px 5px 0 0; + -webkit-border-radius: 5px; + border-radius: 5px 5px 0 0; } + .shepherd-element.shepherd-theme-arrows-plain-buttons .shepherd-content header:after { + content: ""; + display: table; + clear: both; } + .shepherd-element.shepherd-theme-arrows-plain-buttons .shepherd-content header h3 { + margin: 0; + line-height: 1; + font-weight: normal; } + .shepherd-element.shepherd-theme-arrows-plain-buttons .shepherd-content header a.shepherd-cancel-link { + float: right; + text-decoration: none; + font-size: 1.25em; + line-height: 0.8em; + font-weight: normal; + color: rgba(0, 0, 0, 0.5); + opacity: 0.25; + position: relative; + top: 0.1em; + padding: 0.8em; + margin-bottom: -0.8em; } + .shepherd-element.shepherd-theme-arrows-plain-buttons .shepherd-content header a.shepherd-cancel-link:hover { + opacity: 1; } + .shepherd-element.shepherd-theme-arrows-plain-buttons .shepherd-content .shepherd-text { + padding: 1em; } + .shepherd-element.shepherd-theme-arrows-plain-buttons .shepherd-content .shepherd-text p { + margin: 0 0 0.5em 0; + line-height: 1.3em; } + .shepherd-element.shepherd-theme-arrows-plain-buttons .shepherd-content .shepherd-text p:last-child { + margin-bottom: 0; } + .shepherd-element.shepherd-theme-arrows-plain-buttons .shepherd-content footer { + padding: 0 1em 1em; } + .shepherd-element.shepherd-theme-arrows-plain-buttons .shepherd-content footer .shepherd-buttons { + text-align: right; + list-style: none; + padding: 0; + margin: 0; } + .shepherd-element.shepherd-theme-arrows-plain-buttons .shepherd-content footer .shepherd-buttons li { + display: inline; + padding: 0; + margin: 0; } + .shepherd-element.shepherd-theme-arrows-plain-buttons .shepherd-content footer .shepherd-buttons li .shepherd-button { + display: inline-block; + vertical-align: middle; + *vertical-align: auto; + *zoom: 1; + *display: inline; + cursor: pointer; + margin: 0 0.5em 0 0; + text-decoration: none; } + .shepherd-element.shepherd-theme-arrows-plain-buttons .shepherd-content footer .shepherd-buttons li:last-child .shepherd-button { + margin-right: 0; } diff --git a/frappe/public/css/shepherd/shepherd-theme-arrows.css b/frappe/public/css/shepherd/shepherd-theme-arrows.css new file mode 100755 index 0000000000..5091c726ce --- /dev/null +++ b/frappe/public/css/shepherd/shepherd-theme-arrows.css @@ -0,0 +1,201 @@ +.shepherd-element, .shepherd-element:after, .shepherd-element:before, .shepherd-element *, .shepherd-element *:after, .shepherd-element *:before { + -moz-box-sizing: border-box; + -webkit-box-sizing: border-box; + box-sizing: border-box; } + +.shepherd-element { + position: absolute; + display: none; } + .shepherd-element.shepherd-open { + display: block; } + +.shepherd-element.shepherd-theme-arrows { + max-width: 100%; + max-height: 100%; } + .shepherd-element.shepherd-theme-arrows .shepherd-content { + -moz-border-radius: 5px; + -webkit-border-radius: 5px; + border-radius: 5px; + position: relative; + font-family: inherit; + background: #fff; + /*color: #444;*/ + padding: 1em; + /*font-size: 1.1em;*/ + /*line-height: 1.5em;*/ + -moz-transform: translateZ(0); + -ms-transform: translateZ(0); + -webkit-transform: translateZ(0); + transform: translateZ(0); + -webkit-filter: drop-shadow(0 1px 4px rgba(0, 0, 0, 0.2)); + filter: drop-shadow(0 1px 4px rgba(0, 0, 0, 0.2)); } + .shepherd-element.shepherd-theme-arrows .shepherd-content:before { + content: ""; + display: block; + position: absolute; + width: 0; + height: 0; + border-color: transparent; + border-width: 16px; + border-style: solid; } + .shepherd-element.shepherd-theme-arrows.shepherd-element-attached-bottom.shepherd-element-attached-center .shepherd-content { + margin-bottom: 16px; } + .shepherd-element.shepherd-theme-arrows.shepherd-element-attached-bottom.shepherd-element-attached-center .shepherd-content:before { + top: 100%; + left: 50%; + margin-left: -16px; + border-top-color: #fff; } + .shepherd-element.shepherd-theme-arrows.shepherd-element-attached-top.shepherd-element-attached-center .shepherd-content { + margin-top: 16px; } + .shepherd-element.shepherd-theme-arrows.shepherd-element-attached-top.shepherd-element-attached-center .shepherd-content:before { + bottom: 100%; + left: 50%; + margin-left: -16px; + border-bottom-color: #fff; } + .shepherd-element.shepherd-theme-arrows.shepherd-element-attached-right.shepherd-element-attached-middle .shepherd-content { + margin-right: 16px; } + .shepherd-element.shepherd-theme-arrows.shepherd-element-attached-right.shepherd-element-attached-middle .shepherd-content:before { + left: 100%; + top: 50%; + margin-top: -16px; + border-left-color: #fff; } + .shepherd-element.shepherd-theme-arrows.shepherd-element-attached-left.shepherd-element-attached-middle .shepherd-content { + margin-left: 16px; } + .shepherd-element.shepherd-theme-arrows.shepherd-element-attached-left.shepherd-element-attached-middle .shepherd-content:before { + right: 100%; + top: 50%; + margin-top: -16px; + border-right-color: #fff; } + .shepherd-element.shepherd-theme-arrows.shepherd-element-attached-top.shepherd-element-attached-left.shepherd-target-attached-bottom .shepherd-content { + margin-top: 16px; } + .shepherd-element.shepherd-theme-arrows.shepherd-element-attached-top.shepherd-element-attached-left.shepherd-target-attached-bottom .shepherd-content:before { + bottom: 100%; + left: 16px; + border-bottom-color: #fff; } + .shepherd-element.shepherd-theme-arrows.shepherd-element-attached-top.shepherd-element-attached-right.shepherd-target-attached-bottom .shepherd-content { + margin-top: 16px; } + .shepherd-element.shepherd-theme-arrows.shepherd-element-attached-top.shepherd-element-attached-right.shepherd-target-attached-bottom .shepherd-content:before { + bottom: 100%; + right: 16px; + border-bottom-color: #fff; } + .shepherd-element.shepherd-theme-arrows.shepherd-element-attached-bottom.shepherd-element-attached-left.shepherd-target-attached-top .shepherd-content { + margin-bottom: 16px; } + .shepherd-element.shepherd-theme-arrows.shepherd-element-attached-bottom.shepherd-element-attached-left.shepherd-target-attached-top .shepherd-content:before { + top: 100%; + left: 16px; + border-top-color: #fff; } + .shepherd-element.shepherd-theme-arrows.shepherd-element-attached-bottom.shepherd-element-attached-right.shepherd-target-attached-top .shepherd-content { + margin-bottom: 16px; } + .shepherd-element.shepherd-theme-arrows.shepherd-element-attached-bottom.shepherd-element-attached-right.shepherd-target-attached-top .shepherd-content:before { + top: 100%; + right: 16px; + border-top-color: #fff; } + .shepherd-element.shepherd-theme-arrows.shepherd-element-attached-top.shepherd-element-attached-right.shepherd-target-attached-left .shepherd-content { + margin-right: 16px; } + .shepherd-element.shepherd-theme-arrows.shepherd-element-attached-top.shepherd-element-attached-right.shepherd-target-attached-left .shepherd-content:before { + top: 16px; + left: 100%; + border-left-color: #fff; } + .shepherd-element.shepherd-theme-arrows.shepherd-element-attached-top.shepherd-element-attached-left.shepherd-target-attached-right .shepherd-content { + margin-left: 16px; } + .shepherd-element.shepherd-theme-arrows.shepherd-element-attached-top.shepherd-element-attached-left.shepherd-target-attached-right .shepherd-content:before { + top: 16px; + right: 100%; + border-right-color: #fff; } + .shepherd-element.shepherd-theme-arrows.shepherd-element-attached-bottom.shepherd-element-attached-right.shepherd-target-attached-left .shepherd-content { + margin-right: 16px; } + .shepherd-element.shepherd-theme-arrows.shepherd-element-attached-bottom.shepherd-element-attached-right.shepherd-target-attached-left .shepherd-content:before { + bottom: 16px; + left: 100%; + border-left-color: #fff; } + .shepherd-element.shepherd-theme-arrows.shepherd-element-attached-bottom.shepherd-element-attached-left.shepherd-target-attached-right .shepherd-content { + margin-left: 16px; } + .shepherd-element.shepherd-theme-arrows.shepherd-element-attached-bottom.shepherd-element-attached-left.shepherd-target-attached-right .shepherd-content:before { + bottom: 16px; + right: 100%; + border-right-color: #fff; } + +.shepherd-element.shepherd-theme-arrows.shepherd-element-attached-top.shepherd-element-attached-center.shepherd-has-title .shepherd-content:before, .shepherd-element.shepherd-theme-arrows.shepherd-element-attached-top.shepherd-element-attached-right.shepherd-target-attached-bottom.shepherd-has-title .shepherd-content:before, .shepherd-element.shepherd-theme-arrows.shepherd-element-attached-top.shepherd-element-attached-left.shepherd-target-attached-bottom.shepherd-has-title .shepherd-content:before { + border-bottom-color: #eee; } +.shepherd-element.shepherd-theme-arrows.shepherd-has-title .shepherd-content header { + background: #eee; + padding: 1em; } + .shepherd-element.shepherd-theme-arrows.shepherd-has-title .shepherd-content header a.shepherd-cancel-link { + padding: 0; + margin-bottom: 0; } +.shepherd-element.shepherd-theme-arrows.shepherd-has-cancel-link .shepherd-content header h3 { + float: left; } +.shepherd-element.shepherd-theme-arrows .shepherd-content { + padding: 0; } + .shepherd-element.shepherd-theme-arrows .shepherd-content * { + font-size: inherit; } + .shepherd-element.shepherd-theme-arrows .shepherd-content header { + *zoom: 1; + -moz-border-radius: 5px 5px 0 0; + -webkit-border-radius: 5px; + border-radius: 5px 5px 0 0; } + .shepherd-element.shepherd-theme-arrows .shepherd-content header:after { + content: ""; + display: table; + clear: both; } + .shepherd-element.shepherd-theme-arrows .shepherd-content header h3 { + margin: 0; + line-height: 1; + font-weight: normal; } + .shepherd-element.shepherd-theme-arrows .shepherd-content header a.shepherd-cancel-link { + float: right; + text-decoration: none; + font-size: 1.25em; + line-height: 0.8em; + font-weight: normal; + color: rgba(0, 0, 0, 0.5); + opacity: 0.25; + position: relative; + top: 0.1em; + padding: 0.8em; + margin-bottom: -0.8em; } + .shepherd-element.shepherd-theme-arrows .shepherd-content header a.shepherd-cancel-link:hover { + opacity: 1; } + .shepherd-element.shepherd-theme-arrows .shepherd-content .shepherd-text { + padding: 1em; } + .shepherd-element.shepherd-theme-arrows .shepherd-content .shepherd-text p { + margin: 0 0 0.5em 0; + line-height: 1.3em; } + .shepherd-element.shepherd-theme-arrows .shepherd-content .shepherd-text p:last-child { + margin-bottom: 0; } + .shepherd-element.shepherd-theme-arrows .shepherd-content footer { + padding: 0 1em 1em; } + .shepherd-element.shepherd-theme-arrows .shepherd-content footer .shepherd-buttons { + text-align: right; + list-style: none; + padding: 0; + margin: 0; } + .shepherd-element.shepherd-theme-arrows .shepherd-content footer .shepherd-buttons li { + display: inline; + padding: 0; + margin: 0; } + .shepherd-element.shepherd-theme-arrows .shepherd-content footer .shepherd-buttons li .shepherd-button { + display: inline-block; + vertical-align: middle; + *vertical-align: auto; + *zoom: 1; + *display: inline; + -moz-border-radius: 3px; + -webkit-border-radius: 3px; + border-radius: 3px; + cursor: pointer; + border: 0; + margin: 0 0.5em 0 0; + font-family: inherit; + text-transform: uppercase; + letter-spacing: 0.1em; + font-size: 0.8em; + line-height: 1em; + padding: 0.75em 2em; + background: #3288e6; + color: #fff; } + .shepherd-element.shepherd-theme-arrows .shepherd-content footer .shepherd-buttons li .shepherd-button.shepherd-button-secondary { + background: #eee; + color: #888; } + .shepherd-element.shepherd-theme-arrows .shepherd-content footer .shepherd-buttons li:last-child .shepherd-button { + margin-right: 0; } diff --git a/frappe/public/css/shepherd/shepherd-theme-dark.css b/frappe/public/css/shepherd/shepherd-theme-dark.css new file mode 100755 index 0000000000..d079dc7139 --- /dev/null +++ b/frappe/public/css/shepherd/shepherd-theme-dark.css @@ -0,0 +1,223 @@ +.shepherd-element, .shepherd-element:after, .shepherd-element:before, .shepherd-element *, .shepherd-element *:after, .shepherd-element *:before { + -moz-box-sizing: border-box; + -webkit-box-sizing: border-box; + box-sizing: border-box; } + +.shepherd-element { + position: absolute; + display: none; } + .shepherd-element.shepherd-open { + display: block; } + +.shepherd-element.shepherd-theme-dark { + max-width: 100%; + max-height: 100%; } + .shepherd-element.shepherd-theme-dark .shepherd-content { + -moz-border-radius: 5px; + -webkit-border-radius: 5px; + border-radius: 5px; + position: relative; + font-family: inherit; + background: #232323; + color: #eee; + padding: 1em; + font-size: 1.1em; + line-height: 1.5em; } + .shepherd-element.shepherd-theme-dark .shepherd-content:before { + content: ""; + display: block; + position: absolute; + width: 0; + height: 0; + border-color: transparent; + border-width: 16px; + border-style: solid; } + .shepherd-element.shepherd-theme-dark.shepherd-element-attached-bottom.shepherd-element-attached-center .shepherd-content { + margin-bottom: 16px; } + .shepherd-element.shepherd-theme-dark.shepherd-element-attached-bottom.shepherd-element-attached-center .shepherd-content:before { + top: 100%; + left: 50%; + margin-left: -16px; + border-top-color: #232323; } + .shepherd-element.shepherd-theme-dark.shepherd-element-attached-top.shepherd-element-attached-center .shepherd-content { + margin-top: 16px; } + .shepherd-element.shepherd-theme-dark.shepherd-element-attached-top.shepherd-element-attached-center .shepherd-content:before { + bottom: 100%; + left: 50%; + margin-left: -16px; + border-bottom-color: #232323; } + .shepherd-element.shepherd-theme-dark.shepherd-element-attached-right.shepherd-element-attached-middle .shepherd-content { + margin-right: 16px; } + .shepherd-element.shepherd-theme-dark.shepherd-element-attached-right.shepherd-element-attached-middle .shepherd-content:before { + left: 100%; + top: 50%; + margin-top: -16px; + border-left-color: #232323; } + .shepherd-element.shepherd-theme-dark.shepherd-element-attached-left.shepherd-element-attached-middle .shepherd-content { + margin-left: 16px; } + .shepherd-element.shepherd-theme-dark.shepherd-element-attached-left.shepherd-element-attached-middle .shepherd-content:before { + right: 100%; + top: 50%; + margin-top: -16px; + border-right-color: #232323; } + .shepherd-element.shepherd-theme-dark.shepherd-element-attached-top.shepherd-element-attached-left.shepherd-target-attached-bottom .shepherd-content { + margin-top: 16px; } + .shepherd-element.shepherd-theme-dark.shepherd-element-attached-top.shepherd-element-attached-left.shepherd-target-attached-bottom .shepherd-content:before { + bottom: 100%; + left: 16px; + border-bottom-color: #232323; } + .shepherd-element.shepherd-theme-dark.shepherd-element-attached-top.shepherd-element-attached-right.shepherd-target-attached-bottom .shepherd-content { + margin-top: 16px; } + .shepherd-element.shepherd-theme-dark.shepherd-element-attached-top.shepherd-element-attached-right.shepherd-target-attached-bottom .shepherd-content:before { + bottom: 100%; + right: 16px; + border-bottom-color: #232323; } + .shepherd-element.shepherd-theme-dark.shepherd-element-attached-bottom.shepherd-element-attached-left.shepherd-target-attached-top .shepherd-content { + margin-bottom: 16px; } + .shepherd-element.shepherd-theme-dark.shepherd-element-attached-bottom.shepherd-element-attached-left.shepherd-target-attached-top .shepherd-content:before { + top: 100%; + left: 16px; + border-top-color: #232323; } + .shepherd-element.shepherd-theme-dark.shepherd-element-attached-bottom.shepherd-element-attached-right.shepherd-target-attached-top .shepherd-content { + margin-bottom: 16px; } + .shepherd-element.shepherd-theme-dark.shepherd-element-attached-bottom.shepherd-element-attached-right.shepherd-target-attached-top .shepherd-content:before { + top: 100%; + right: 16px; + border-top-color: #232323; } + .shepherd-element.shepherd-theme-dark.shepherd-element-attached-top.shepherd-element-attached-right.shepherd-target-attached-left .shepherd-content { + margin-right: 16px; } + .shepherd-element.shepherd-theme-dark.shepherd-element-attached-top.shepherd-element-attached-right.shepherd-target-attached-left .shepherd-content:before { + top: 16px; + left: 100%; + border-left-color: #232323; } + .shepherd-element.shepherd-theme-dark.shepherd-element-attached-top.shepherd-element-attached-left.shepherd-target-attached-right .shepherd-content { + margin-left: 16px; } + .shepherd-element.shepherd-theme-dark.shepherd-element-attached-top.shepherd-element-attached-left.shepherd-target-attached-right .shepherd-content:before { + top: 16px; + right: 100%; + border-right-color: #232323; } + .shepherd-element.shepherd-theme-dark.shepherd-element-attached-bottom.shepherd-element-attached-right.shepherd-target-attached-left .shepherd-content { + margin-right: 16px; } + .shepherd-element.shepherd-theme-dark.shepherd-element-attached-bottom.shepherd-element-attached-right.shepherd-target-attached-left .shepherd-content:before { + bottom: 16px; + left: 100%; + border-left-color: #232323; } + .shepherd-element.shepherd-theme-dark.shepherd-element-attached-bottom.shepherd-element-attached-left.shepherd-target-attached-right .shepherd-content { + margin-left: 16px; } + .shepherd-element.shepherd-theme-dark.shepherd-element-attached-bottom.shepherd-element-attached-left.shepherd-target-attached-right .shepherd-content:before { + bottom: 16px; + right: 100%; + border-right-color: #232323; } + +.shepherd-element.shepherd-theme-dark { + z-index: 9999; + max-width: 24em; + font-size: 1em; } + .shepherd-element.shepherd-theme-dark.shepherd-element-attached-top.shepherd-element-attached-center.shepherd-has-title .shepherd-content:before, .shepherd-element.shepherd-theme-dark.shepherd-element-attached-top.shepherd-element-attached-right.shepherd-target-attached-bottom.shepherd-has-title .shepherd-content:before, .shepherd-element.shepherd-theme-dark.shepherd-element-attached-top.shepherd-element-attached-left.shepherd-target-attached-bottom.shepherd-has-title .shepherd-content:before { + border-bottom-color: #303030; } + .shepherd-element.shepherd-theme-dark.shepherd-has-title .shepherd-content header { + background: #303030; + padding: 1em; } + .shepherd-element.shepherd-theme-dark.shepherd-has-title .shepherd-content header a.shepherd-cancel-link { + padding: 0; + margin-bottom: 0; } + .shepherd-element.shepherd-theme-dark.shepherd-has-cancel-link .shepherd-content header h3 { + float: left; } + .shepherd-element.shepherd-theme-dark .shepherd-content { + -moz-box-shadow: 0 0 1em rgba(0, 0, 0, 0.2); + -webkit-box-shadow: 0 0 1em rgba(0, 0, 0, 0.2); + box-shadow: 0 0 1em rgba(0, 0, 0, 0.2); + padding: 0; } + .shepherd-element.shepherd-theme-dark .shepherd-content * { + font-size: inherit; } + .shepherd-element.shepherd-theme-dark .shepherd-content header { + *zoom: 1; + -moz-border-radius: 5px 5px 0 0; + -webkit-border-radius: 5px; + border-radius: 5px 5px 0 0; } + .shepherd-element.shepherd-theme-dark .shepherd-content header:after { + content: ""; + display: table; + clear: both; } + .shepherd-element.shepherd-theme-dark .shepherd-content header h3 { + margin: 0; + line-height: 1; + font-weight: normal; } + .shepherd-element.shepherd-theme-dark .shepherd-content header a.shepherd-cancel-link { + float: right; + text-decoration: none; + font-size: 1.25em; + line-height: 0.8em; + font-weight: normal; + color: rgba(0, 0, 0, 0.5); + opacity: 0.25; + position: relative; + top: 0.1em; + padding: 0.8em; + margin-bottom: -0.8em; } + .shepherd-element.shepherd-theme-dark .shepherd-content header a.shepherd-cancel-link:hover { + opacity: 1; } + .shepherd-element.shepherd-theme-dark .shepherd-content .shepherd-text { + padding: 1em; } + .shepherd-element.shepherd-theme-dark .shepherd-content .shepherd-text p { + margin: 0 0 0.5em 0; + line-height: 1.3em; } + .shepherd-element.shepherd-theme-dark .shepherd-content .shepherd-text p:last-child { + margin-bottom: 0; } + .shepherd-element.shepherd-theme-dark .shepherd-content footer { + padding: 0 1em 1em; } + .shepherd-element.shepherd-theme-dark .shepherd-content footer .shepherd-buttons { + text-align: right; + list-style: none; + padding: 0; + margin: 0; } + .shepherd-element.shepherd-theme-dark .shepherd-content footer .shepherd-buttons li { + display: inline; + padding: 0; + margin: 0; } + .shepherd-element.shepherd-theme-dark .shepherd-content footer .shepherd-buttons li .shepherd-button { + display: inline-block; + vertical-align: middle; + *vertical-align: auto; + *zoom: 1; + *display: inline; + -moz-border-radius: 3px; + -webkit-border-radius: 3px; + border-radius: 3px; + cursor: pointer; + border: 0; + margin: 0 0.5em 0 0; + font-family: inherit; + text-transform: uppercase; + letter-spacing: 0.1em; + font-size: 0.8em; + line-height: 1em; + padding: 0.75em 2em; + background: #3288e6; + color: #fff; } + .shepherd-element.shepherd-theme-dark .shepherd-content footer .shepherd-buttons li .shepherd-button.shepherd-button-secondary { + background: #eee; + color: #888; } + .shepherd-element.shepherd-theme-dark .shepherd-content footer .shepherd-buttons li:last-child .shepherd-button { + margin-right: 0; } + +.shepherd-start-tour-button.shepherd-theme-dark { + display: inline-block; + vertical-align: middle; + *vertical-align: auto; + *zoom: 1; + *display: inline; + -moz-border-radius: 3px; + -webkit-border-radius: 3px; + border-radius: 3px; + cursor: pointer; + border: 0; + margin: 0 0.5em 0 0; + font-family: inherit; + text-transform: uppercase; + letter-spacing: 0.1em; + font-size: 0.8em; + line-height: 1em; + padding: 0.75em 2em; + background: #3288e6; + color: #fff; } diff --git a/frappe/public/css/shepherd/shepherd-theme-default.css b/frappe/public/css/shepherd/shepherd-theme-default.css new file mode 100755 index 0000000000..b6ab7e766a --- /dev/null +++ b/frappe/public/css/shepherd/shepherd-theme-default.css @@ -0,0 +1,223 @@ +.shepherd-element, .shepherd-element:after, .shepherd-element:before, .shepherd-element *, .shepherd-element *:after, .shepherd-element *:before { + -moz-box-sizing: border-box; + -webkit-box-sizing: border-box; + box-sizing: border-box; } + +.shepherd-element { + position: absolute; + display: none; } + .shepherd-element.shepherd-open { + display: block; } + +.shepherd-element.shepherd-theme-default { + max-width: 100%; + max-height: 100%; } + .shepherd-element.shepherd-theme-default .shepherd-content { + -moz-border-radius: 5px; + -webkit-border-radius: 5px; + border-radius: 5px; + position: relative; + font-family: inherit; + background: #f6f6f6; + color: #444; + padding: 1em; + font-size: 1.1em; + line-height: 1.5em; } + .shepherd-element.shepherd-theme-default .shepherd-content:before { + content: ""; + display: block; + position: absolute; + width: 0; + height: 0; + border-color: transparent; + border-width: 16px; + border-style: solid; } + .shepherd-element.shepherd-theme-default.shepherd-element-attached-bottom.shepherd-element-attached-center .shepherd-content { + margin-bottom: 16px; } + .shepherd-element.shepherd-theme-default.shepherd-element-attached-bottom.shepherd-element-attached-center .shepherd-content:before { + top: 100%; + left: 50%; + margin-left: -16px; + border-top-color: #f6f6f6; } + .shepherd-element.shepherd-theme-default.shepherd-element-attached-top.shepherd-element-attached-center .shepherd-content { + margin-top: 16px; } + .shepherd-element.shepherd-theme-default.shepherd-element-attached-top.shepherd-element-attached-center .shepherd-content:before { + bottom: 100%; + left: 50%; + margin-left: -16px; + border-bottom-color: #f6f6f6; } + .shepherd-element.shepherd-theme-default.shepherd-element-attached-right.shepherd-element-attached-middle .shepherd-content { + margin-right: 16px; } + .shepherd-element.shepherd-theme-default.shepherd-element-attached-right.shepherd-element-attached-middle .shepherd-content:before { + left: 100%; + top: 50%; + margin-top: -16px; + border-left-color: #f6f6f6; } + .shepherd-element.shepherd-theme-default.shepherd-element-attached-left.shepherd-element-attached-middle .shepherd-content { + margin-left: 16px; } + .shepherd-element.shepherd-theme-default.shepherd-element-attached-left.shepherd-element-attached-middle .shepherd-content:before { + right: 100%; + top: 50%; + margin-top: -16px; + border-right-color: #f6f6f6; } + .shepherd-element.shepherd-theme-default.shepherd-element-attached-top.shepherd-element-attached-left.shepherd-target-attached-bottom .shepherd-content { + margin-top: 16px; } + .shepherd-element.shepherd-theme-default.shepherd-element-attached-top.shepherd-element-attached-left.shepherd-target-attached-bottom .shepherd-content:before { + bottom: 100%; + left: 16px; + border-bottom-color: #f6f6f6; } + .shepherd-element.shepherd-theme-default.shepherd-element-attached-top.shepherd-element-attached-right.shepherd-target-attached-bottom .shepherd-content { + margin-top: 16px; } + .shepherd-element.shepherd-theme-default.shepherd-element-attached-top.shepherd-element-attached-right.shepherd-target-attached-bottom .shepherd-content:before { + bottom: 100%; + right: 16px; + border-bottom-color: #f6f6f6; } + .shepherd-element.shepherd-theme-default.shepherd-element-attached-bottom.shepherd-element-attached-left.shepherd-target-attached-top .shepherd-content { + margin-bottom: 16px; } + .shepherd-element.shepherd-theme-default.shepherd-element-attached-bottom.shepherd-element-attached-left.shepherd-target-attached-top .shepherd-content:before { + top: 100%; + left: 16px; + border-top-color: #f6f6f6; } + .shepherd-element.shepherd-theme-default.shepherd-element-attached-bottom.shepherd-element-attached-right.shepherd-target-attached-top .shepherd-content { + margin-bottom: 16px; } + .shepherd-element.shepherd-theme-default.shepherd-element-attached-bottom.shepherd-element-attached-right.shepherd-target-attached-top .shepherd-content:before { + top: 100%; + right: 16px; + border-top-color: #f6f6f6; } + .shepherd-element.shepherd-theme-default.shepherd-element-attached-top.shepherd-element-attached-right.shepherd-target-attached-left .shepherd-content { + margin-right: 16px; } + .shepherd-element.shepherd-theme-default.shepherd-element-attached-top.shepherd-element-attached-right.shepherd-target-attached-left .shepherd-content:before { + top: 16px; + left: 100%; + border-left-color: #f6f6f6; } + .shepherd-element.shepherd-theme-default.shepherd-element-attached-top.shepherd-element-attached-left.shepherd-target-attached-right .shepherd-content { + margin-left: 16px; } + .shepherd-element.shepherd-theme-default.shepherd-element-attached-top.shepherd-element-attached-left.shepherd-target-attached-right .shepherd-content:before { + top: 16px; + right: 100%; + border-right-color: #f6f6f6; } + .shepherd-element.shepherd-theme-default.shepherd-element-attached-bottom.shepherd-element-attached-right.shepherd-target-attached-left .shepherd-content { + margin-right: 16px; } + .shepherd-element.shepherd-theme-default.shepherd-element-attached-bottom.shepherd-element-attached-right.shepherd-target-attached-left .shepherd-content:before { + bottom: 16px; + left: 100%; + border-left-color: #f6f6f6; } + .shepherd-element.shepherd-theme-default.shepherd-element-attached-bottom.shepherd-element-attached-left.shepherd-target-attached-right .shepherd-content { + margin-left: 16px; } + .shepherd-element.shepherd-theme-default.shepherd-element-attached-bottom.shepherd-element-attached-left.shepherd-target-attached-right .shepherd-content:before { + bottom: 16px; + right: 100%; + border-right-color: #f6f6f6; } + +.shepherd-element.shepherd-theme-default { + z-index: 9999; + max-width: 24em; + font-size: 1em; } + .shepherd-element.shepherd-theme-default.shepherd-element-attached-top.shepherd-element-attached-center.shepherd-has-title .shepherd-content:before, .shepherd-element.shepherd-theme-default.shepherd-element-attached-top.shepherd-element-attached-right.shepherd-target-attached-bottom.shepherd-has-title .shepherd-content:before, .shepherd-element.shepherd-theme-default.shepherd-element-attached-top.shepherd-element-attached-left.shepherd-target-attached-bottom.shepherd-has-title .shepherd-content:before { + border-bottom-color: #e6e6e6; } + .shepherd-element.shepherd-theme-default.shepherd-has-title .shepherd-content header { + background: #e6e6e6; + padding: 1em; } + .shepherd-element.shepherd-theme-default.shepherd-has-title .shepherd-content header a.shepherd-cancel-link { + padding: 0; + margin-bottom: 0; } + .shepherd-element.shepherd-theme-default.shepherd-has-cancel-link .shepherd-content header h3 { + float: left; } + .shepherd-element.shepherd-theme-default .shepherd-content { + -moz-box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.17); + -webkit-box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.17); + box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.17); + padding: 0; } + .shepherd-element.shepherd-theme-default .shepherd-content * { + font-size: inherit; } + .shepherd-element.shepherd-theme-default .shepherd-content header { + *zoom: 1; + -moz-border-radius: 5px 5px 0 0; + -webkit-border-radius: 5px; + border-radius: 5px 5px 0 0; } + .shepherd-element.shepherd-theme-default .shepherd-content header:after { + content: ""; + display: table; + clear: both; } + .shepherd-element.shepherd-theme-default .shepherd-content header h3 { + margin: 0; + line-height: 1; + font-weight: normal; } + .shepherd-element.shepherd-theme-default .shepherd-content header a.shepherd-cancel-link { + float: right; + text-decoration: none; + font-size: 1.25em; + line-height: 0.8em; + font-weight: normal; + color: rgba(0, 0, 0, 0.5); + opacity: 0.25; + position: relative; + top: 0.1em; + padding: 0.8em; + margin-bottom: -0.8em; } + .shepherd-element.shepherd-theme-default .shepherd-content header a.shepherd-cancel-link:hover { + opacity: 1; } + .shepherd-element.shepherd-theme-default .shepherd-content .shepherd-text { + padding: 1em; } + .shepherd-element.shepherd-theme-default .shepherd-content .shepherd-text p { + margin: 0 0 0.5em 0; + line-height: 1.3em; } + .shepherd-element.shepherd-theme-default .shepherd-content .shepherd-text p:last-child { + margin-bottom: 0; } + .shepherd-element.shepherd-theme-default .shepherd-content footer { + padding: 0 1em 1em; } + .shepherd-element.shepherd-theme-default .shepherd-content footer .shepherd-buttons { + text-align: right; + list-style: none; + padding: 0; + margin: 0; } + .shepherd-element.shepherd-theme-default .shepherd-content footer .shepherd-buttons li { + display: inline; + padding: 0; + margin: 0; } + .shepherd-element.shepherd-theme-default .shepherd-content footer .shepherd-buttons li .shepherd-button { + display: inline-block; + vertical-align: middle; + *vertical-align: auto; + *zoom: 1; + *display: inline; + -moz-border-radius: 3px; + -webkit-border-radius: 3px; + border-radius: 3px; + cursor: pointer; + border: 0; + margin: 0 0.5em 0 0; + font-family: inherit; + text-transform: uppercase; + letter-spacing: 0.1em; + font-size: 0.8em; + line-height: 1em; + padding: 0.75em 2em; + background: #3288e6; + color: #fff; } + .shepherd-element.shepherd-theme-default .shepherd-content footer .shepherd-buttons li .shepherd-button.shepherd-button-secondary { + background: #eee; + color: #888; } + .shepherd-element.shepherd-theme-default .shepherd-content footer .shepherd-buttons li:last-child .shepherd-button { + margin-right: 0; } + +.shepherd-start-tour-button.shepherd-theme-default { + display: inline-block; + vertical-align: middle; + *vertical-align: auto; + *zoom: 1; + *display: inline; + -moz-border-radius: 3px; + -webkit-border-radius: 3px; + border-radius: 3px; + cursor: pointer; + border: 0; + margin: 0 0.5em 0 0; + font-family: inherit; + text-transform: uppercase; + letter-spacing: 0.1em; + font-size: 0.8em; + line-height: 1em; + padding: 0.75em 2em; + background: #3288e6; + color: #fff; } diff --git a/frappe/public/css/shepherd/shepherd-theme-square-dark.css b/frappe/public/css/shepherd/shepherd-theme-square-dark.css new file mode 100755 index 0000000000..c941280510 --- /dev/null +++ b/frappe/public/css/shepherd/shepherd-theme-square-dark.css @@ -0,0 +1,229 @@ +.shepherd-element, .shepherd-element:after, .shepherd-element:before, .shepherd-element *, .shepherd-element *:after, .shepherd-element *:before { + -moz-box-sizing: border-box; + -webkit-box-sizing: border-box; + box-sizing: border-box; } + +.shepherd-element { + position: absolute; + display: none; } + .shepherd-element.shepherd-open { + display: block; } + +.shepherd-element.shepherd-theme-square-dark { + max-width: 100%; + max-height: 100%; } + .shepherd-element.shepherd-theme-square-dark .shepherd-content { + -moz-border-radius: 5px; + -webkit-border-radius: 5px; + border-radius: 5px; + position: relative; + font-family: inherit; + background: #232323; + color: #eee; + padding: 1em; + font-size: 1.1em; + line-height: 1.5em; } + .shepherd-element.shepherd-theme-square-dark .shepherd-content:before { + content: ""; + display: block; + position: absolute; + width: 0; + height: 0; + border-color: transparent; + border-width: 16px; + border-style: solid; } + .shepherd-element.shepherd-theme-square-dark.shepherd-element-attached-bottom.shepherd-element-attached-center .shepherd-content { + margin-bottom: 16px; } + .shepherd-element.shepherd-theme-square-dark.shepherd-element-attached-bottom.shepherd-element-attached-center .shepherd-content:before { + top: 100%; + left: 50%; + margin-left: -16px; + border-top-color: #232323; } + .shepherd-element.shepherd-theme-square-dark.shepherd-element-attached-top.shepherd-element-attached-center .shepherd-content { + margin-top: 16px; } + .shepherd-element.shepherd-theme-square-dark.shepherd-element-attached-top.shepherd-element-attached-center .shepherd-content:before { + bottom: 100%; + left: 50%; + margin-left: -16px; + border-bottom-color: #232323; } + .shepherd-element.shepherd-theme-square-dark.shepherd-element-attached-right.shepherd-element-attached-middle .shepherd-content { + margin-right: 16px; } + .shepherd-element.shepherd-theme-square-dark.shepherd-element-attached-right.shepherd-element-attached-middle .shepherd-content:before { + left: 100%; + top: 50%; + margin-top: -16px; + border-left-color: #232323; } + .shepherd-element.shepherd-theme-square-dark.shepherd-element-attached-left.shepherd-element-attached-middle .shepherd-content { + margin-left: 16px; } + .shepherd-element.shepherd-theme-square-dark.shepherd-element-attached-left.shepherd-element-attached-middle .shepherd-content:before { + right: 100%; + top: 50%; + margin-top: -16px; + border-right-color: #232323; } + .shepherd-element.shepherd-theme-square-dark.shepherd-element-attached-top.shepherd-element-attached-left.shepherd-target-attached-bottom .shepherd-content { + margin-top: 16px; } + .shepherd-element.shepherd-theme-square-dark.shepherd-element-attached-top.shepherd-element-attached-left.shepherd-target-attached-bottom .shepherd-content:before { + bottom: 100%; + left: 16px; + border-bottom-color: #232323; } + .shepherd-element.shepherd-theme-square-dark.shepherd-element-attached-top.shepherd-element-attached-right.shepherd-target-attached-bottom .shepherd-content { + margin-top: 16px; } + .shepherd-element.shepherd-theme-square-dark.shepherd-element-attached-top.shepherd-element-attached-right.shepherd-target-attached-bottom .shepherd-content:before { + bottom: 100%; + right: 16px; + border-bottom-color: #232323; } + .shepherd-element.shepherd-theme-square-dark.shepherd-element-attached-bottom.shepherd-element-attached-left.shepherd-target-attached-top .shepherd-content { + margin-bottom: 16px; } + .shepherd-element.shepherd-theme-square-dark.shepherd-element-attached-bottom.shepherd-element-attached-left.shepherd-target-attached-top .shepherd-content:before { + top: 100%; + left: 16px; + border-top-color: #232323; } + .shepherd-element.shepherd-theme-square-dark.shepherd-element-attached-bottom.shepherd-element-attached-right.shepherd-target-attached-top .shepherd-content { + margin-bottom: 16px; } + .shepherd-element.shepherd-theme-square-dark.shepherd-element-attached-bottom.shepherd-element-attached-right.shepherd-target-attached-top .shepherd-content:before { + top: 100%; + right: 16px; + border-top-color: #232323; } + .shepherd-element.shepherd-theme-square-dark.shepherd-element-attached-top.shepherd-element-attached-right.shepherd-target-attached-left .shepherd-content { + margin-right: 16px; } + .shepherd-element.shepherd-theme-square-dark.shepherd-element-attached-top.shepherd-element-attached-right.shepherd-target-attached-left .shepherd-content:before { + top: 16px; + left: 100%; + border-left-color: #232323; } + .shepherd-element.shepherd-theme-square-dark.shepherd-element-attached-top.shepherd-element-attached-left.shepherd-target-attached-right .shepherd-content { + margin-left: 16px; } + .shepherd-element.shepherd-theme-square-dark.shepherd-element-attached-top.shepherd-element-attached-left.shepherd-target-attached-right .shepherd-content:before { + top: 16px; + right: 100%; + border-right-color: #232323; } + .shepherd-element.shepherd-theme-square-dark.shepherd-element-attached-bottom.shepherd-element-attached-right.shepherd-target-attached-left .shepherd-content { + margin-right: 16px; } + .shepherd-element.shepherd-theme-square-dark.shepherd-element-attached-bottom.shepherd-element-attached-right.shepherd-target-attached-left .shepherd-content:before { + bottom: 16px; + left: 100%; + border-left-color: #232323; } + .shepherd-element.shepherd-theme-square-dark.shepherd-element-attached-bottom.shepherd-element-attached-left.shepherd-target-attached-right .shepherd-content { + margin-left: 16px; } + .shepherd-element.shepherd-theme-square-dark.shepherd-element-attached-bottom.shepherd-element-attached-left.shepherd-target-attached-right .shepherd-content:before { + bottom: 16px; + right: 100%; + border-right-color: #232323; } + +.shepherd-element.shepherd-theme-square-dark { + -moz-border-radius: 0; + -webkit-border-radius: 0; + border-radius: 0; + z-index: 9999; + max-width: 24em; + font-size: 1em; } + .shepherd-element.shepherd-theme-square-dark.shepherd-element-attached-top.shepherd-element-attached-center.shepherd-has-title .shepherd-content:before, .shepherd-element.shepherd-theme-square-dark.shepherd-element-attached-top.shepherd-element-attached-right.shepherd-target-attached-bottom.shepherd-has-title .shepherd-content:before, .shepherd-element.shepherd-theme-square-dark.shepherd-element-attached-top.shepherd-element-attached-left.shepherd-target-attached-bottom.shepherd-has-title .shepherd-content:before { + border-bottom-color: #303030; } + .shepherd-element.shepherd-theme-square-dark.shepherd-has-title .shepherd-content header { + background: #303030; + padding: 1em; } + .shepherd-element.shepherd-theme-square-dark.shepherd-has-title .shepherd-content header a.shepherd-cancel-link { + padding: 0; + margin-bottom: 0; } + .shepherd-element.shepherd-theme-square-dark.shepherd-has-cancel-link .shepherd-content header h3 { + float: left; } + .shepherd-element.shepherd-theme-square-dark .shepherd-content { + -moz-box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.17); + -webkit-box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.17); + box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.17); + -moz-border-radius: 0; + -webkit-border-radius: 0; + border-radius: 0; + padding: 0; } + .shepherd-element.shepherd-theme-square-dark .shepherd-content * { + font-size: inherit; } + .shepherd-element.shepherd-theme-square-dark .shepherd-content header { + *zoom: 1; + -moz-border-radius: 0; + -webkit-border-radius: 0; + border-radius: 0; } + .shepherd-element.shepherd-theme-square-dark .shepherd-content header:after { + content: ""; + display: table; + clear: both; } + .shepherd-element.shepherd-theme-square-dark .shepherd-content header h3 { + margin: 0; + line-height: 1; + font-weight: normal; } + .shepherd-element.shepherd-theme-square-dark .shepherd-content header a.shepherd-cancel-link { + float: right; + text-decoration: none; + font-size: 1.25em; + line-height: 0.8em; + font-weight: normal; + color: rgba(0, 0, 0, 0.5); + opacity: 0.25; + position: relative; + top: 0.1em; + padding: 0.8em; + margin-bottom: -0.8em; } + .shepherd-element.shepherd-theme-square-dark .shepherd-content header a.shepherd-cancel-link:hover { + opacity: 1; } + .shepherd-element.shepherd-theme-square-dark .shepherd-content .shepherd-text { + padding: 1em; } + .shepherd-element.shepherd-theme-square-dark .shepherd-content .shepherd-text p { + margin: 0 0 0.5em 0; + line-height: 1.3em; } + .shepherd-element.shepherd-theme-square-dark .shepherd-content .shepherd-text p:last-child { + margin-bottom: 0; } + .shepherd-element.shepherd-theme-square-dark .shepherd-content footer { + padding: 0 1em 1em; } + .shepherd-element.shepherd-theme-square-dark .shepherd-content footer .shepherd-buttons { + text-align: right; + list-style: none; + padding: 0; + margin: 0; } + .shepherd-element.shepherd-theme-square-dark .shepherd-content footer .shepherd-buttons li { + display: inline; + padding: 0; + margin: 0; } + .shepherd-element.shepherd-theme-square-dark .shepherd-content footer .shepherd-buttons li .shepherd-button { + display: inline-block; + vertical-align: middle; + *vertical-align: auto; + *zoom: 1; + *display: inline; + -moz-border-radius: 0; + -webkit-border-radius: 0; + border-radius: 0; + cursor: pointer; + border: 0; + margin: 0 0.5em 0 0; + font-family: inherit; + text-transform: uppercase; + letter-spacing: 0.1em; + font-size: 0.8em; + line-height: 1em; + padding: 0.75em 2em; + background: #3288e6; + color: #fff; } + .shepherd-element.shepherd-theme-square-dark .shepherd-content footer .shepherd-buttons li .shepherd-button.shepherd-button-secondary { + background: #eee; + color: #888; } + .shepherd-element.shepherd-theme-square-dark .shepherd-content footer .shepherd-buttons li:last-child .shepherd-button { + margin-right: 0; } + +.shepherd-start-tour-button.shepherd-theme-square-dark { + display: inline-block; + vertical-align: middle; + *vertical-align: auto; + *zoom: 1; + *display: inline; + -moz-border-radius: 0; + -webkit-border-radius: 0; + border-radius: 0; + cursor: pointer; + border: 0; + margin: 0 0.5em 0 0; + font-family: inherit; + text-transform: uppercase; + letter-spacing: 0.1em; + font-size: 0.8em; + line-height: 1em; + padding: 0.75em 2em; + background: #3288e6; + color: #fff; } diff --git a/frappe/public/css/shepherd/shepherd-theme-square.css b/frappe/public/css/shepherd/shepherd-theme-square.css new file mode 100755 index 0000000000..4faba44d9b --- /dev/null +++ b/frappe/public/css/shepherd/shepherd-theme-square.css @@ -0,0 +1,229 @@ +.shepherd-element, .shepherd-element:after, .shepherd-element:before, .shepherd-element *, .shepherd-element *:after, .shepherd-element *:before { + -moz-box-sizing: border-box; + -webkit-box-sizing: border-box; + box-sizing: border-box; } + +.shepherd-element { + position: absolute; + display: none; } + .shepherd-element.shepherd-open { + display: block; } + +.shepherd-element.shepherd-theme-square { + max-width: 100%; + max-height: 100%; } + .shepherd-element.shepherd-theme-square .shepherd-content { + -moz-border-radius: 5px; + -webkit-border-radius: 5px; + border-radius: 5px; + position: relative; + font-family: inherit; + background: #f6f6f6; + color: #444; + padding: 1em; + font-size: 1.1em; + line-height: 1.5em; } + .shepherd-element.shepherd-theme-square .shepherd-content:before { + content: ""; + display: block; + position: absolute; + width: 0; + height: 0; + border-color: transparent; + border-width: 16px; + border-style: solid; } + .shepherd-element.shepherd-theme-square.shepherd-element-attached-bottom.shepherd-element-attached-center .shepherd-content { + margin-bottom: 16px; } + .shepherd-element.shepherd-theme-square.shepherd-element-attached-bottom.shepherd-element-attached-center .shepherd-content:before { + top: 100%; + left: 50%; + margin-left: -16px; + border-top-color: #f6f6f6; } + .shepherd-element.shepherd-theme-square.shepherd-element-attached-top.shepherd-element-attached-center .shepherd-content { + margin-top: 16px; } + .shepherd-element.shepherd-theme-square.shepherd-element-attached-top.shepherd-element-attached-center .shepherd-content:before { + bottom: 100%; + left: 50%; + margin-left: -16px; + border-bottom-color: #f6f6f6; } + .shepherd-element.shepherd-theme-square.shepherd-element-attached-right.shepherd-element-attached-middle .shepherd-content { + margin-right: 16px; } + .shepherd-element.shepherd-theme-square.shepherd-element-attached-right.shepherd-element-attached-middle .shepherd-content:before { + left: 100%; + top: 50%; + margin-top: -16px; + border-left-color: #f6f6f6; } + .shepherd-element.shepherd-theme-square.shepherd-element-attached-left.shepherd-element-attached-middle .shepherd-content { + margin-left: 16px; } + .shepherd-element.shepherd-theme-square.shepherd-element-attached-left.shepherd-element-attached-middle .shepherd-content:before { + right: 100%; + top: 50%; + margin-top: -16px; + border-right-color: #f6f6f6; } + .shepherd-element.shepherd-theme-square.shepherd-element-attached-top.shepherd-element-attached-left.shepherd-target-attached-bottom .shepherd-content { + margin-top: 16px; } + .shepherd-element.shepherd-theme-square.shepherd-element-attached-top.shepherd-element-attached-left.shepherd-target-attached-bottom .shepherd-content:before { + bottom: 100%; + left: 16px; + border-bottom-color: #f6f6f6; } + .shepherd-element.shepherd-theme-square.shepherd-element-attached-top.shepherd-element-attached-right.shepherd-target-attached-bottom .shepherd-content { + margin-top: 16px; } + .shepherd-element.shepherd-theme-square.shepherd-element-attached-top.shepherd-element-attached-right.shepherd-target-attached-bottom .shepherd-content:before { + bottom: 100%; + right: 16px; + border-bottom-color: #f6f6f6; } + .shepherd-element.shepherd-theme-square.shepherd-element-attached-bottom.shepherd-element-attached-left.shepherd-target-attached-top .shepherd-content { + margin-bottom: 16px; } + .shepherd-element.shepherd-theme-square.shepherd-element-attached-bottom.shepherd-element-attached-left.shepherd-target-attached-top .shepherd-content:before { + top: 100%; + left: 16px; + border-top-color: #f6f6f6; } + .shepherd-element.shepherd-theme-square.shepherd-element-attached-bottom.shepherd-element-attached-right.shepherd-target-attached-top .shepherd-content { + margin-bottom: 16px; } + .shepherd-element.shepherd-theme-square.shepherd-element-attached-bottom.shepherd-element-attached-right.shepherd-target-attached-top .shepherd-content:before { + top: 100%; + right: 16px; + border-top-color: #f6f6f6; } + .shepherd-element.shepherd-theme-square.shepherd-element-attached-top.shepherd-element-attached-right.shepherd-target-attached-left .shepherd-content { + margin-right: 16px; } + .shepherd-element.shepherd-theme-square.shepherd-element-attached-top.shepherd-element-attached-right.shepherd-target-attached-left .shepherd-content:before { + top: 16px; + left: 100%; + border-left-color: #f6f6f6; } + .shepherd-element.shepherd-theme-square.shepherd-element-attached-top.shepherd-element-attached-left.shepherd-target-attached-right .shepherd-content { + margin-left: 16px; } + .shepherd-element.shepherd-theme-square.shepherd-element-attached-top.shepherd-element-attached-left.shepherd-target-attached-right .shepherd-content:before { + top: 16px; + right: 100%; + border-right-color: #f6f6f6; } + .shepherd-element.shepherd-theme-square.shepherd-element-attached-bottom.shepherd-element-attached-right.shepherd-target-attached-left .shepherd-content { + margin-right: 16px; } + .shepherd-element.shepherd-theme-square.shepherd-element-attached-bottom.shepherd-element-attached-right.shepherd-target-attached-left .shepherd-content:before { + bottom: 16px; + left: 100%; + border-left-color: #f6f6f6; } + .shepherd-element.shepherd-theme-square.shepherd-element-attached-bottom.shepherd-element-attached-left.shepherd-target-attached-right .shepherd-content { + margin-left: 16px; } + .shepherd-element.shepherd-theme-square.shepherd-element-attached-bottom.shepherd-element-attached-left.shepherd-target-attached-right .shepherd-content:before { + bottom: 16px; + right: 100%; + border-right-color: #f6f6f6; } + +.shepherd-element.shepherd-theme-square { + -moz-border-radius: 0; + -webkit-border-radius: 0; + border-radius: 0; + z-index: 9999; + max-width: 24em; + font-size: 1em; } + .shepherd-element.shepherd-theme-square.shepherd-element-attached-top.shepherd-element-attached-center.shepherd-has-title .shepherd-content:before, .shepherd-element.shepherd-theme-square.shepherd-element-attached-top.shepherd-element-attached-right.shepherd-target-attached-bottom.shepherd-has-title .shepherd-content:before, .shepherd-element.shepherd-theme-square.shepherd-element-attached-top.shepherd-element-attached-left.shepherd-target-attached-bottom.shepherd-has-title .shepherd-content:before { + border-bottom-color: #e6e6e6; } + .shepherd-element.shepherd-theme-square.shepherd-has-title .shepherd-content header { + background: #e6e6e6; + padding: 1em; } + .shepherd-element.shepherd-theme-square.shepherd-has-title .shepherd-content header a.shepherd-cancel-link { + padding: 0; + margin-bottom: 0; } + .shepherd-element.shepherd-theme-square.shepherd-has-cancel-link .shepherd-content header h3 { + float: left; } + .shepherd-element.shepherd-theme-square .shepherd-content { + -moz-box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.17); + -webkit-box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.17); + box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.17); + -moz-border-radius: 0; + -webkit-border-radius: 0; + border-radius: 0; + padding: 0; } + .shepherd-element.shepherd-theme-square .shepherd-content * { + font-size: inherit; } + .shepherd-element.shepherd-theme-square .shepherd-content header { + *zoom: 1; + -moz-border-radius: 0; + -webkit-border-radius: 0; + border-radius: 0; } + .shepherd-element.shepherd-theme-square .shepherd-content header:after { + content: ""; + display: table; + clear: both; } + .shepherd-element.shepherd-theme-square .shepherd-content header h3 { + margin: 0; + line-height: 1; + font-weight: normal; } + .shepherd-element.shepherd-theme-square .shepherd-content header a.shepherd-cancel-link { + float: right; + text-decoration: none; + font-size: 1.25em; + line-height: 0.8em; + font-weight: normal; + color: rgba(0, 0, 0, 0.5); + opacity: 0.25; + position: relative; + top: 0.1em; + padding: 0.8em; + margin-bottom: -0.8em; } + .shepherd-element.shepherd-theme-square .shepherd-content header a.shepherd-cancel-link:hover { + opacity: 1; } + .shepherd-element.shepherd-theme-square .shepherd-content .shepherd-text { + padding: 1em; } + .shepherd-element.shepherd-theme-square .shepherd-content .shepherd-text p { + margin: 0 0 0.5em 0; + line-height: 1.3em; } + .shepherd-element.shepherd-theme-square .shepherd-content .shepherd-text p:last-child { + margin-bottom: 0; } + .shepherd-element.shepherd-theme-square .shepherd-content footer { + padding: 0 1em 1em; } + .shepherd-element.shepherd-theme-square .shepherd-content footer .shepherd-buttons { + text-align: right; + list-style: none; + padding: 0; + margin: 0; } + .shepherd-element.shepherd-theme-square .shepherd-content footer .shepherd-buttons li { + display: inline; + padding: 0; + margin: 0; } + .shepherd-element.shepherd-theme-square .shepherd-content footer .shepherd-buttons li .shepherd-button { + display: inline-block; + vertical-align: middle; + *vertical-align: auto; + *zoom: 1; + *display: inline; + -moz-border-radius: 0; + -webkit-border-radius: 0; + border-radius: 0; + cursor: pointer; + border: 0; + margin: 0 0.5em 0 0; + font-family: inherit; + text-transform: uppercase; + letter-spacing: 0.1em; + font-size: 0.8em; + line-height: 1em; + padding: 0.75em 2em; + background: #3288e6; + color: #fff; } + .shepherd-element.shepherd-theme-square .shepherd-content footer .shepherd-buttons li .shepherd-button.shepherd-button-secondary { + background: #eee; + color: #888; } + .shepherd-element.shepherd-theme-square .shepherd-content footer .shepherd-buttons li:last-child .shepherd-button { + margin-right: 0; } + +.shepherd-start-tour-button.shepherd-theme-square { + display: inline-block; + vertical-align: middle; + *vertical-align: auto; + *zoom: 1; + *display: inline; + -moz-border-radius: 0; + -webkit-border-radius: 0; + border-radius: 0; + cursor: pointer; + border: 0; + margin: 0 0.5em 0 0; + font-family: inherit; + text-transform: uppercase; + letter-spacing: 0.1em; + font-size: 0.8em; + line-height: 1em; + padding: 0.75em 2em; + background: #3288e6; + color: #fff; } diff --git a/frappe/public/css/sidebar.css b/frappe/public/css/sidebar.css index aa04584a8f..c9a03858a6 100644 --- a/frappe/public/css/sidebar.css +++ b/frappe/public/css/sidebar.css @@ -140,11 +140,22 @@ body[data-route^="Module"] .main-menu .form-sidebar { .form-sidebar .form-shared .share-doc-btn { cursor: pointer; } -.form-sidebar .form-shared .octicon-plus { +.form-sidebar .form-shared .octicon { position: relative; top: 2px; left: 7px; } +.form-sidebar .form-shared .avatar { + margin-top: 5px; +} +.form-sidebar .form-shared .shared-with-everyone { + border-style: solid; + border-color: #f0f4f7; + background-color: #f0f4f7; +} +.form-sidebar .form-shared .shared-with-everyone .octicon { + color: #36414c !important; +} .form-sidebar .form-shared .share-doc-btn:hover, .form-sidebar .form-shared .share-doc-btn:focus, .form-sidebar .form-shared .share-doc-btn:active { diff --git a/frappe/public/css/website.css b/frappe/public/css/website.css index f3b3ad1c44..74a50bf87b 100644 --- a/frappe/public/css/website.css +++ b/frappe/public/css/website.css @@ -285,6 +285,7 @@ body { } .avatar-empty { border: 1px dashed #d1d8dd; + border-radius: 4px; } .avatar-small { margin-right: 5px; @@ -459,6 +460,10 @@ body { .panel-body { padding-left: 15px; } +.page-header-actions-block { + padding-top: 20px; + text-align: right; +} fieldset { margin-bottom: 20px; } @@ -529,8 +534,18 @@ fieldset { border-top: 1px solid #d1d8dd; } /* post and post list */ +.list-group-item { + border-radius: 0px !important; +} +.website-list { + min-height: 200px; + padding-bottom: 15px; +} +.website-list .result { + border: 1px solid #d1d8dd; +} .web-list-item { - padding: 5px 0px; + padding: 10px; border-bottom: 1px solid #d1d8dd; } .web-list-item h1, @@ -547,9 +562,8 @@ fieldset { color: inherit !important; text-decoration: none; } -.web-list-item:first-child { - margin-top: -1px; - border-top: 1px solid #d1d8dd; +.web-list-item:hover { + background: #f7fafc; } .web-list-item:last-child { border-bottom: none; @@ -559,8 +573,20 @@ fieldset { border-top: 1px solid #d1d8dd; margin: 0px -15px -20px -15px; } +.blog-list-content .website-list .result { + border: 0px; +} +.blog-list-content .web-list-item { + padding: 0px; +} +.blog-list-content .web-list-item:hover { + background: transparent; +} .longform { padding: 15px 0px; + line-height: 1.5; + font-size: 1.1em; + max-width: 700px; } .longform p { margin-bottom: 30px; @@ -586,6 +612,7 @@ fieldset { } .blog-comment-row:last-child { margin-bottom: 30px; + border-bottom: 0px; } textarea { resize: vertical; diff --git a/frappe/public/images/favicon.png b/frappe/public/images/favicon.png index 00d97cb834..62ff240fb2 100644 Binary files a/frappe/public/images/favicon.png and b/frappe/public/images/favicon.png differ diff --git a/frappe/public/images/frappe.svg b/frappe/public/images/frappe.svg deleted file mode 100644 index 6b6ea9df2b..0000000000 --- a/frappe/public/images/frappe.svg +++ /dev/null @@ -1,92 +0,0 @@ - - - -image/svg+xml - - - - - - - diff --git a/frappe/public/js/frappe/assets.js b/frappe/public/js/frappe/assets.js index 7340b19ae4..018e0a7c4e 100644 --- a/frappe/public/js/frappe/assets.js +++ b/frappe/public/js/frappe/assets.js @@ -92,6 +92,7 @@ frappe.assets = { // *without* the template frappe.call({ + type: "GET", method:"frappe.client.get_js", args: { "src": src diff --git a/frappe/public/js/frappe/desk.js b/frappe/public/js/frappe/desk.js index 007efdfd45..8e5c45559b 100644 --- a/frappe/public/js/frappe/desk.js +++ b/frappe/public/js/frappe/desk.js @@ -69,8 +69,15 @@ frappe.Application = Class.extend({ this.check_metadata_cache_status(); this.set_globals(); this.sync_pages(); + moment.locale(frappe.boot.lang); if(frappe.boot.timezone_info) { moment.tz.add(frappe.boot.timezone_info); + if(sys_defaults.time_zone) { + moment.system_utc_offset = moment().tz(sys_defaults.time_zone).utcOffset(); + } else { + moment.system_utc_offset = moment().utcOffset(); + } + moment.user_utc_offset = moment().utcOffset(); } if(frappe.boot.print_css) { frappe.dom.set_style(frappe.boot.print_css) diff --git a/frappe/public/js/frappe/dom.js b/frappe/public/js/frappe/dom.js index 1334922733..386e40d884 100644 --- a/frappe/public/js/frappe/dom.js +++ b/frappe/public/js/frappe/dom.js @@ -24,10 +24,20 @@ frappe.dom = { // execute the script globally document.getElementsByTagName('head')[0].appendChild(el); }, - set_style: function(txt) { + set_style: function(txt, id) { if(!txt) return; + var se = document.createElement('style'); se.type = "text/css"; + + if (id) { + var element = document.getElementById(id); + if (element) { + element.parentNode.removeChild(element); + } + se.id = id; + } + if (se.styleSheet) { se.styleSheet.cssText = txt; } else { diff --git a/frappe/public/js/frappe/form/control.js b/frappe/public/js/frappe/form/control.js index 8701e59f33..4b2e5cf7b7 100644 --- a/frappe/public/js/frappe/form/control.js +++ b/frappe/public/js/frappe/form/control.js @@ -28,8 +28,8 @@ frappe.ui.form.Control = Class.extend({ make: function() { this.make_wrapper(); this.$wrapper - .addClass("ui-front") - .attr("data-fieldtype", this.df.fieldtype); + .attr("data-fieldtype", this.df.fieldtype) + .attr("data-fieldname", this.df.fieldname); this.wrapper = this.$wrapper.get(0); this.wrapper.fieldobj = this; // reference for event handlers }, @@ -505,10 +505,16 @@ frappe.ui.form.ControlDate = frappe.ui.form.ControlData.extend({ this.$input.datepicker(this.datepicker_options); }, parse: function(value) { - return value ? dateutil.user_to_str(value) : value; + if(value) { + value = dateutil.user_to_str(value); + } + return value; }, format_for_input: function(value) { - return value ? dateutil.str_to_user(value) : ""; + if(value) { + value = dateutil.str_to_user(value); + } + return value || ""; }, validate: function(value, callback) { if(!dateutil.validate(value)) { @@ -541,9 +547,13 @@ frappe.ui.form.ControlTime = frappe.ui.form.ControlData.extend({ frappe.ui.form.ControlDatetime = frappe.ui.form.ControlDate.extend({ set_datepicker: function() { - this.datepicker_options.timeFormat = "HH:mm:ss"; - this.datepicker_options.dateFormat = - (frappe.boot.sysdefaults.date_format || 'yy-mm-dd').replace('yyyy','yy'); + var now = new Date(); + $.extend(this.datepicker_options, { + "timeFormat": "HH:mm:ss", + "dateFormat": (frappe.boot.sysdefaults.date_format || 'yy-mm-dd').replace('yyyy','yy'), + "hour": now.getHours(), + "minute": now.getMinutes() + }); this.$input.datetimepicker(this.datepicker_options); }, @@ -551,6 +561,21 @@ frappe.ui.form.ControlDatetime = frappe.ui.form.ControlDate.extend({ import_timepicker(); this._super(); }, + parse: function(value) { + if(value) { + // parse and convert + value = dateutil.convert_to_system_tz(dateutil.user_to_str(value)); + } + return value; + }, + format_for_input: function(value) { + if(value) { + // convert and format + value = dateutil.str_to_user(dateutil.convert_to_user_tz(value)); + + } + return value || ""; + }, }); @@ -912,7 +937,7 @@ frappe.ui.form.ControlSelect = frappe.ui.form.ControlData.extend({ frappe.ui.form.ControlLink = frappe.ui.form.ControlData.extend({ make_input: function() { var me = this; - $('').appendTo(this.section.body) - .find("form") - .on("submit", function() { return false; }) - - // distribute all columns equally - var colspan = cint(12 / this.section.find(".form-column").length); - this.section.find(".form-column").removeClass() - .addClass("form-column") - .addClass("col-sm-" + colspan); - }, make_field: function(df, colspan) { !this.section && this.make_section(); !this.column && this.make_column(); @@ -174,7 +167,7 @@ frappe.ui.form.Layout = Class.extend({ section.df = df; if(df) { if(df.label) { - $('

' + __(df.label) + '

') + $('

' + __(df.label) + '

') .appendTo(this.section); } if(df.description) { @@ -191,24 +184,49 @@ frappe.ui.form.Layout = Class.extend({ section.row = { wrapper: section }; + section.layout = me; section.refresh = function() { - if(!this.df) - return; - - // hide if explictly hidden - var hide = this.df.hidden || this.df.hidden_due_to_dependency; - - // hide if no perm - if(!hide && me.frm && !me.frm.get_perm(this.df.permlevel || 0, "read")) { - hide = true; - } - - $(this).toggleClass("hide-control", !!hide); + frappe.ui.section_refresh.apply(this); } this.column = null; section.refresh.call(section); return this.section; }, + make_column: function(df) { + if(!df) df = {}; + + var column = $('
\ +
\ +
\ +
').appendTo(this.section.body) + .find("form") + .on("submit", function() { return false; }) + + if(df.label) { + $('').appendTo(column); + } + + // distribute all columns equally + var colspan = cint(12 / this.section.find(".form-column").length); + this.section.find(".form-column").removeClass() + .addClass("form-column") + .addClass("col-sm-" + colspan); + + column.df = df; + column.layout = this; + + //this.fields_dict[df.fieldname] = column; + if(df.fieldname) { + this.fields_list.push(column); + } + + column.refresh = function() { + frappe.ui.section_refresh.apply(this); + } + + this.column = column; + }, refresh_sections: function() { var cnt = 0; this.wrapper.find(".form-section:not(.hide-control)").each(function() { @@ -378,4 +396,19 @@ frappe.ui.form.Layout = Class.extend({ this.refresh_section_count(); } -}) +}); + +frappe.ui.section_refresh = function() { + if(!this.df) + return; + + // hide if explictly hidden + var hide = this.df.hidden || this.df.hidden_due_to_dependency; + + // hide if no perm + if(!hide && this.layout && this.layout.frm && !this.layout.frm.get_perm(this.df.permlevel || 0, "read")) { + hide = true; + } + + $(this).toggleClass("hide-control", !!hide); +} diff --git a/frappe/public/js/frappe/form/print.js b/frappe/public/js/frappe/form/print.js index 61f86deb60..f5ac5d8e46 100644 --- a/frappe/public/js/frappe/form/print.js +++ b/frappe/public/js/frappe/form/print.js @@ -30,6 +30,7 @@ frappe.ui.form.PrintPreview = Class.extend({ .on("change", function() { if(me.is_old_style()) { me.wrapper.find(".btn-download-pdf").toggle(false); + me.set_style(); me.preview_old_style(); } else { me.wrapper.find(".btn-download-pdf").toggle(true); @@ -91,8 +92,9 @@ frappe.ui.form.PrintPreview = Class.extend({ }, preview: function() { var me = this; - this.get_print_html(function(html) { - me.wrapper.find(".print-format").html(html); + this.get_print_html(function(out) { + me.wrapper.find(".print-format").html(out.html); + me.set_style(out.style); }); }, printit: function() { @@ -100,21 +102,19 @@ frappe.ui.form.PrintPreview = Class.extend({ }, new_page_preview: function(printit) { var me = this; - this.get_print_html(function(html) { - var w = window.open("/print?" - +"doctype="+encodeURIComponent(me.frm.doc.doctype) - +"&name="+encodeURIComponent(me.frm.doc.name) - +(printit ? "&trigger_print=1" : "") - +"&format="+me.selected_format() - +"&no_letterhead="+(me.with_letterhead() ? "0" : "1")); - if(!w) { - msgprint(__("Please enable pop-ups")); return; - } - }); + var w = window.open("/print?" + +"doctype="+encodeURIComponent(me.frm.doc.doctype) + +"&name="+encodeURIComponent(me.frm.doc.name) + +(printit ? "&trigger_print=1" : "") + +"&format="+me.selected_format() + +"&no_letterhead="+(me.with_letterhead() ? "0" : "1")); + if(!w) { + msgprint(__("Please enable pop-ups")); return; + } }, get_print_html: function(callback) { frappe.call({ - method: "frappe.templates.pages.print.get_html", + method: "frappe.templates.pages.print.get_html_and_style", args: { doc: this.frm.doc, print_format: this.selected_format(), @@ -181,5 +181,8 @@ frappe.ui.form.PrintPreview = Class.extend({ }, with_letterhead: function() { return this.print_letterhead.is(":checked") ? 1 : 0; + }, + set_style: function(style) { + frappe.dom.set_style(style || frappe.boot.print_css, "print-style"); } }) diff --git a/frappe/public/js/frappe/form/script_manager.js b/frappe/public/js/frappe/form/script_manager.js index e2f4f3b77b..e70adf3112 100644 --- a/frappe/public/js/frappe/form/script_manager.js +++ b/frappe/public/js/frappe/form/script_manager.js @@ -15,7 +15,8 @@ frappe.ui.form.on = frappe.ui.form.on_change = function(doctype, fieldname, hand // add last handler to events so it can be called as // frm.events.handler(frm) - cur_frm.events[fieldname] = handler; + if(cur_frm && cur_frm.doctype===doctype) + cur_frm.events[fieldname] = handler; } if (!handler && $.isPlainObject(fieldname)) { diff --git a/frappe/public/js/frappe/form/set_sharing.html b/frappe/public/js/frappe/form/set_sharing.html index 6088b7a15b..969e0c1461 100644 --- a/frappe/public/js/frappe/form/set_sharing.html +++ b/frappe/public/js/frappe/form/set_sharing.html @@ -1,29 +1,35 @@
- {% if(!shared.length) { %} -

{%= __("Not shared with anyone yet.") %}

- {% } else { %} -
-
{%= __("User") %}
-
{%= __("Can Read") %}
-
{%= __("Can Write") %}
-
{%= __("Can Share") %}
-
+
+
{%= __("User") %}
+
{%= __("Can Read") %}
+
{%= __("Can Write") %}
+
{%= __("Can Share") %}
+
- {% for (var i=0, l=shared.length; i < l; i++) { - var s = shared[i]; %} - {% if(s) { %} -
-
{%= s.user %}
-
-
-
-
- {% } %} - {% } %} +
+ +
+
+
+
+ + {% for (var i=0, l=shared.length; i < l; i++) { + var s = shared[i]; %} + {% if(s && !s.everyone) { %} +
+
{%= s.user %}
+
+
+
+
+ {% } %} {% } %} {% if(frappe.model.can_share(null, frm)) { %} diff --git a/frappe/public/js/frappe/form/share.js b/frappe/public/js/frappe/form/share.js index b15c8086c2..202a884ae5 100644 --- a/frappe/public/js/frappe/form/share.js +++ b/frappe/public/js/frappe/form/share.js @@ -10,26 +10,42 @@ frappe.ui.form.Share = Class.extend({ refresh: function() { var me = this; this.parent.empty(); + + var everyone = null; var shared = $.map(this.shared || this.frm.get_docinfo().shared, function(s) { + if (s.everyone) { + everyone = s; + } + return s ? s.user : null; }); + if (everyone) { + $(repl('', {title: __("Shared with everyone")})) + .appendTo(this.parent) + .on("click", function() { me.frm.share_doc(); }); + } + for(var i=0; i\ %(fullname)s', {image: user_info.image, fullname: user_info.fullname})) .appendTo(this.parent) - .on("click", function() { me.frm.share_doc(); });; + .on("click", function() { me.frm.share_doc(); }); } + // share if(!me.frm.doc.__islocal) { $(repl('', {title: __("Share")})) .appendTo(this.parent) .on("click", function() { me.frm.share_doc(); }); + } + }, show: function() { var me = this; @@ -65,7 +81,16 @@ frappe.ui.form.Share = Class.extend({ this.shared = shared; var d = this.dialog; $(d.body).empty(); - $(frappe.render_template("set_sharing", {frm: this.frm, shared: this.shared})) + + var everyone = {}; + $.each(this.shared, function(i, s) { + // pullout everyone record from shared list + if (s && s.everyone) { + everyone = s; + } + }); + + $(frappe.render_template("set_sharing", {frm: this.frm, shared: this.shared, everyone: everyone})) .appendTo(d.body); if(frappe.model.can_share(null, this.frm)) { @@ -113,6 +138,7 @@ frappe.ui.form.Share = Class.extend({ write: $(d.body).find(".add-share-write").prop("checked") ? 1 : 0, share: $(d.body).find(".add-share-share").prop("checked") ? 1 : 0 }, + btn: this, callback: function(r) { $.each(me.shared, function(i, s) { if(s && s.user===r.message.user) { @@ -131,9 +157,10 @@ frappe.ui.form.Share = Class.extend({ set_edit_share_events: function() { var me = this, d = this.dialog; $(d.body).find(".edit-share").on("click", function() { - var user = $(this).parents(".shared-user:first").attr("data-user"), + var user = $(this).parents(".shared-user:first").attr("data-user") || "", value = $(this).prop("checked") ? 1 : 0, - property = $(this).attr("name"); + property = $(this).attr("name") + everyone = cint($(this).parents(".shared-user:first").attr("data-everyone")); frappe.call({ method: "frappe.share.set_permission", @@ -142,20 +169,28 @@ frappe.ui.form.Share = Class.extend({ name: me.frm.doc.name, user: user, permission_to: property, - value: value + value: value, + everyone: everyone }, callback: function(r) { + var found = null; $.each(me.shared, function(i, s) { // update shared object - if(s && s.user===user) { + if(s && (s.user===user || (everyone && s.everyone===1))) { if(!r.message) { delete me.shared[i]; } else { me.shared[i] = $.extend(s, r.message); } + found = true; return false; } }); + + if (!found) { + me.shared.push(r.message); + } + me.dirty = true; me.render_shared(); me.frm.shared.refresh(); diff --git a/frappe/public/js/frappe/form/workflow.js b/frappe/public/js/frappe/form/workflow.js index 1c258eca4c..13947aebb9 100644 --- a/frappe/public/js/frappe/form/workflow.js +++ b/frappe/public/js/frappe/form/workflow.js @@ -67,6 +67,11 @@ frappe.ui.form.States = Class.extend({ this.frm.page.clear_actions_menu(); + // if the loaded doc is dirty, don't show workflow buttons + if (this.frm.doc.__unsaved===1) { + return; + } + $.each(frappe.workflow.get_transitions(this.frm.doctype, state), function(i, d) { if(in_list(user_roles, d.allowed)) { added = true; @@ -89,7 +94,6 @@ frappe.ui.form.States = Class.extend({ // revert state on error var on_error = function() { - console.log("here", doc_before_action); // reset in locals frappe.model.add_to_locals(doc_before_action); me.frm.refresh(); diff --git a/frappe/public/js/frappe/list/list_sidebar.html b/frappe/public/js/frappe/list/list_sidebar.html index e63fad4dc9..57ef1cff6b 100644 --- a/frappe/public/js/frappe/list/list_sidebar.html +++ b/frappe/public/js/frappe/list/list_sidebar.html @@ -7,6 +7,9 @@
  • {%= __("Assigned To Me") %}
  • + {% if(frappe.help.has_help(doctype)) { %} +
  • {{ __("Help") }}
  • + {% } %} diff --git a/frappe/public/js/frappe/list/listview.js b/frappe/public/js/frappe/list/listview.js index 258b4d1092..e6b230a9ba 100644 --- a/frappe/public/js/frappe/list/listview.js +++ b/frappe/public/js/frappe/list/listview.js @@ -102,11 +102,15 @@ frappe.views.ListView = Class.extend({ set_columns: function() { var me = this; this.columns = []; - this.columns.push({ + var name_column = { colspan: this.settings.colwidths && this.settings.colwidths.subject || 6, type: "Subject", - title: "Title" - }); + title: "Name" + }; + if (this.meta.title_field) { + name_column.title = frappe.meta.get_docfield(this.doctype, this.meta.title_field).label; + } + this.columns.push(name_column); this.total_colspans = this.columns[0].colspan; if(frappe.model.is_submittable(this.doctype) diff --git a/frappe/public/js/frappe/misc/datetime.js b/frappe/public/js/frappe/misc/datetime.js index 90abe360ce..44b5dbbbe6 100644 --- a/frappe/public/js/frappe/misc/datetime.js +++ b/frappe/public/js/frappe/misc/datetime.js @@ -8,13 +8,38 @@ moment.defaultDatetimeFormat = "YYYY-MM-DD HH:mm:ss" frappe.provide("frappe.datetime"); $.extend(frappe.datetime, { + convert_to_user_tz: function(date) { + if(sys_defaults.time_zone) { + return moment.tz(date, sys_defaults.time_zone).utc() + .utcOffset(moment.user_utc_offset).format(moment.defaultDatetimeFormat); + } else { + return moment(date).format(moment.defaultDatetimeFormat); + } + }, + + convert_to_system_tz: function(date) { + if(sys_defaults.time_zone) { + return moment(date).utc() + .utcOffset(moment.system_utc_offset).format(moment.defaultDatetimeFormat); + } else { + return moment(date).format(moment.defaultDatetimeFormat); + } + }, + + is_timezone_same: function() { + if(sys_defaults.time_zone) { + return moment().tz(sys_defaults.time_zone).utcOffset() === moment().utcOffset(); + } else { + return true; + } + }, + str_to_obj: function(d) { - // zone hack to remove timezone diff added by momentjs - return moment(d, moment.defaultDatetimeFormat).zone(moment().zone())._d; + return moment(d, moment.defaultDatetimeFormat)._d; }, obj_to_str: function(d) { - return moment(d).format(); + return moment(d).locale("en").format(); }, obj_to_user: function(d) { @@ -81,7 +106,8 @@ $.extend(frappe.datetime, { } // user_fmt.replace("YYYY", "YY")? user might only input 2 digits of the year, which should also be parsed - return moment(val, [user_fmt.replace("YYYY", "YY"), user_fmt]).format(system_fmt); + return moment(val, [user_fmt.replace("YYYY", "YY"), + user_fmt]).locale("en").format(system_fmt); }, user_to_obj: function(d) { @@ -98,7 +124,7 @@ $.extend(frappe.datetime, { }, get_today: function() { - return moment().format(); + return moment().locale("en").format(); }, nowdate: function() { @@ -106,7 +132,7 @@ $.extend(frappe.datetime, { }, now_time: function() { - return moment().format("HH:mm:ss"); + return moment().locale("en").format("HH:mm:ss"); }, validate: function(d) { diff --git a/frappe/public/js/frappe/misc/help.js b/frappe/public/js/frappe/misc/help.js new file mode 100644 index 0000000000..5179f2d1d3 --- /dev/null +++ b/frappe/public/js/frappe/misc/help.js @@ -0,0 +1,39 @@ +// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors +// MIT License. See license.txt + +frappe.provide("frappe.help"); + +frappe.help.youtube_id = {}; + +frappe.help.has_help = function(doctype) { + return frappe.help.youtube_id[doctype]; +} + +frappe.help.show_link = function() { + +} + +frappe.help.show = function(doctype) { + if(frappe.help.youtube_id[doctype]) { + frappe.help.show_video(frappe.help.youtube_id[doctype]); + } +} + +frappe.help.show_video = function(youtube_id, title) { + if($("body").width() > 768) { + var size = [670, 377]; + } else { + var size = [560, 315]; + } + var dialog = frappe.msgprint('' + (frappe.help_feedback_link || ""), + title || __("Help")); + + dialog.$wrapper.find(".modal-content").addClass("video-modal"); +} + +$("body").on("click", "a.help-link", function() { + var doctype = $(this).attr("data-doctype"); + doctype && frappe.help.show(doctype); +}); diff --git a/frappe/public/js/frappe/misc/pretty_date.js b/frappe/public/js/frappe/misc/pretty_date.js index 143fd3e433..d766c5a784 100644 --- a/frappe/public/js/frappe/misc/pretty_date.js +++ b/frappe/public/js/frappe/misc/pretty_date.js @@ -1,14 +1,8 @@ function prettyDate(time, mini){ if(moment) { - if(frappe.boot) { - var user_timezone = frappe.boot.user.time_zone; - var system_timezone = sys_defaults.time_zone; - var zones = (frappe.boot.timezone_info || {}).zones || {}; - } - if (frappe.boot && user_timezone && (user_timezone != system_timezone) - && zones[user_timezone] && zones[system_timezone]) { - var ret = moment.tz(time, sys_defaults.time_zone).tz(frappe.boot.user.time_zone).fromNow(mini); + if(window.sys_defaults && sys_defaults.time_zone) { + var ret = moment.tz(time, sys_defaults.time_zone).fromNow(mini); } else { var ret = moment(time).fromNow(mini); } @@ -17,10 +11,12 @@ function prettyDate(time, mini){ ret = "now"; } else { var parts = ret.split(" "); - if(parts[0]==="a" || parts[0]==="an") { - parts[0] = 1; + if(parts.length > 1) { + if(parts[0]==="a" || parts[0]==="an") { + parts[0] = 1; + } + ret = parts[0] + " " + parts[1].substr(0, 1); } - ret = parts[0] + " " + parts[1].substr(0, 1); } } return ret; diff --git a/frappe/public/js/frappe/misc/user.js b/frappe/public/js/frappe/misc/user.js index 641b8296e5..f9d9d66f7f 100644 --- a/frappe/public/js/frappe/misc/user.js +++ b/frappe/public/js/frappe/misc/user.js @@ -132,7 +132,7 @@ $.extend(frappe.user, { var ret = null; switch(type) { case "module": - if(frappe.boot.user.allow_modules.indexOf(m)!=-1) + if(frappe.boot.user.allow_modules.indexOf(m)!=-1 || frappe.modules[m].is_help) ret = m; break; case "page": diff --git a/frappe/public/js/frappe/model/perm.js b/frappe/public/js/frappe/model/perm.js index 06084b7144..028d4c586f 100644 --- a/frappe/public/js/frappe/model/perm.js +++ b/frappe/public/js/frappe/model/perm.js @@ -65,10 +65,16 @@ $.extend(frappe.perm, { for(var i=0; i"); + errors.push(__(f.df.label)); if(v) ret[f.df.fieldname] = v; } } if(errors.length) { - msgprint($.format('\ - {0}:\ -

    \ - {1}', [__('Missing Values Required'), errors.join('\n')])); + msgprint('' + __('Missing Values Required') + "
    " + + errors.join('
    ')); return null; } return ret; diff --git a/frappe/public/js/frappe/ui/filters/filters.js b/frappe/public/js/frappe/ui/filters/filters.js index d3a6d4cdf4..31f49c1032 100644 --- a/frappe/public/js/frappe/ui/filters/filters.js +++ b/frappe/public/js/frappe/ui/filters/filters.js @@ -272,7 +272,8 @@ frappe.ui.Filter = Class.extend({ } else if(df.fieldtype=='Check') { df.fieldtype='Select'; df.options='No\nYes'; - } else if(['Text','Small Text','Text Editor','Code','Tag','Comments','Dynamic Link', 'Read Only'].indexOf(df.fieldtype)!=-1) { + } else if(['Text','Small Text','Text Editor','Code','Tag','Comments', + 'Dynamic Link','Read Only','Assign'].indexOf(df.fieldtype)!=-1) { df.fieldtype = 'Data'; } else if(df.fieldtype=='Link' && this.$w.find('.condition').val()!="=") { df.fieldtype = 'Data'; @@ -306,13 +307,20 @@ frappe.ui.Filter = Class.extend({ } if(this.get_condition()==='like') { - // add % only if not there at the end - if ((val.length === 0) || (val.lastIndexOf("%") !== (val.length - 1))) { - val = (val || "") + '%'; + // automatically append wildcards + if(val) { + if(val.slice(0,1) !== "%") { + val = "%" + val; + } + if(val.slice(-1) !== "%") { + val = val + "%"; + } } } else if(in_list(["in", "not in"], this.get_condition())) { val = $.map(val.split(","), function(v) { return strip(v); }); - } if(val === '%') val = ""; + } if(val === '%') { + val = ""; + } return val; }, @@ -382,26 +390,28 @@ frappe.ui.Filter = Class.extend({ frappe.ui.FieldSelect = Class.extend({ // opts parent, doctype, filter_fields, with_blank, select init: function(opts) { + var me = this; $.extend(this, opts); this.fields_by_name = {}; this.options = []; - this.$select = $('').appendTo(this.parent); - var me = this; - this.$select.autocomplete({ - source: me.options, - minLength: 0, - focus: function(event, ui) { - ui.item && me.$select.val(ui.item.label); - return false; - }, - select: function(event, ui) { - me.selected_doctype = ui.item.doctype; - me.selected_fieldname = ui.item.fieldname; - me.$select.val(ui.item.label); - if(me.select) me.select(ui.item.doctype, ui.item.fieldname); - return false; - } - }); + this.$select = $('') + .appendTo(this.parent) + .on("click", function () { $(this).select(); }) + .autocomplete({ + source: me.options, + minLength: 0, + autoFocus: true, + focus: function(event, ui) { + event.preventDefault(); + }, + select: function(event, ui) { + me.selected_doctype = ui.item.doctype; + me.selected_fieldname = ui.item.fieldname; + me.$select.val(ui.item.label); + if(me.select) me.select(ui.item.doctype, ui.item.fieldname); + return false; + } + }); this.$select.data('ui-autocomplete')._renderItem = function(ul, item) { return $(repl('
  • %(label)s

  • ', item)) diff --git a/frappe/public/js/frappe/ui/messages.js b/frappe/public/js/frappe/ui/messages.js index 38a1100384..bb6a114a48 100644 --- a/frappe/public/js/frappe/ui/messages.js +++ b/frappe/public/js/frappe/ui/messages.js @@ -48,7 +48,7 @@ frappe.prompt = function(fields, callback, title, primary_label) { var d = new frappe.ui.Dialog({ fields: fields, title: title || __("Enter Value"), - }) + }); d.set_primary_action(primary_label || __("Submit"), function() { var values = d.get_values(); if(!values) { @@ -56,7 +56,7 @@ frappe.prompt = function(fields, callback, title, primary_label) { } d.hide(); callback(values); - }) + }); d.show(); return d; } @@ -113,6 +113,27 @@ frappe.msgprint = function(msg, title) { return msg_dialog; } +frappe.verify_password = function(callback) { + frappe.prompt({ + fieldname: "password", + label: __("Enter your password"), + fieldtype: "Password", + reqd: 1 + }, function(data) { + frappe.call({ + method: "frappe.core.doctype.user.user.verify_password", + args: { + password: data.password + }, + callback: function(r) { + if(!r.exc) { + callback(); + } + } + }); + }, __("Verify Password"), __("Verify")) +} + var msgprint = frappe.msgprint; // Floating Message diff --git a/frappe/public/js/frappe/ui/page.html b/frappe/public/js/frappe/ui/page.html index f5f549fcf1..188d79290c 100644 --- a/frappe/public/js/frappe/ui/page.html +++ b/frappe/public/js/frappe/ui/page.html @@ -2,37 +2,39 @@
    - -

    -
    - -

    + +

    +
    + +

    - -
    - + +
    + - - - -
    - - -
    - + + + +
    + + +
    +
    diff --git a/frappe/public/js/frappe/ui/page.js b/frappe/public/js/frappe/ui/page.js index 1df246f0ff..6e23e7ca6c 100644 --- a/frappe/public/js/frappe/ui/page.js +++ b/frappe/public/js/frappe/ui/page.js @@ -85,7 +85,9 @@ frappe.ui.Page = Class.extend({ this.actions_btn_group = this.page_actions.find(".actions-btn-group"); this.page_form = $('
    ').prependTo(this.main); + this.inner_toolbar = $('
    ').prependTo(this.main); this.icon_group = this.page_actions.find(".page-icon-group"); + }, set_indicator: function(label, color) { @@ -225,6 +227,11 @@ frappe.ui.Page = Class.extend({ return $('
  • ').appendTo(this.menu); }, + add_inner_button: function(label, action) { + return $('
    ", frappe.app)); frappe.ui.misc.about_dialog = d; diff --git a/frappe/public/js/frappe/ui/toolbar/awesome_bar.js b/frappe/public/js/frappe/ui/toolbar/awesome_bar.js index 3040217455..ff4955f084 100644 --- a/frappe/public/js/frappe/ui/toolbar/awesome_bar.js +++ b/frappe/public/js/frappe/ui/toolbar/awesome_bar.js @@ -27,10 +27,10 @@ frappe.search = { response(frappe.search.options); }, - open: function() { - frappe.search.autocomplete_open = true; + open: function(event, ui) { + frappe.search.autocomplete_open = event.target; }, - close: function() { + close: function(event, ui) { frappe.search.autocomplete_open = false; }, select: function(event, ui) { @@ -48,16 +48,6 @@ frappe.search = { } }; - var render_item = function(ul, d) { - var html = "" + __(d.label || d.value) + ""; - if(d.description && d.value!==d.description) { - html += '
    ' + __(d.description) + ''; - } - return $('
  • ') - .data('item.autocomplete', d) - .html('

    ' + html + '

    ') - .appendTo(ul); - }; var open_recent = function() { if (!frappe.search.autocomplete_open) { @@ -67,15 +57,27 @@ frappe.search = { $("#navbar-search") .on("focus", open_recent) - .autocomplete(opts).data('ui-autocomplete')._renderItem = render_item; + .autocomplete(opts).data('ui-autocomplete')._renderItem = + frappe.search.render_item; $("#sidebar-search") .on("focus", open_recent) - .autocomplete(opts).data('ui-autocomplete')._renderItem = render_item; + .autocomplete(opts).data('ui-autocomplete')._renderItem = + frappe.search.render_item; frappe.search.make_page_title_map(); frappe.search.setup_recent(); }, + render_item: function(ul, d) { + var html = "" + __(d.label || d.value) + ""; + if(d.description && d.value!==d.description) { + html += '
    ' + __(d.description) + ''; + } + return $('
  • ') + .data('item.autocomplete', d) + .html('

    ' + html + '

    ') + .appendTo(ul); + }, add_help: function() { frappe.search.options.push({ label: __("Help on Search"), @@ -208,12 +210,24 @@ frappe.search.verbs = [ }); }, + // reports + function(txt) { + frappe.search.find(keys(frappe.boot.user.all_reports), txt, function(match) { + var report_type = frappe.boot.user.all_reports[match]; + return { + label: __("Open {0}", [""+__(match)+""]), + value: __("Open {0}", [__(match)]), + route: [report_type=="Report Builder" ? "Report" : "query-report", match] + } + }); + }, + // pages function(txt) { frappe.search.find(keys(frappe.search.pages), txt, function(match) { return { - label: __("Open {0}", [""+__(match)+""]), - value: __("Open {0}", [__(match)]), + label: __("Report {0}", [""+__(match)+""]), + value: __("Report {0}", [__(match)]), route: [frappe.search.pages[match].route || frappe.search.pages[match].name] } }); @@ -274,5 +288,5 @@ frappe.search.verbs = [ } }; - }, + } ]; diff --git a/frappe/public/js/frappe/upload.js b/frappe/public/js/frappe/upload.js index 6cf7b9616a..1031937326 100644 --- a/frappe/public/js/frappe/upload.js +++ b/frappe/public/js/frappe/upload.js @@ -92,7 +92,8 @@ frappe.upload = { var attachment = r.message; opts.callback(attachment, r); $(document).trigger("upload_complete", attachment); - } + }, + btn: opts.btn }); } } @@ -137,6 +138,7 @@ frappe.upload = { var a = parts[1]; } - return atob(a); + return decodeURIComponent(escape(atob(a))); + } } diff --git a/frappe/public/js/frappe/views/calendar.js b/frappe/public/js/frappe/views/calendar.js index 497f17c003..7d19b15fc2 100644 --- a/frappe/public/js/frappe/views/calendar.js +++ b/frappe/public/js/frappe/views/calendar.js @@ -8,8 +8,8 @@ frappe.views.CalendarFactory = frappe.views.Factory.extend({ make: function(route) { var me = this; - frappe.require('assets/frappe/js/lib/fullcalendar/fullcalendar.css'); - frappe.require('assets/frappe/js/lib/fullcalendar/fullcalendar.js'); + frappe.require('assets/frappe/js/lib/fullcalendar/fullcalendar.min.css'); + frappe.require('assets/frappe/js/lib/fullcalendar/fullcalendar.min.js'); frappe.model.with_doctype(route[1], function() { var options = { @@ -53,7 +53,10 @@ frappe.views.Calendar = frappe.views.CalendarBase.extend({ "default": frappe.datetime.month_start(), input_css: {"z-index": 1}, change: function() { - me.$cal.fullCalendar("gotoDate", $(this).val()); + var selected = $(this).val(); + if (selected) { + me.$cal.fullCalendar("gotoDate", frappe.datetime.user_to_obj(selected)); + } } }); @@ -62,7 +65,17 @@ frappe.views.Calendar = frappe.views.CalendarBase.extend({ frappe.set_route("Form", me.doctype, doc.name); }); - var me = this; + // add links to other calendars + $.each(frappe.boot.calendars, function(i, doctype) { + if(frappe.model.can_read(doctype)) { + me.page.add_menu_item(__(doctype), function() { + frappe.set_route("Calendar", doctype); + }); + } + }); + + this.page.page_actions.find(".menu-btn-group-label").text(__("Type")); + $(this.parent).on("show", function() { me.$cal.fullCalendar("refetchEvents"); }) @@ -124,6 +137,10 @@ frappe.views.Calendar = frappe.views.CalendarBase.extend({ "color": "#D9F6FF" } }, + get_system_datetime: function(date) { + date._offset = moment.user_utc_offset; + return frappe.datetime.convert_to_system_tz(date); + }, setup_options: function() { var me = this; this.cal_options = { @@ -135,6 +152,7 @@ frappe.views.Calendar = frappe.views.CalendarBase.extend({ editable: true, selectable: true, selectHelper: true, + forceEventDuration: true, events: function(start, end, timezone, callback) { return frappe.call({ method: me.get_events_method || "frappe.desk.calendar.get_events", @@ -154,10 +172,10 @@ frappe.views.Calendar = frappe.views.CalendarBase.extend({ frappe.set_route("Form", doctype, event.name); } }, - eventDrop: function(event, dayDelta, minuteDelta, allDay, revertFunc) { + eventDrop: function(event, delta, revertFunc, jsEvent, ui, view) { me.update_event(event, revertFunc); }, - eventResize: function(event, dayDelta, minuteDelta, allDay, revertFunc) { + eventResize: function(event, delta, revertFunc, jsEvent, ui, view) { me.update_event(event, revertFunc); }, select: function(startDate, endDate, jsEvent, view) { @@ -169,10 +187,10 @@ frappe.views.Calendar = frappe.views.CalendarBase.extend({ var event = frappe.model.get_new_doc(me.doctype); - event[me.field_map.start] = frappe.datetime.get_datetime_as_string(startDate); + event[me.field_map.start] = me.get_system_datetime(startDate); if(me.field_map.end) - event[me.field_map.end] = frappe.datetime.get_datetime_as_string(endDate); + event[me.field_map.end] = me.get_system_datetime(endDate); if(me.field_map.allDay) { var all_day = (startDate._ambigTime && endDate._ambigTime) ? 1 : 0; @@ -180,10 +198,9 @@ frappe.views.Calendar = frappe.views.CalendarBase.extend({ event[me.field_map.allDay] = all_day; if (all_day) - event[me.field_map.end] = frappe.datetime.get_datetime_as_string(endDate.subtract(1, "s")); + event[me.field_map.end] = me.get_system_datetime(moment(endDate).subtract(1, "s")); } - frappe.set_route("Form", me.doctype, event.name); }, dayClick: function(date, allDay, jsEvent, view) { @@ -199,8 +216,8 @@ frappe.views.Calendar = frappe.views.CalendarBase.extend({ get_args: function(start, end) { var args = { doctype: this.doctype, - start: frappe.datetime.get_datetime_as_string(start), - end: frappe.datetime.get_datetime_as_string(end), + start: this.get_system_datetime(start), + end: this.get_system_datetime(end), filters: this.get_filters() }; return args; @@ -226,6 +243,12 @@ frappe.views.Calendar = frappe.views.CalendarBase.extend({ if(!me.field_map.allDay) d.allDay = 1; + // convert to user tz + d.start = frappe.datetime.convert_to_user_tz(d.start); + d.end = frappe.datetime.convert_to_user_tz(d.end); + + me.fix_end_date_for_event_render(d); + if(d.status) { if(me.style_map) { $.extend(d, me.styles[me.style_map[d.status]] || {}); @@ -246,31 +269,46 @@ frappe.views.Calendar = frappe.views.CalendarBase.extend({ args: me.get_update_args(event), callback: function(r) { if(r.exc) { - show_alert("Unable to update event.") + show_alert(__("Unable to update event")); revertFunc(); } + }, + error: function() { + revertFunc(); } }); }, get_update_args: function(event) { + var me = this; var args = { name: event[this.field_map.id] }; - args[this.field_map.start] = frappe.datetime.get_datetime_as_string(event.start); + + args[this.field_map.start] = me.get_system_datetime(event.start); if(this.field_map.allDay) - args[this.field_map.allDay] = event.allDay ? 1 : 0; + args[this.field_map.allDay] = (event.start._ambigTime && event.end._ambigTime) ? 1 : 0; if(this.field_map.end) { + if (!event.end) { + event.end = event.start.add(1, "hour"); + } + if (args[this.field_map.allDay]) { - args[this.field_map.end] = frappe.datetime.get_datetime_as_string(event.start); - } else if (event.end) { - args[this.field_map.end] = frappe.datetime.get_datetime_as_string(event.end); + args[this.field_map.end] = me.get_system_datetime(moment(event.end).subtract(1, "s")); } } args.doctype = event.doctype || this.doctype; return { args: args, field_map: this.field_map }; + }, + + fix_end_date_for_event_render: function(event) { + if (event.allDay) { + // We use inclusive end dates. This workaround fixes the rendering of events + event.start = event.start ? $.fullCalendar.moment(event.start).stripTime() : null; + event.end = event.end ? $.fullCalendar.moment(event.end).add(1, "day").stripTime() : null; + } } }) diff --git a/frappe/public/js/frappe/views/communication.js b/frappe/public/js/frappe/views/communication.js index 52065badc7..70227ff056 100644 --- a/frappe/public/js/frappe/views/communication.js +++ b/frappe/public/js/frappe/views/communication.js @@ -33,6 +33,8 @@ frappe.views.CommunicationComposer = Class.extend({ {fieldtype: "Column Break"}, {label:__("Send As Email"), fieldtype:"Check", fieldname:"send_email"}, + {label:__("Send me a copy"), fieldtype:"Check", + fieldname:"send_me_a_copy"}, {label:__("Communication Medium"), fieldtype:"Select", options: ["Phone", "Chat", "Email", "SMS", "Visit", "Other"], fieldname:"communication_medium"}, @@ -116,6 +118,10 @@ frappe.views.CommunicationComposer = Class.extend({ this.subject = "Re: " + this.subject; } } + + if (!this.subject) { + this.subject = __(this.frm.doctype) + ': ' + this.frm.docname; + } } }, @@ -316,6 +322,7 @@ frappe.views.CommunicationComposer = Class.extend({ name: me.doc.name, send_email: form_values.send_email, print_html: print_html, + send_me_a_copy: form_values.send_me_a_copy, print_format: print_format, communication_medium: form_values.communication_medium, sent_or_received: form_values.sent_or_received, @@ -324,8 +331,8 @@ frappe.views.CommunicationComposer = Class.extend({ btn: btn, callback: function(r) { if(!r.exc) { - if(form_values.send_email) - msgprint(__("Email sent to {0}", [form_values.recipients])); + if(form_values.send_email && r.message["recipients"]) + msgprint(__("Email sent to {0}", [r.message["recipients"]])); me.dialog.hide(); if (cur_frm) { @@ -395,6 +402,7 @@ frappe.views.CommunicationComposer = Class.extend({ $(this.dialog.fields_dict.recipients.input) .bind( "keydown", function(event) { if (event.keyCode === $.ui.keyCode.TAB && + $(this).data( "autocomplete" ) && $(this).data( "autocomplete" ).menu.active ) { event.preventDefault(); } @@ -418,8 +426,7 @@ frappe.views.CommunicationComposer = Class.extend({ }, appendTo: this.dialog.$wrapper, focus: function() { - // prevent value inserted on focus - return false; + event.preventDefault(); }, select: function( event, ui ) { var terms = split( this.value ); @@ -435,4 +442,3 @@ frappe.views.CommunicationComposer = Class.extend({ }); } }); - diff --git a/frappe/public/js/frappe/views/container.js b/frappe/public/js/frappe/views/container.js index 38bfa4e54e..cb82837718 100644 --- a/frappe/public/js/frappe/views/container.js +++ b/frappe/public/js/frappe/views/container.js @@ -5,6 +5,7 @@ frappe.provide('frappe.pages'); frappe.provide('frappe.views'); +var cur_page = null; frappe.views.Container = Class.extend({ _intro: "Container contains pages inside `#container` and manages \ page creation, switching", @@ -37,6 +38,7 @@ frappe.views.Container = Class.extend({ return page; }, change_to: function(label) { + cur_page = this; if(this.page && this.page.label === label) { $(this.page).trigger('show'); return; diff --git a/frappe/public/js/frappe/views/ganttview.js b/frappe/public/js/frappe/views/ganttview.js index 05354a61a0..2d671f3da8 100644 --- a/frappe/public/js/frappe/views/ganttview.js +++ b/frappe/public/js/frappe/views/ganttview.js @@ -53,7 +53,7 @@ frappe.views.Gantt = frappe.views.CalendarBase.extend({ fieldname:"end", "default": frappe.datetime.month_end(), input_css: {"z-index": 3}}); this.add_filters(); - this.wrapper = $("
    ").appendTo(this.page.main); + this.wrapper = $("
    ").appendTo(this.page.main); }, refresh: function() { diff --git a/frappe/public/js/frappe/views/module/moduleview.js b/frappe/public/js/frappe/views/module/moduleview.js index fc7bb40d7c..deeb1f9fbb 100644 --- a/frappe/public/js/frappe/views/module/moduleview.js +++ b/frappe/public/js/frappe/views/module/moduleview.js @@ -85,14 +85,23 @@ frappe.views.moduleview.ModuleView = Class.extend({ .appendTo(this.page.main); $(this.sections[name]).find(".module-item").each(function(i, mi) { - $(mi).on("click", function(event) { - // if clicked on open notification! - if (event.target.classList.contains("open-notification")) { - var doctype = event.target.getAttribute("data-doctype"); - frappe.route_options = frappe.boot.notification_info.conditions[doctype]; - } - frappe.set_route(me.get_route(data.items[$(mi).attr("data-item-index")])); - }); + var item = data.items[$(mi).attr("data-item-index")]; + $(mi) + .attr("data-route", me.get_route(item).join("/")) + .attr("data-label", item.name) + .on("click", function(event) { + // if clicked on open notification! + if (event.target.classList.contains("open-notification")) { + var doctype = event.target.getAttribute("data-doctype"); + frappe.route_options = frappe.boot.notification_info.conditions[doctype]; + } + if(item.type==="help") { + frappe.help.show_video(item.youtube_id); + return false; + } else { + frappe.set_route(me.get_route(item)); + } + }); }); } diff --git a/frappe/public/js/frappe/views/reports/reportview.js b/frappe/public/js/frappe/views/reports/reportview.js index cd2c365d60..72cb27132b 100644 --- a/frappe/public/js/frappe/views/reports/reportview.js +++ b/frappe/public/js/frappe/views/reports/reportview.js @@ -187,17 +187,21 @@ frappe.views.ReportView = frappe.ui.Listing.extend({ }, get_order_by: function() { + var order_by = []; + // first - var order_by = this.get_selected_table_and_column(this.sort_by_select) - + ' ' + this.sort_order_select.val(); + var sort_by_select = this.get_selected_table_and_column(this.sort_by_select); + if (sort_by_select) { + order_by.push(sort_by_select + " " + this.sort_order_select.val()); + } // second if(this.sort_by_next_select.val()) { - order_by += ', ' + this.get_selected_table_and_column(this.sort_by_next_select) - + ' ' + this.sort_order_next_select.val(); + order_by.push(this.get_selected_table_and_column(this.sort_by_next_select) + + ' ' + this.sort_order_next_select.val()); } - return order_by; + return order_by.join(", "); }, get_selected_table_and_column: function(select) { diff --git a/frappe/public/js/legacy/form.js b/frappe/public/js/legacy/form.js index 48b259ca19..a7ef72e5c8 100644 --- a/frappe/public/js/legacy/form.js +++ b/frappe/public/js/legacy/form.js @@ -173,8 +173,9 @@ _f.Frm.prototype.print_doc = function() { } _f.Frm.prototype.hide_print = function() { - if(this.setup_done) { - this.page.set_view(this.page.previous_view_name != "print" && this.page.previous_view_name || "main"); + if(this.setup_done && this.page.current_view_name==="print") { + this.page.set_view(this.page.previous_view_name==="print" ? + "main" : (this.page.previous_view_name || "main")); } } @@ -212,7 +213,6 @@ _f.Frm.prototype.watch_model_updates = function() { _f.Frm.prototype.setup_std_layout = function() { this.form_wrapper = $('
    ').appendTo(this.layout_main); - this.inner_toolbar = $('
    ').appendTo(this.form_wrapper); this.body = $('
    ').appendTo(this.form_wrapper); // only tray @@ -298,7 +298,7 @@ _f.Frm.prototype.setup_meta = function(doctype) { if(this.meta.istable) { this.meta.in_dialog = 1 } } -_f.Frm.prototype.refresh_header = function() { +_f.Frm.prototype.refresh_header = function(is_a_different_doc) { // set title // main title if(!this.meta.in_dialog || this.in_form) { @@ -310,6 +310,10 @@ _f.Frm.prototype.refresh_header = function() { // show / hide buttons if(this.toolbar) { + if (is_a_different_doc) { + this.toolbar.current_status = undefined; + } + this.toolbar.refresh(); } @@ -341,8 +345,10 @@ _f.Frm.prototype.check_doc_perm = function() { } _f.Frm.prototype.refresh = function(docname) { - // record switch + var is_a_different_doc = docname ? true : false; + if(docname) { + // record switch if(this.docname != docname && (!this.meta.in_dialog || this.in_form) && !this.meta.istable) { scroll(0, 0); @@ -388,7 +394,7 @@ _f.Frm.prototype.refresh = function(docname) { cur_frm.cscript.is_onload = true; this.setnewdoc(); } else { - this.render_form(); + this.render_form(is_a_different_doc); } // if print format is shown, refresh the format @@ -398,8 +404,11 @@ _f.Frm.prototype.refresh = function(docname) { } } -_f.Frm.prototype.render_form = function() { +_f.Frm.prototype.render_form = function(is_a_different_doc) { if(!this.meta.istable) { + this.layout.doc = this.doc; + this.layout.attach_doc_and_docfields() + this.sidebar = new frappe.ui.form.Sidebar({ frm: this, page: this.page @@ -407,7 +416,7 @@ _f.Frm.prototype.render_form = function() { // header must be refreshed before client methods // because add_custom_button - this.refresh_header(); + this.refresh_header(is_a_different_doc); // call trigger this.script_manager.trigger("refresh"); @@ -435,7 +444,7 @@ _f.Frm.prototype.render_form = function() { } } else { - this.refresh_header(); + this.refresh_header(is_a_different_doc); } $(cur_frm.wrapper).trigger('render_complete'); @@ -609,8 +618,10 @@ _f.Frm.prototype._save = function(save_action, callback, btn, on_error) { // done is called after all ajaxes in validate & before_save are completed :) if(!validated) { - if(on_error) + btn && $(btn).prop("disabled", false); + if(on_error) { on_error(); + } return; } @@ -763,13 +774,11 @@ _f.Frm.prototype.set_footnote = function(txt) { _f.Frm.prototype.add_custom_button = function(label, fn, icon, toolbar_or_class) { - return $('' - ) - .click(function() { - // don't process clicks for disabled buttons - if (!button.hasClass(tm + '-state-disabled')) { - - buttonClick(); - - // after the click action, if the button becomes the "active" tab, or disabled, - // it should never have a hover class, so remove it now. - if ( - button.hasClass(tm + '-state-active') || - button.hasClass(tm + '-state-disabled') - ) { - button.removeClass(tm + '-state-hover'); - } - } - }) - .mousedown(function() { - // the *down* effect (mouse pressed in). - // only on buttons that are not the "active" tab, or disabled - button - .not('.' + tm + '-state-active') - .not('.' + tm + '-state-disabled') - .addClass(tm + '-state-down'); - }) - .mouseup(function() { - // undo the *down* effect - button.removeClass(tm + '-state-down'); - }) - .hover( - function() { - // the *hover* effect. - // only on buttons that are not the "active" tab, or disabled - button - .not('.' + tm + '-state-active') - .not('.' + tm + '-state-disabled') - .addClass(tm + '-state-hover'); - }, - function() { - // undo the *hover* effect - button - .removeClass(tm + '-state-hover') - .removeClass(tm + '-state-down'); // if mouseleave happens before mouseup - } - ); - - groupChildren = groupChildren.add(button); - } - } - }); - - if (isOnlyButtons) { - groupChildren - .first().addClass(tm + '-corner-left').end() - .last().addClass(tm + '-corner-right').end(); - } - - if (groupChildren.length > 1) { - groupEl = $('
    '); - if (isOnlyButtons) { - groupEl.addClass('fc-button-group'); - } - groupEl.append(groupChildren); - sectionEl.append(groupEl); - } - else { - sectionEl.append(groupChildren); // 1 or 0 children - } - }); - } - - return sectionEl; - } - - - function updateTitle(text) { - el.find('h2').text(text); - } - - - function activateButton(buttonName) { - el.find('.fc-' + buttonName + '-button') - .addClass(tm + '-state-active'); - } - - - function deactivateButton(buttonName) { - el.find('.fc-' + buttonName + '-button') - .removeClass(tm + '-state-active'); - } - - - function disableButton(buttonName) { - el.find('.fc-' + buttonName + '-button') - .attr('disabled', 'disabled') - .addClass(tm + '-state-disabled'); - } - - - function enableButton(buttonName) { - el.find('.fc-' + buttonName + '-button') - .removeAttr('disabled') - .removeClass(tm + '-state-disabled'); - } - - - function getViewsWithButtons() { - return viewsWithButtons; - } - -} - -;; - -fc.sourceNormalizers = []; -fc.sourceFetchers = []; - -var ajaxDefaults = { - dataType: 'json', - cache: false -}; - -var eventGUID = 1; - - -function EventManager(options) { // assumed to be a calendar - var t = this; - - - // exports - t.isFetchNeeded = isFetchNeeded; - t.fetchEvents = fetchEvents; - t.addEventSource = addEventSource; - t.removeEventSource = removeEventSource; - t.updateEvent = updateEvent; - t.renderEvent = renderEvent; - t.removeEvents = removeEvents; - t.clientEvents = clientEvents; - t.mutateEvent = mutateEvent; - - - // imports - var trigger = t.trigger; - var getView = t.getView; - var reportEvents = t.reportEvents; - var getEventEnd = t.getEventEnd; - - - // locals - var stickySource = { events: [] }; - var sources = [ stickySource ]; - var rangeStart, rangeEnd; - var currentFetchID = 0; - var pendingSourceCnt = 0; - var loadingLevel = 0; - var cache = []; // holds events that have already been expanded - - - $.each( - (options.events ? [ options.events ] : []).concat(options.eventSources || []), - function(i, sourceInput) { - var source = buildEventSource(sourceInput); - if (source) { - sources.push(source); - } - } - ); - - - - /* Fetching - -----------------------------------------------------------------------------*/ - - - function isFetchNeeded(start, end) { - return !rangeStart || // nothing has been fetched yet? - // or, a part of the new range is outside of the old range? (after normalizing) - start.clone().stripZone() < rangeStart.clone().stripZone() || - end.clone().stripZone() > rangeEnd.clone().stripZone(); - } - - - function fetchEvents(start, end) { - rangeStart = start; - rangeEnd = end; - cache = []; - var fetchID = ++currentFetchID; - var len = sources.length; - pendingSourceCnt = len; - for (var i=0; i= eventStart && end <= eventEnd; - } - - - // Does the event's date range intersect with the given range? - // start/end already assumed to have stripped zones :( - function eventIntersectsRange(event, start, end) { - var eventStart = event.start.clone().stripZone(); - var eventEnd = t.getEventEnd(event).stripZone(); - - return start < eventEnd && end > eventStart; - } - -} - - -// updates the "backup" properties, which are preserved in order to compute diffs later on. -function backupEventDates(event) { - event._allDay = event.allDay; - event._start = event.start.clone(); - event._end = event.end ? event.end.clone() : null; -} - -;; - -/* FullCalendar-specific DOM Utilities -----------------------------------------------------------------------------------------------------------------------*/ - - -// Given the scrollbar widths of some other container, create borders/margins on rowEls in order to match the left -// and right space that was offset by the scrollbars. A 1-pixel border first, then margin beyond that. -function compensateScroll(rowEls, scrollbarWidths) { - if (scrollbarWidths.left) { - rowEls.css({ - 'border-left-width': 1, - 'margin-left': scrollbarWidths.left - 1 - }); - } - if (scrollbarWidths.right) { - rowEls.css({ - 'border-right-width': 1, - 'margin-right': scrollbarWidths.right - 1 - }); - } -} - - -// Undoes compensateScroll and restores all borders/margins -function uncompensateScroll(rowEls) { - rowEls.css({ - 'margin-left': '', - 'margin-right': '', - 'border-left-width': '', - 'border-right-width': '' - }); -} - - -// Make the mouse cursor express that an event is not allowed in the current area -function disableCursor() { - $('body').addClass('fc-not-allowed'); -} - - -// Returns the mouse cursor to its original look -function enableCursor() { - $('body').removeClass('fc-not-allowed'); -} - - -// Given a total available height to fill, have `els` (essentially child rows) expand to accomodate. -// By default, all elements that are shorter than the recommended height are expanded uniformly, not considering -// any other els that are already too tall. if `shouldRedistribute` is on, it considers these tall rows and -// reduces the available height. -function distributeHeight(els, availableHeight, shouldRedistribute) { - - // *FLOORING NOTE*: we floor in certain places because zoom can give inaccurate floating-point dimensions, - // and it is better to be shorter than taller, to avoid creating unnecessary scrollbars. - - var minOffset1 = Math.floor(availableHeight / els.length); // for non-last element - var minOffset2 = Math.floor(availableHeight - minOffset1 * (els.length - 1)); // for last element *FLOORING NOTE* - var flexEls = []; // elements that are allowed to expand. array of DOM nodes - var flexOffsets = []; // amount of vertical space it takes up - var flexHeights = []; // actual css height - var usedHeight = 0; - - undistributeHeight(els); // give all elements their natural height - - // find elements that are below the recommended height (expandable). - // important to query for heights in a single first pass (to avoid reflow oscillation). - els.each(function(i, el) { - var minOffset = i === els.length - 1 ? minOffset2 : minOffset1; - var naturalOffset = $(el).outerHeight(true); - - if (naturalOffset < minOffset) { - flexEls.push(el); - flexOffsets.push(naturalOffset); - flexHeights.push($(el).height()); - } - else { - // this element stretches past recommended height (non-expandable). mark the space as occupied. - usedHeight += naturalOffset; - } - }); - - // readjust the recommended height to only consider the height available to non-maxed-out rows. - if (shouldRedistribute) { - availableHeight -= usedHeight; - minOffset1 = Math.floor(availableHeight / flexEls.length); - minOffset2 = Math.floor(availableHeight - minOffset1 * (flexEls.length - 1)); // *FLOORING NOTE* - } - - // assign heights to all expandable elements - $(flexEls).each(function(i, el) { - var minOffset = i === flexEls.length - 1 ? minOffset2 : minOffset1; - var naturalOffset = flexOffsets[i]; - var naturalHeight = flexHeights[i]; - var newHeight = minOffset - (naturalOffset - naturalHeight); // subtract the margin/padding - - if (naturalOffset < minOffset) { // we check this again because redistribution might have changed things - $(el).height(newHeight); - } - }); -} - - -// Undoes distrubuteHeight, restoring all els to their natural height -function undistributeHeight(els) { - els.height(''); -} - - -// Given `els`, a jQuery set of cells, find the cell with the largest natural width and set the widths of all the -// cells to be that width. -// PREREQUISITE: if you want a cell to take up width, it needs to have a single inner element w/ display:inline -function matchCellWidths(els) { - var maxInnerWidth = 0; - - els.find('> *').each(function(i, innerEl) { - var innerWidth = $(innerEl).outerWidth(); - if (innerWidth > maxInnerWidth) { - maxInnerWidth = innerWidth; - } - }); - - maxInnerWidth++; // sometimes not accurate of width the text needs to stay on one line. insurance - - els.width(maxInnerWidth); - - return maxInnerWidth; -} - - -// Turns a container element into a scroller if its contents is taller than the allotted height. -// Returns true if the element is now a scroller, false otherwise. -// NOTE: this method is best because it takes weird zooming dimensions into account -function setPotentialScroller(containerEl, height) { - containerEl.height(height).addClass('fc-scroller'); - - // are scrollbars needed? - if (containerEl[0].scrollHeight - 1 > containerEl[0].clientHeight) { // !!! -1 because IE is often off-by-one :( - return true; - } - - unsetScroller(containerEl); // undo - return false; -} - - -// Takes an element that might have been a scroller, and turns it back into a normal element. -function unsetScroller(containerEl) { - containerEl.height('').removeClass('fc-scroller'); -} - - -/* General DOM Utilities -----------------------------------------------------------------------------------------------------------------------*/ - - -// borrowed from https://github.com/jquery/jquery-ui/blob/1.11.0/ui/core.js#L51 -function getScrollParent(el) { - var position = el.css('position'), - scrollParent = el.parents().filter(function() { - var parent = $(this); - return (/(auto|scroll)/).test( - parent.css('overflow') + parent.css('overflow-y') + parent.css('overflow-x') - ); - }).eq(0); - - return position === 'fixed' || !scrollParent.length ? $(el[0].ownerDocument || document) : scrollParent; -} - - -// Given a container element, return an object with the pixel values of the left/right scrollbars. -// Left scrollbars might occur on RTL browsers (IE maybe?) but I have not tested. -// PREREQUISITE: container element must have a single child with display:block -function getScrollbarWidths(container) { - var containerLeft = container.offset().left; - var containerRight = containerLeft + container.width(); - var inner = container.children(); - var innerLeft = inner.offset().left; - var innerRight = innerLeft + inner.outerWidth(); - - return { - left: innerLeft - containerLeft, - right: containerRight - innerRight - }; -} - - -// Returns a boolean whether this was a left mouse click and no ctrl key (which means right click on Mac) -function isPrimaryMouseButton(ev) { - return ev.which == 1 && !ev.ctrlKey; -} - - -/* FullCalendar-specific Misc Utilities -----------------------------------------------------------------------------------------------------------------------*/ - - -// Creates a basic segment with the intersection of the two ranges. Returns undefined if no intersection. -// Expects all dates to be normalized to the same timezone beforehand. -function intersectionToSeg(subjectStart, subjectEnd, intervalStart, intervalEnd) { - var segStart, segEnd; - var isStart, isEnd; - - if (subjectEnd > intervalStart && subjectStart < intervalEnd) { // in bounds at all? - - if (subjectStart >= intervalStart) { - segStart = subjectStart.clone(); - isStart = true; - } - else { - segStart = intervalStart.clone(); - isStart = false; - } - - if (subjectEnd <= intervalEnd) { - segEnd = subjectEnd.clone(); - isEnd = true; - } - else { - segEnd = intervalEnd.clone(); - isEnd = false; - } - - return { - start: segStart, - end: segEnd, - isStart: isStart, - isEnd: isEnd - }; - } -} - - -function smartProperty(obj, name) { // get a camel-cased/namespaced property of an object - obj = obj || {}; - if (obj[name] !== undefined) { - return obj[name]; - } - var parts = name.split(/(?=[A-Z])/), - i = parts.length - 1, res; - for (; i>=0; i--) { - res = obj[parts[i].toLowerCase()]; - if (res !== undefined) { - return res; - } - } - return obj['default']; -} - - -/* Date Utilities -----------------------------------------------------------------------------------------------------------------------*/ - -var dayIDs = [ 'sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat' ]; - - -// Diffs the two moments into a Duration where full-days are recorded first, then the remaining time. -// Moments will have their timezones normalized. -function dayishDiff(a, b) { - return moment.duration({ - days: a.clone().stripTime().diff(b.clone().stripTime(), 'days'), - ms: a.time() - b.time() - }); -} - - -function isNativeDate(input) { - return Object.prototype.toString.call(input) === '[object Date]' || input instanceof Date; -} - - -// Returns a boolean about whether the given input is a time string, like "06:40:00" or "06:00" -function isTimeString(str) { - return /^\d+\:\d+(?:\:\d+\.?(?:\d{3})?)?$/.test(str); -} - - -/* General Utilities -----------------------------------------------------------------------------------------------------------------------*/ - -fc.applyAll = applyAll; // export - - -// Create an object that has the given prototype. Just like Object.create -function createObject(proto) { - var f = function() {}; - f.prototype = proto; - return new f(); -} - - -function applyAll(functions, thisObj, args) { - if ($.isFunction(functions)) { - functions = [ functions ]; - } - if (functions) { - var i; - var ret; - for (i=0; i/g, '>') - .replace(/'/g, ''') - .replace(/"/g, '"') - .replace(/\n/g, '
    '); -} - - -function stripHtmlEntities(text) { - return text.replace(/&.*?;/g, ''); -} - - -function capitaliseFirstLetter(str) { - return str.charAt(0).toUpperCase() + str.slice(1); -} - - -function compareNumbers(a, b) { // for .sort() - return a - b; -} - - -// Returns a function, that, as long as it continues to be invoked, will not -// be triggered. The function will be called after it stops being called for -// N milliseconds. -// https://github.com/jashkenas/underscore/blob/1.6.0/underscore.js#L714 -function debounce(func, wait) { - var timeoutId; - var args; - var context; - var timestamp; // of most recent call - var later = function() { - var last = +new Date() - timestamp; - if (last < wait && last > 0) { - timeoutId = setTimeout(later, wait - last); - } - else { - timeoutId = null; - func.apply(context, args); - if (!timeoutId) { - context = args = null; - } - } - }; - - return function() { - context = this; - args = arguments; - timestamp = +new Date(); - if (!timeoutId) { - timeoutId = setTimeout(later, wait); - } - }; -} - -;; - -var ambigDateOfMonthRegex = /^\s*\d{4}-\d\d$/; -var ambigTimeOrZoneRegex = - /^\s*\d{4}-(?:(\d\d-\d\d)|(W\d\d$)|(W\d\d-\d)|(\d\d\d))((T| )(\d\d(:\d\d(:\d\d(\.\d+)?)?)?)?)?$/; -var newMomentProto = moment.fn; // where we will attach our new methods -var oldMomentProto = $.extend({}, newMomentProto); // copy of original moment methods -var allowValueOptimization; -var setUTCValues; // function defined below -var setLocalValues; // function defined below - - -// Creating -// ------------------------------------------------------------------------------------------------- - -// Creates a new moment, similar to the vanilla moment(...) constructor, but with -// extra features (ambiguous time, enhanced formatting). When given an existing moment, -// it will function as a clone (and retain the zone of the moment). Anything else will -// result in a moment in the local zone. -fc.moment = function() { - return makeMoment(arguments); -}; - -// Sames as fc.moment, but forces the resulting moment to be in the UTC timezone. -fc.moment.utc = function() { - var mom = makeMoment(arguments, true); - - // Force it into UTC because makeMoment doesn't guarantee it - // (if given a pre-existing moment for example) - if (mom.hasTime()) { // don't give ambiguously-timed moments a UTC zone - mom.utc(); - } - - return mom; -}; - -// Same as fc.moment, but when given an ISO8601 string, the timezone offset is preserved. -// ISO8601 strings with no timezone offset will become ambiguously zoned. -fc.moment.parseZone = function() { - return makeMoment(arguments, true, true); -}; - -// Builds an enhanced moment from args. When given an existing moment, it clones. When given a -// native Date, or called with no arguments (the current time), the resulting moment will be local. -// Anything else needs to be "parsed" (a string or an array), and will be affected by: -// parseAsUTC - if there is no zone information, should we parse the input in UTC? -// parseZone - if there is zone information, should we force the zone of the moment? -function makeMoment(args, parseAsUTC, parseZone) { - var input = args[0]; - var isSingleString = args.length == 1 && typeof input === 'string'; - var isAmbigTime; - var isAmbigZone; - var ambigMatch; - var mom; - - if (moment.isMoment(input)) { - mom = moment.apply(null, args); // clone it - transferAmbigs(input, mom); // the ambig flags weren't transfered with the clone - } - else if (isNativeDate(input) || input === undefined) { - mom = moment.apply(null, args); // will be local - } - else { // "parsing" is required - isAmbigTime = false; - isAmbigZone = false; - - if (isSingleString) { - if (ambigDateOfMonthRegex.test(input)) { - // accept strings like '2014-05', but convert to the first of the month - input += '-01'; - args = [ input ]; // for when we pass it on to moment's constructor - isAmbigTime = true; - isAmbigZone = true; - } - else if ((ambigMatch = ambigTimeOrZoneRegex.exec(input))) { - isAmbigTime = !ambigMatch[5]; // no time part? - isAmbigZone = true; - } - } - else if ($.isArray(input)) { - // arrays have no timezone information, so assume ambiguous zone - isAmbigZone = true; - } - // otherwise, probably a string with a format - - if (parseAsUTC) { - mom = moment.utc.apply(moment, args); - } - else { - mom = moment.apply(null, args); - } - - if (isAmbigTime) { - mom._ambigTime = true; - mom._ambigZone = true; // ambiguous time always means ambiguous zone - } - else if (parseZone) { // let's record the inputted zone somehow - if (isAmbigZone) { - mom._ambigZone = true; - } - else if (isSingleString) { - mom.zone(input); // if not a valid zone, will assign UTC - } - } - } - - mom._fullCalendar = true; // flag for extended functionality - - return mom; -} - - -// A clone method that works with the flags related to our enhanced functionality. -// In the future, use moment.momentProperties -newMomentProto.clone = function() { - var mom = oldMomentProto.clone.apply(this, arguments); - - // these flags weren't transfered with the clone - transferAmbigs(this, mom); - if (this._fullCalendar) { - mom._fullCalendar = true; - } - - return mom; -}; - - -// Time-of-day -// ------------------------------------------------------------------------------------------------- - -// GETTER -// Returns a Duration with the hours/minutes/seconds/ms values of the moment. -// If the moment has an ambiguous time, a duration of 00:00 will be returned. -// -// SETTER -// You can supply a Duration, a Moment, or a Duration-like argument. -// When setting the time, and the moment has an ambiguous time, it then becomes unambiguous. -newMomentProto.time = function(time) { - - // Fallback to the original method (if there is one) if this moment wasn't created via FullCalendar. - // `time` is a generic enough method name where this precaution is necessary to avoid collisions w/ other plugins. - if (!this._fullCalendar) { - return oldMomentProto.time.apply(this, arguments); - } - - if (time == null) { // getter - return moment.duration({ - hours: this.hours(), - minutes: this.minutes(), - seconds: this.seconds(), - milliseconds: this.milliseconds() - }); - } - else { // setter - - this._ambigTime = false; // mark that the moment now has a time - - if (!moment.isDuration(time) && !moment.isMoment(time)) { - time = moment.duration(time); - } - - // The day value should cause overflow (so 24 hours becomes 00:00:00 of next day). - // Only for Duration times, not Moment times. - var dayHours = 0; - if (moment.isDuration(time)) { - dayHours = Math.floor(time.asDays()) * 24; - } - - // We need to set the individual fields. - // Can't use startOf('day') then add duration. In case of DST at start of day. - return this.hours(dayHours + time.hours()) - .minutes(time.minutes()) - .seconds(time.seconds()) - .milliseconds(time.milliseconds()); - } -}; - -// Converts the moment to UTC, stripping out its time-of-day and timezone offset, -// but preserving its YMD. A moment with a stripped time will display no time -// nor timezone offset when .format() is called. -newMomentProto.stripTime = function() { - var a = this.toArray(); // year,month,date,hours,minutes,seconds as an array - - this.utc(); // set the internal UTC flag (will clear the ambig flags) - setUTCValues(this, a.slice(0, 3)); // set the year/month/date. time will be zero - - // Mark the time as ambiguous. This needs to happen after the .utc() call, which calls .zone(), - // which clears all ambig flags. Same with setUTCValues with moment-timezone. - this._ambigTime = true; - this._ambigZone = true; // if ambiguous time, also ambiguous timezone offset - - return this; // for chaining -}; - -// Returns if the moment has a non-ambiguous time (boolean) -newMomentProto.hasTime = function() { - return !this._ambigTime; -}; - - -// Timezone -// ------------------------------------------------------------------------------------------------- - -// Converts the moment to UTC, stripping out its timezone offset, but preserving its -// YMD and time-of-day. A moment with a stripped timezone offset will display no -// timezone offset when .format() is called. -newMomentProto.stripZone = function() { - var a = this.toArray(); // year,month,date,hours,minutes,seconds as an array - var wasAmbigTime = this._ambigTime; - - this.utc(); // set the internal UTC flag (will clear the ambig flags) - setUTCValues(this, a); // will set the year/month/date/hours/minutes/seconds/ms - - if (wasAmbigTime) { - // the above call to .utc()/.zone() unfortunately clears the ambig flags, so reassign - this._ambigTime = true; - } - - // Mark the zone as ambiguous. This needs to happen after the .utc() call, which calls .zone(), - // which clears all ambig flags. Same with setUTCValues with moment-timezone. - this._ambigZone = true; - - return this; // for chaining -}; - -// Returns of the moment has a non-ambiguous timezone offset (boolean) -newMomentProto.hasZone = function() { - return !this._ambigZone; -}; - -// this method implicitly marks a zone (will get called upon .utc() and .local()) -newMomentProto.zone = function(tzo) { - - if (tzo != null) { // setter - // these assignments needs to happen before the original zone method is called. - // I forget why, something to do with a browser crash. - this._ambigTime = false; - this._ambigZone = false; - } - - return oldMomentProto.zone.apply(this, arguments); -}; - -// this method implicitly marks a zone -newMomentProto.local = function() { - var a = this.toArray(); // year,month,date,hours,minutes,seconds,ms as an array - var wasAmbigZone = this._ambigZone; - - oldMomentProto.local.apply(this, arguments); // will clear ambig flags - - if (wasAmbigZone) { - // If the moment was ambiguously zoned, the date fields were stored as UTC. - // We want to preserve these, but in local time. - setLocalValues(this, a); - } - - return this; // for chaining -}; - - -// Formatting -// ------------------------------------------------------------------------------------------------- - -newMomentProto.format = function() { - if (this._fullCalendar && arguments[0]) { // an enhanced moment? and a format string provided? - return formatDate(this, arguments[0]); // our extended formatting - } - if (this._ambigTime) { - return oldMomentFormat(this, 'YYYY-MM-DD'); - } - if (this._ambigZone) { - return oldMomentFormat(this, 'YYYY-MM-DD[T]HH:mm:ss'); - } - return oldMomentProto.format.apply(this, arguments); -}; - -newMomentProto.toISOString = function() { - if (this._ambigTime) { - return oldMomentFormat(this, 'YYYY-MM-DD'); - } - if (this._ambigZone) { - return oldMomentFormat(this, 'YYYY-MM-DD[T]HH:mm:ss'); - } - return oldMomentProto.toISOString.apply(this, arguments); -}; - - -// Querying -// ------------------------------------------------------------------------------------------------- - -// Is the moment within the specified range? `end` is exclusive. -// FYI, this method is not a standard Moment method, so always do our enhanced logic. -newMomentProto.isWithin = function(start, end) { - var a = commonlyAmbiguate([ this, start, end ]); - return a[0] >= a[1] && a[0] < a[2]; -}; - -// When isSame is called with units, timezone ambiguity is normalized before the comparison happens. -// If no units specified, the two moments must be identically the same, with matching ambig flags. -newMomentProto.isSame = function(input, units) { - var a; - - // only do custom logic if this is an enhanced moment - if (!this._fullCalendar) { - return oldMomentProto.isSame.apply(this, arguments); - } - - if (units) { - a = commonlyAmbiguate([ this, input ], true); // normalize timezones but don't erase times - return oldMomentProto.isSame.call(a[0], a[1], units); - } - else { - input = fc.moment.parseZone(input); // normalize input - return oldMomentProto.isSame.call(this, input) && - Boolean(this._ambigTime) === Boolean(input._ambigTime) && - Boolean(this._ambigZone) === Boolean(input._ambigZone); - } -}; - -// Make these query methods work with ambiguous moments -$.each([ - 'isBefore', - 'isAfter' -], function(i, methodName) { - newMomentProto[methodName] = function(input, units) { - var a; - - // only do custom logic if this is an enhanced moment - if (!this._fullCalendar) { - return oldMomentProto[methodName].apply(this, arguments); - } - - a = commonlyAmbiguate([ this, input ]); - return oldMomentProto[methodName].call(a[0], a[1], units); - }; -}); - - -// Misc Internals -// ------------------------------------------------------------------------------------------------- - -// given an array of moment-like inputs, return a parallel array w/ moments similarly ambiguated. -// for example, of one moment has ambig time, but not others, all moments will have their time stripped. -// set `preserveTime` to `true` to keep times, but only normalize zone ambiguity. -function commonlyAmbiguate(inputs, preserveTime) { - var outputs = []; - var anyAmbigTime = false; - var anyAmbigZone = false; - var i; - - for (i=0; i "MMMM D YYYY" - formatStr = localeData.longDateFormat(formatStr) || formatStr; - // BTW, this is not important for `formatDate` because it is impossible to put custom tokens - // or non-zero areas in Moment's localized format strings. - - separator = separator || ' - '; - - return formatRangeWithChunks( - date1, - date2, - getFormatStringChunks(formatStr), - separator, - isRTL - ); -} -fc.formatRange = formatRange; // expose - - -function formatRangeWithChunks(date1, date2, chunks, separator, isRTL) { - var chunkStr; // the rendering of the chunk - var leftI; - var leftStr = ''; - var rightI; - var rightStr = ''; - var middleI; - var middleStr1 = ''; - var middleStr2 = ''; - var middleStr = ''; - - // Start at the leftmost side of the formatting string and continue until you hit a token - // that is not the same between dates. - for (leftI=0; leftIleftI; rightI--) { - chunkStr = formatSimilarChunk(date1, date2, chunks[rightI]); - if (chunkStr === false) { - break; - } - rightStr = chunkStr + rightStr; - } - - // The area in the middle is different for both of the dates. - // Collect them distinctly so we can jam them together later. - for (middleI=leftI; middleI<=rightI; middleI++) { - middleStr1 += formatDateWithChunk(date1, chunks[middleI]); - middleStr2 += formatDateWithChunk(date2, chunks[middleI]); - } - - if (middleStr1 || middleStr2) { - if (isRTL) { - middleStr = middleStr2 + separator + middleStr1; - } - else { - middleStr = middleStr1 + separator + middleStr2; - } - } - - return leftStr + middleStr + rightStr; -} - - -var similarUnitMap = { - Y: 'year', - M: 'month', - D: 'day', // day of month - d: 'day', // day of week - // prevents a separator between anything time-related... - A: 'second', // AM/PM - a: 'second', // am/pm - T: 'second', // A/P - t: 'second', // a/p - H: 'second', // hour (24) - h: 'second', // hour (12) - m: 'second', // minute - s: 'second' // second -}; -// TODO: week maybe? - - -// Given a formatting chunk, and given that both dates are similar in the regard the -// formatting chunk is concerned, format date1 against `chunk`. Otherwise, return `false`. -function formatSimilarChunk(date1, date2, chunk) { - var token; - var unit; - - if (typeof chunk === 'string') { // a literal string - return chunk; - } - else if ((token = chunk.token)) { - unit = similarUnitMap[token.charAt(0)]; - // are the dates the same for this unit of measurement? - if (unit && date1.isSame(date2, unit)) { - return oldMomentFormat(date1, token); // would be the same if we used `date2` - // BTW, don't support custom tokens - } - } - - return false; // the chunk is NOT the same for the two dates - // BTW, don't support splitting on non-zero areas -} - - -// Chunking Utils -// ------------------------------------------------------------------------------------------------- - - -var formatStringChunkCache = {}; - - -function getFormatStringChunks(formatStr) { - if (formatStr in formatStringChunkCache) { - return formatStringChunkCache[formatStr]; - } - return (formatStringChunkCache[formatStr] = chunkFormatString(formatStr)); -} - - -// Break the formatting string into an array of chunks -function chunkFormatString(formatStr) { - var chunks = []; - var chunker = /\[([^\]]*)\]|\(([^\)]*)\)|(LT|(\w)\4*o?)|([^\w\[\(]+)/g; // TODO: more descrimination - var match; - - while ((match = chunker.exec(formatStr))) { - if (match[1]) { // a literal string inside [ ... ] - chunks.push(match[1]); - } - else if (match[2]) { // non-zero formatting inside ( ... ) - chunks.push({ maybe: chunkFormatString(match[2]) }); - } - else if (match[3]) { // a formatting token - chunks.push({ token: match[3] }); - } - else if (match[5]) { // an unenclosed literal string - chunks.push(match[5]); - } - } - - return chunks; -} - -;; - -/* A rectangular panel that is absolutely positioned over other content ------------------------------------------------------------------------------------------------------------------------- -Options: - - className (string) - - content (HTML string or jQuery element set) - - parentEl - - top - - left - - right (the x coord of where the right edge should be. not a "CSS" right) - - autoHide (boolean) - - show (callback) - - hide (callback) -*/ - -function Popover(options) { - this.options = options || {}; -} - - -Popover.prototype = { - - isHidden: true, - options: null, - el: null, // the container element for the popover. generated by this object - documentMousedownProxy: null, // document mousedown handler bound to `this` - margin: 10, // the space required between the popover and the edges of the scroll container - - - // Shows the popover on the specified position. Renders it if not already - show: function() { - if (this.isHidden) { - if (!this.el) { - this.render(); - } - this.el.show(); - this.position(); - this.isHidden = false; - this.trigger('show'); - } - }, - - - // Hides the popover, through CSS, but does not remove it from the DOM - hide: function() { - if (!this.isHidden) { - this.el.hide(); - this.isHidden = true; - this.trigger('hide'); - } - }, - - - // Creates `this.el` and renders content inside of it - render: function() { - var _this = this; - var options = this.options; - - this.el = $('
    ') - .addClass(options.className || '') - .css({ - // position initially to the top left to avoid creating scrollbars - top: 0, - left: 0 - }) - .append(options.content) - .appendTo(options.parentEl); - - // when a click happens on anything inside with a 'fc-close' className, hide the popover - this.el.on('click', '.fc-close', function() { - _this.hide(); - }); - - if (options.autoHide) { - $(document).on('mousedown', this.documentMousedownProxy = $.proxy(this, 'documentMousedown')); - } - }, - - - // Triggered when the user clicks *anywhere* in the document, for the autoHide feature - documentMousedown: function(ev) { - // only hide the popover if the click happened outside the popover - if (this.el && !$(ev.target).closest(this.el).length) { - this.hide(); - } - }, - - - // Hides and unregisters any handlers - destroy: function() { - this.hide(); - - if (this.el) { - this.el.remove(); - this.el = null; - } - - $(document).off('mousedown', this.documentMousedownProxy); - }, - - - // Positions the popover optimally, using the top/left/right options - position: function() { - var options = this.options; - var origin = this.el.offsetParent().offset(); - var width = this.el.outerWidth(); - var height = this.el.outerHeight(); - var windowEl = $(window); - var viewportEl = getScrollParent(this.el); - var viewportTop; - var viewportLeft; - var viewportOffset; - var top; // the "position" (not "offset") values for the popover - var left; // - - // compute top and left - top = options.top || 0; - if (options.left !== undefined) { - left = options.left; - } - else if (options.right !== undefined) { - left = options.right - width; // derive the left value from the right value - } - else { - left = 0; - } - - if (viewportEl.is(window) || viewportEl.is(document)) { // normalize getScrollParent's result - viewportEl = windowEl; - viewportTop = 0; // the window is always at the top left - viewportLeft = 0; // (and .offset() won't work if called here) - } - else { - viewportOffset = viewportEl.offset(); - viewportTop = viewportOffset.top; - viewportLeft = viewportOffset.left; - } - - // if the window is scrolled, it causes the visible area to be further down - viewportTop += windowEl.scrollTop(); - viewportLeft += windowEl.scrollLeft(); - - // constrain to the view port. if constrained by two edges, give precedence to top/left - if (options.viewportConstrain !== false) { - top = Math.min(top, viewportTop + viewportEl.outerHeight() - height - this.margin); - top = Math.max(top, viewportTop + this.margin); - left = Math.min(left, viewportLeft + viewportEl.outerWidth() - width - this.margin); - left = Math.max(left, viewportLeft + this.margin); - } - - this.el.css({ - top: top - origin.top, - left: left - origin.left - }); - }, - - - // Triggers a callback. Calls a function in the option hash of the same name. - // Arguments beyond the first `name` are forwarded on. - // TODO: better code reuse for this. Repeat code - trigger: function(name) { - if (this.options[name]) { - this.options[name].apply(this, Array.prototype.slice.call(arguments, 1)); - } - } - -}; - -;; - -/* A "coordinate map" converts pixel coordinates into an associated cell, which has an associated date ------------------------------------------------------------------------------------------------------------------------- -Common interface: - - CoordMap.prototype = { - build: function() {}, - getCell: function(x, y) {} - }; - -*/ - -/* Coordinate map for a grid component -----------------------------------------------------------------------------------------------------------------------*/ - -function GridCoordMap(grid) { - this.grid = grid; -} - - -GridCoordMap.prototype = { - - grid: null, // reference to the Grid - rows: null, // the top-to-bottom y coordinates. including the bottom of the last item - cols: null, // the left-to-right x coordinates. including the right of the last item - - containerEl: null, // container element that all coordinates are constrained to. optionally assigned - minX: null, - maxX: null, // exclusive - minY: null, - maxY: null, // exclusive - - - // Queries the grid for the coordinates of all the cells - build: function() { - this.grid.buildCoords( - this.rows = [], - this.cols = [] - ); - this.computeBounds(); - }, - - - // Given a coordinate of the document, gets the associated cell. If no cell is underneath, returns null - getCell: function(x, y) { - var cell = null; - var rows = this.rows; - var cols = this.cols; - var r = -1; - var c = -1; - var i; - - if (this.inBounds(x, y)) { - - for (i = 0; i < rows.length; i++) { - if (y >= rows[i][0] && y < rows[i][1]) { - r = i; - break; - } - } - - for (i = 0; i < cols.length; i++) { - if (x >= cols[i][0] && x < cols[i][1]) { - c = i; - break; - } - } - - if (r >= 0 && c >= 0) { - cell = { row: r, col: c }; - cell.grid = this.grid; - cell.date = this.grid.getCellDate(cell); - } - } - - return cell; - }, - - - // If there is a containerEl, compute the bounds into min/max values - computeBounds: function() { - var containerOffset; - - if (this.containerEl) { - containerOffset = this.containerEl.offset(); - this.minX = containerOffset.left; - this.maxX = containerOffset.left + this.containerEl.outerWidth(); - this.minY = containerOffset.top; - this.maxY = containerOffset.top + this.containerEl.outerHeight(); - } - }, - - - // Determines if the given coordinates are in bounds. If no `containerEl`, always true - inBounds: function(x, y) { - if (this.containerEl) { - return x >= this.minX && x < this.maxX && y >= this.minY && y < this.maxY; - } - return true; - } - -}; - - -/* Coordinate map that is a combination of multiple other coordinate maps -----------------------------------------------------------------------------------------------------------------------*/ - -function ComboCoordMap(coordMaps) { - this.coordMaps = coordMaps; -} - - -ComboCoordMap.prototype = { - - coordMaps: null, // an array of CoordMaps - - - // Builds all coordMaps - build: function() { - var coordMaps = this.coordMaps; - var i; - - for (i = 0; i < coordMaps.length; i++) { - coordMaps[i].build(); - } - }, - - - // Queries all coordMaps for the cell underneath the given coordinates, returning the first result - getCell: function(x, y) { - var coordMaps = this.coordMaps; - var cell = null; - var i; - - for (i = 0; i < coordMaps.length && !cell; i++) { - cell = coordMaps[i].getCell(x, y); - } - - return cell; - } - -}; - -;; - -/* Tracks mouse movements over a CoordMap and raises events about which cell the mouse is over. -----------------------------------------------------------------------------------------------------------------------*/ -// TODO: very useful to have a handler that gets called upon cellOut OR when dragging stops (for cleanup) - -function DragListener(coordMap, options) { - this.coordMap = coordMap; - this.options = options || {}; -} - - -DragListener.prototype = { - - coordMap: null, - options: null, - - isListening: false, - isDragging: false, - - // the cell/date the mouse was over when listening started - origCell: null, - origDate: null, - - // the cell/date the mouse is over - cell: null, - date: null, - - // coordinates of the initial mousedown - mouseX0: null, - mouseY0: null, - - // handler attached to the document, bound to the DragListener's `this` - mousemoveProxy: null, - mouseupProxy: null, - - scrollEl: null, - scrollBounds: null, // { top, bottom, left, right } - scrollTopVel: null, // pixels per second - scrollLeftVel: null, // pixels per second - scrollIntervalId: null, // ID of setTimeout for scrolling animation loop - scrollHandlerProxy: null, // this-scoped function for handling when scrollEl is scrolled - - scrollSensitivity: 30, // pixels from edge for scrolling to start - scrollSpeed: 200, // pixels per second, at maximum speed - scrollIntervalMs: 50, // millisecond wait between scroll increment - - - // Call this when the user does a mousedown. Will probably lead to startListening - mousedown: function(ev) { - if (isPrimaryMouseButton(ev)) { - - ev.preventDefault(); // prevents native selection in most browsers - - this.startListening(ev); - - // start the drag immediately if there is no minimum distance for a drag start - if (!this.options.distance) { - this.startDrag(ev); - } - } - }, - - - // Call this to start tracking mouse movements - startListening: function(ev) { - var scrollParent; - var cell; - - if (!this.isListening) { - - // grab scroll container and attach handler - if (ev && this.options.scroll) { - scrollParent = getScrollParent($(ev.target)); - if (!scrollParent.is(window) && !scrollParent.is(document)) { - this.scrollEl = scrollParent; - - // scope to `this`, and use `debounce` to make sure rapid calls don't happen - this.scrollHandlerProxy = debounce($.proxy(this, 'scrollHandler'), 100); - this.scrollEl.on('scroll', this.scrollHandlerProxy); - } - } - - this.computeCoords(); // relies on `scrollEl` - - // get info on the initial cell, date, and coordinates - if (ev) { - cell = this.getCell(ev); - this.origCell = cell; - this.origDate = cell ? cell.date : null; - - this.mouseX0 = ev.pageX; - this.mouseY0 = ev.pageY; - } - - $(document) - .on('mousemove', this.mousemoveProxy = $.proxy(this, 'mousemove')) - .on('mouseup', this.mouseupProxy = $.proxy(this, 'mouseup')) - .on('selectstart', this.preventDefault); // prevents native selection in IE<=8 - - this.isListening = true; - this.trigger('listenStart', ev); - } - }, - - - // Recomputes the drag-critical positions of elements - computeCoords: function() { - this.coordMap.build(); - this.computeScrollBounds(); - }, - - - // Called when the user moves the mouse - mousemove: function(ev) { - var minDistance; - var distanceSq; // current distance from mouseX0/mouseY0, squared - - if (!this.isDragging) { // if not already dragging... - // then start the drag if the minimum distance criteria is met - minDistance = this.options.distance || 1; - distanceSq = Math.pow(ev.pageX - this.mouseX0, 2) + Math.pow(ev.pageY - this.mouseY0, 2); - if (distanceSq >= minDistance * minDistance) { // use pythagorean theorem - this.startDrag(ev); - } - } - - if (this.isDragging) { - this.drag(ev); // report a drag, even if this mousemove initiated the drag - } - }, - - - // Call this to initiate a legitimate drag. - // This function is called internally from this class, but can also be called explicitly from outside - startDrag: function(ev) { - var cell; - - if (!this.isListening) { // startDrag must have manually initiated - this.startListening(); - } - - if (!this.isDragging) { - this.isDragging = true; - this.trigger('dragStart', ev); - - // report the initial cell the mouse is over - cell = this.getCell(ev); - if (cell) { - this.cellOver(cell, true); - } - } - }, - - - // Called while the mouse is being moved and when we know a legitimate drag is taking place - drag: function(ev) { - var cell; - - if (this.isDragging) { - cell = this.getCell(ev); - - if (!isCellsEqual(cell, this.cell)) { // a different cell than before? - if (this.cell) { - this.cellOut(); - } - if (cell) { - this.cellOver(cell); - } - } - - this.dragScroll(ev); // will possibly cause scrolling - } - }, - - - // Called when a the mouse has just moved over a new cell - cellOver: function(cell) { - this.cell = cell; - this.date = cell.date; - this.trigger('cellOver', cell, cell.date); - }, - - - // Called when the mouse has just moved out of a cell - cellOut: function() { - if (this.cell) { - this.trigger('cellOut', this.cell); - this.cell = null; - this.date = null; - } - }, - - - // Called when the user does a mouseup - mouseup: function(ev) { - this.stopDrag(ev); - this.stopListening(ev); - }, - - - // Called when the drag is over. Will not cause listening to stop however. - // A concluding 'cellOut' event will NOT be triggered. - stopDrag: function(ev) { - if (this.isDragging) { - this.stopScrolling(); - this.trigger('dragStop', ev); - this.isDragging = false; - } - }, - - - // Call this to stop listening to the user's mouse events - stopListening: function(ev) { - if (this.isListening) { - - // remove the scroll handler if there is a scrollEl - if (this.scrollEl) { - this.scrollEl.off('scroll', this.scrollHandlerProxy); - this.scrollHandlerProxy = null; - } - - $(document) - .off('mousemove', this.mousemoveProxy) - .off('mouseup', this.mouseupProxy) - .off('selectstart', this.preventDefault); - - this.mousemoveProxy = null; - this.mouseupProxy = null; - - this.isListening = false; - this.trigger('listenStop', ev); - - this.origCell = this.cell = null; - this.origDate = this.date = null; - } - }, - - - // Gets the cell underneath the coordinates for the given mouse event - getCell: function(ev) { - return this.coordMap.getCell(ev.pageX, ev.pageY); - }, - - - // Triggers a callback. Calls a function in the option hash of the same name. - // Arguments beyond the first `name` are forwarded on. - trigger: function(name) { - if (this.options[name]) { - this.options[name].apply(this, Array.prototype.slice.call(arguments, 1)); - } - }, - - - // Stops a given mouse event from doing it's native browser action. In our case, text selection. - preventDefault: function(ev) { - ev.preventDefault(); - }, - - - /* Scrolling - ------------------------------------------------------------------------------------------------------------------*/ - - - // Computes and stores the bounding rectangle of scrollEl - computeScrollBounds: function() { - var el = this.scrollEl; - var offset; - - if (el) { - offset = el.offset(); - this.scrollBounds = { - top: offset.top, - left: offset.left, - bottom: offset.top + el.outerHeight(), - right: offset.left + el.outerWidth() - }; - } - }, - - - // Called when the dragging is in progress and scrolling should be updated - dragScroll: function(ev) { - var sensitivity = this.scrollSensitivity; - var bounds = this.scrollBounds; - var topCloseness, bottomCloseness; - var leftCloseness, rightCloseness; - var topVel = 0; - var leftVel = 0; - - if (bounds) { // only scroll if scrollEl exists - - // compute closeness to edges. valid range is from 0.0 - 1.0 - topCloseness = (sensitivity - (ev.pageY - bounds.top)) / sensitivity; - bottomCloseness = (sensitivity - (bounds.bottom - ev.pageY)) / sensitivity; - leftCloseness = (sensitivity - (ev.pageX - bounds.left)) / sensitivity; - rightCloseness = (sensitivity - (bounds.right - ev.pageX)) / sensitivity; - - // translate vertical closeness into velocity. - // mouse must be completely in bounds for velocity to happen. - if (topCloseness >= 0 && topCloseness <= 1) { - topVel = topCloseness * this.scrollSpeed * -1; // negative. for scrolling up - } - else if (bottomCloseness >= 0 && bottomCloseness <= 1) { - topVel = bottomCloseness * this.scrollSpeed; - } - - // translate horizontal closeness into velocity - if (leftCloseness >= 0 && leftCloseness <= 1) { - leftVel = leftCloseness * this.scrollSpeed * -1; // negative. for scrolling left - } - else if (rightCloseness >= 0 && rightCloseness <= 1) { - leftVel = rightCloseness * this.scrollSpeed; - } - } - - this.setScrollVel(topVel, leftVel); - }, - - - // Sets the speed-of-scrolling for the scrollEl - setScrollVel: function(topVel, leftVel) { - - this.scrollTopVel = topVel; - this.scrollLeftVel = leftVel; - - this.constrainScrollVel(); // massages into realistic values - - // if there is non-zero velocity, and an animation loop hasn't already started, then START - if ((this.scrollTopVel || this.scrollLeftVel) && !this.scrollIntervalId) { - this.scrollIntervalId = setInterval( - $.proxy(this, 'scrollIntervalFunc'), // scope to `this` - this.scrollIntervalMs - ); - } - }, - - - // Forces scrollTopVel and scrollLeftVel to be zero if scrolling has already gone all the way - constrainScrollVel: function() { - var el = this.scrollEl; - - if (this.scrollTopVel < 0) { // scrolling up? - if (el.scrollTop() <= 0) { // already scrolled all the way up? - this.scrollTopVel = 0; - } - } - else if (this.scrollTopVel > 0) { // scrolling down? - if (el.scrollTop() + el[0].clientHeight >= el[0].scrollHeight) { // already scrolled all the way down? - this.scrollTopVel = 0; - } - } - - if (this.scrollLeftVel < 0) { // scrolling left? - if (el.scrollLeft() <= 0) { // already scrolled all the left? - this.scrollLeftVel = 0; - } - } - else if (this.scrollLeftVel > 0) { // scrolling right? - if (el.scrollLeft() + el[0].clientWidth >= el[0].scrollWidth) { // already scrolled all the way right? - this.scrollLeftVel = 0; - } - } - }, - - - // This function gets called during every iteration of the scrolling animation loop - scrollIntervalFunc: function() { - var el = this.scrollEl; - var frac = this.scrollIntervalMs / 1000; // considering animation frequency, what the vel should be mult'd by - - // change the value of scrollEl's scroll - if (this.scrollTopVel) { - el.scrollTop(el.scrollTop() + this.scrollTopVel * frac); - } - if (this.scrollLeftVel) { - el.scrollLeft(el.scrollLeft() + this.scrollLeftVel * frac); - } - - this.constrainScrollVel(); // since the scroll values changed, recompute the velocities - - // if scrolled all the way, which causes the vels to be zero, stop the animation loop - if (!this.scrollTopVel && !this.scrollLeftVel) { - this.stopScrolling(); - } - }, - - - // Kills any existing scrolling animation loop - stopScrolling: function() { - if (this.scrollIntervalId) { - clearInterval(this.scrollIntervalId); - this.scrollIntervalId = null; - - // when all done with scrolling, recompute positions since they probably changed - this.computeCoords(); - } - }, - - - // Get called when the scrollEl is scrolled (NOTE: this is delayed via debounce) - scrollHandler: function() { - // recompute all coordinates, but *only* if this is *not* part of our scrolling animation - if (!this.scrollIntervalId) { - this.computeCoords(); - } - } - -}; - - -// Returns `true` if the cells are identically equal. `false` otherwise. -// They must have the same row, col, and be from the same grid. -// Two null values will be considered equal, as two "out of the grid" states are the same. -function isCellsEqual(cell1, cell2) { - - if (!cell1 && !cell2) { - return true; - } - - if (cell1 && cell2) { - return cell1.grid === cell2.grid && - cell1.row === cell2.row && - cell1.col === cell2.col; - } - - return false; -} - -;; - -/* Creates a clone of an element and lets it track the mouse as it moves -----------------------------------------------------------------------------------------------------------------------*/ - -function MouseFollower(sourceEl, options) { - this.options = options = options || {}; - this.sourceEl = sourceEl; - this.parentEl = options.parentEl ? $(options.parentEl) : sourceEl.parent(); // default to sourceEl's parent -} - - -MouseFollower.prototype = { - - options: null, - - sourceEl: null, // the element that will be cloned and made to look like it is dragging - el: null, // the clone of `sourceEl` that will track the mouse - parentEl: null, // the element that `el` (the clone) will be attached to - - // the initial position of el, relative to the offset parent. made to match the initial offset of sourceEl - top0: null, - left0: null, - - // the initial position of the mouse - mouseY0: null, - mouseX0: null, - - // the number of pixels the mouse has moved from its initial position - topDelta: null, - leftDelta: null, - - mousemoveProxy: null, // document mousemove handler, bound to the MouseFollower's `this` - - isFollowing: false, - isHidden: false, - isAnimating: false, // doing the revert animation? - - - // Causes the element to start following the mouse - start: function(ev) { - if (!this.isFollowing) { - this.isFollowing = true; - - this.mouseY0 = ev.pageY; - this.mouseX0 = ev.pageX; - this.topDelta = 0; - this.leftDelta = 0; - - if (!this.isHidden) { - this.updatePosition(); - } - - $(document).on('mousemove', this.mousemoveProxy = $.proxy(this, 'mousemove')); - } - }, - - - // Causes the element to stop following the mouse. If shouldRevert is true, will animate back to original position. - // `callback` gets invoked when the animation is complete. If no animation, it is invoked immediately. - stop: function(shouldRevert, callback) { - var _this = this; - var revertDuration = this.options.revertDuration; - - function complete() { - this.isAnimating = false; - _this.destroyEl(); - - this.top0 = this.left0 = null; // reset state for future updatePosition calls - - if (callback) { - callback(); - } - } - - if (this.isFollowing && !this.isAnimating) { // disallow more than one stop animation at a time - this.isFollowing = false; - - $(document).off('mousemove', this.mousemoveProxy); - - if (shouldRevert && revertDuration && !this.isHidden) { // do a revert animation? - this.isAnimating = true; - this.el.animate({ - top: this.top0, - left: this.left0 - }, { - duration: revertDuration, - complete: complete - }); - } - else { - complete(); - } - } - }, - - - // Gets the tracking element. Create it if necessary - getEl: function() { - var el = this.el; - - if (!el) { - this.sourceEl.width(); // hack to force IE8 to compute correct bounding box - el = this.el = this.sourceEl.clone() - .css({ - position: 'absolute', - visibility: '', // in case original element was hidden (commonly through hideEvents()) - display: this.isHidden ? 'none' : '', // for when initially hidden - margin: 0, - right: 'auto', // erase and set width instead - bottom: 'auto', // erase and set height instead - width: this.sourceEl.width(), // explicit height in case there was a 'right' value - height: this.sourceEl.height(), // explicit width in case there was a 'bottom' value - opacity: this.options.opacity || '', - zIndex: this.options.zIndex - }) - .appendTo(this.parentEl); - } - - return el; - }, - - - // Removes the tracking element if it has already been created - destroyEl: function() { - if (this.el) { - this.el.remove(); - this.el = null; - } - }, - - - // Update the CSS position of the tracking element - updatePosition: function() { - var sourceOffset; - var origin; - - this.getEl(); // ensure this.el - - // make sure origin info was computed - if (this.top0 === null) { - this.sourceEl.width(); // hack to force IE8 to compute correct bounding box - sourceOffset = this.sourceEl.offset(); - origin = this.el.offsetParent().offset(); - this.top0 = sourceOffset.top - origin.top; - this.left0 = sourceOffset.left - origin.left; - } - - this.el.css({ - top: this.top0 + this.topDelta, - left: this.left0 + this.leftDelta - }); - }, - - - // Gets called when the user moves the mouse - mousemove: function(ev) { - this.topDelta = ev.pageY - this.mouseY0; - this.leftDelta = ev.pageX - this.mouseX0; - - if (!this.isHidden) { - this.updatePosition(); - } - }, - - - // Temporarily makes the tracking element invisible. Can be called before following starts - hide: function() { - if (!this.isHidden) { - this.isHidden = true; - if (this.el) { - this.el.hide(); - } - } - }, - - - // Show the tracking element after it has been temporarily hidden - show: function() { - if (this.isHidden) { - this.isHidden = false; - this.updatePosition(); - this.getEl().show(); - } - } - -}; - -;; - -/* A utility class for rendering rows. -----------------------------------------------------------------------------------------------------------------------*/ -// It leverages methods of the subclass and the View to determine custom rendering behavior for each row "type" -// (such as highlight rows, day rows, helper rows, etc). - -function RowRenderer(view) { - this.view = view; -} - - -RowRenderer.prototype = { - - view: null, // a View object - cellHtml: '', // plain default HTML used for a cell when no other is available - - - // Renders the HTML for a row, leveraging custom cell-HTML-renderers based on the `rowType`. - // Also applies the "intro" and "outro" cells, which are specified by the subclass and views. - // `row` is an optional row number. - rowHtml: function(rowType, row) { - var view = this.view; - var renderCell = this.getHtmlRenderer('cell', rowType); - var cellHtml = ''; - var col; - var date; - - row = row || 0; - - for (col = 0; col < view.colCnt; col++) { - date = view.cellToDate(row, col); - cellHtml += renderCell(row, col, date); - } - - cellHtml = this.bookendCells(cellHtml, rowType, row); // apply intro and outro - - return '' + cellHtml + ''; - }, - - - // Applies the "intro" and "outro" HTML to the given cells. - // Intro means the leftmost cell when the calendar is LTR and the rightmost cell when RTL. Vice-versa for outro. - // `cells` can be an HTML string of 's or a jQuery element - // `row` is an optional row number. - bookendCells: function(cells, rowType, row) { - var view = this.view; - var intro = this.getHtmlRenderer('intro', rowType)(row || 0); - var outro = this.getHtmlRenderer('outro', rowType)(row || 0); - var isRTL = view.opt('isRTL'); - var prependHtml = isRTL ? outro : intro; - var appendHtml = isRTL ? intro : outro; - - if (typeof cells === 'string') { - return prependHtml + cells + appendHtml; - } - else { // a jQuery element - return cells.prepend(prependHtml).append(appendHtml); - } - }, - - - // Returns an HTML-rendering function given a specific `rendererName` (like cell, intro, or outro) and a specific - // `rowType` (like day, eventSkeleton, helperSkeleton), which is optional. - // If a renderer for the specific rowType doesn't exist, it will fall back to a generic renderer. - // We will query the View object first for any custom rendering functions, then the methods of the subclass. - getHtmlRenderer: function(rendererName, rowType) { - var view = this.view; - var generalName; // like "cellHtml" - var specificName; // like "dayCellHtml". based on rowType - var provider; // either the View or the RowRenderer subclass, whichever provided the method - var renderer; - - generalName = rendererName + 'Html'; - if (rowType) { - specificName = rowType + capitaliseFirstLetter(rendererName) + 'Html'; - } - - if (specificName && (renderer = view[specificName])) { - provider = view; - } - else if (specificName && (renderer = this[specificName])) { - provider = this; - } - else if ((renderer = view[generalName])) { - provider = view; - } - else if ((renderer = this[generalName])) { - provider = this; - } - - if (typeof renderer === 'function') { - return function() { - return renderer.apply(provider, arguments) || ''; // use correct `this` and always return a string - }; - } - - // the rendered can be a plain string as well. if not specified, always an empty string. - return function() { - return renderer || ''; - }; - } - -}; - -;; - -/* An abstract class comprised of a "grid" of cells that each represent a specific datetime -----------------------------------------------------------------------------------------------------------------------*/ - -function Grid(view) { - RowRenderer.call(this, view); // call the super-constructor - this.coordMap = new GridCoordMap(this); - this.elsByFill = {}; -} - - -Grid.prototype = createObject(RowRenderer.prototype); // declare the super-class -$.extend(Grid.prototype, { - - el: null, // the containing element - coordMap: null, // a GridCoordMap that converts pixel values to datetimes - cellDuration: null, // a cell's duration. subclasses must assign this ASAP - elsByFill: null, // a hash of jQuery element sets used for rendering each fill. Keyed by fill name. - - - // Renders the grid into the `el` element. - // Subclasses should override and call this super-method when done. - render: function() { - this.bindHandlers(); - }, - - - // Called when the grid's resources need to be cleaned up - destroy: function() { - // subclasses can implement - }, - - - /* Coordinates & Cells - ------------------------------------------------------------------------------------------------------------------*/ - - - // Populates the given empty arrays with the y and x coordinates of the cells - buildCoords: function(rows, cols) { - // subclasses must implement - }, - - - // Given a cell object, returns the date for that cell - getCellDate: function(cell) { - // subclasses must implement - }, - - - // Given a cell object, returns the element that represents the cell's whole-day - getCellDayEl: function(cell) { - // subclasses must implement - }, - - - // Converts a range with an inclusive `start` and an exclusive `end` into an array of segment objects - rangeToSegs: function(start, end) { - // subclasses must implement - }, - - - /* Handlers - ------------------------------------------------------------------------------------------------------------------*/ - - - // Attach handlers to `this.el`, using bubbling to listen to all ancestors. - // We don't need to undo any of this in a "destroy" method, because the view will simply remove `this.el` from the - // DOM and jQuery will be smart enough to garbage collect the handlers. - bindHandlers: function() { - var _this = this; - - this.el.on('mousedown', function(ev) { - if ( - !$(ev.target).is('.fc-event-container *, .fc-more') && // not an an event element, or "more.." link - !$(ev.target).closest('.fc-popover').length // not on a popover (like the "more.." events one) - ) { - _this.dayMousedown(ev); - } - }); - - this.bindSegHandlers(); // attach event-element-related handlers. in Grid.events.js - }, - - - // Process a mousedown on an element that represents a day. For day clicking and selecting. - dayMousedown: function(ev) { - var _this = this; - var view = this.view; - var calendar = view.calendar; - var isSelectable = view.opt('selectable'); - var dates = null; // the inclusive dates of the selection. will be null if no selection - var start; // the inclusive start of the selection - var end; // the *exclusive* end of the selection - var dayEl; - - // this listener tracks a mousedown on a day element, and a subsequent drag. - // if the drag ends on the same day, it is a 'dayClick'. - // if 'selectable' is enabled, this listener also detects selections. - var dragListener = new DragListener(this.coordMap, { - //distance: 5, // needs more work if we want dayClick to fire correctly - scroll: view.opt('dragScroll'), - dragStart: function() { - view.unselect(); // since we could be rendering a new selection, we want to clear any old one - }, - cellOver: function(cell, date) { - if (dragListener.origDate) { // click needs to have started on a cell - - dayEl = _this.getCellDayEl(cell); - - dates = [ date, dragListener.origDate ].sort(compareNumbers); // works with Moments - start = dates[0]; - end = dates[1].clone().add(_this.cellDuration); - - if (isSelectable) { - if (calendar.isSelectionAllowedInRange(start, end)) { // allowed to select within this range? - _this.renderSelection(start, end); - } - else { - dates = null; // flag for an invalid selection - disableCursor(); - } - } - } - }, - cellOut: function(cell, date) { - dates = null; - _this.destroySelection(); - enableCursor(); - }, - listenStop: function(ev) { - if (dates) { // started and ended on a cell? - if (dates[0].isSame(dates[1])) { - view.trigger('dayClick', dayEl[0], start, ev); - } - if (isSelectable) { - // the selection will already have been rendered. just report it - view.reportSelection(start, end, ev); - } - } - enableCursor(); - } - }); - - dragListener.mousedown(ev); // start listening, which will eventually initiate a dragStart - }, - - - /* Event Dragging - ------------------------------------------------------------------------------------------------------------------*/ - - - // Renders a visual indication of a event being dragged over the given date(s). - // `end` can be null, as well as `seg`. See View's documentation on renderDrag for more info. - // A returned value of `true` signals that a mock "helper" event has been rendered. - renderDrag: function(start, end, seg) { - // subclasses must implement - }, - - - // Unrenders a visual indication of an event being dragged - destroyDrag: function() { - // subclasses must implement - }, - - - /* Event Resizing - ------------------------------------------------------------------------------------------------------------------*/ - - - // Renders a visual indication of an event being resized. - // `start` and `end` are the updated dates of the event. `seg` is the original segment object involved in the drag. - renderResize: function(start, end, seg) { - // subclasses must implement - }, - - - // Unrenders a visual indication of an event being resized. - destroyResize: function() { - // subclasses must implement - }, - - - /* Event Helper - ------------------------------------------------------------------------------------------------------------------*/ - - - // Renders a mock event over the given date(s). - // `end` can be null, in which case the mock event that is rendered will have a null end time. - // `sourceSeg` is the internal segment object involved in the drag. If null, something external is dragging. - renderRangeHelper: function(start, end, sourceSeg) { - var view = this.view; - var fakeEvent; - - // compute the end time if forced to do so (this is what EventManager does) - if (!end && view.opt('forceEventDuration')) { - end = view.calendar.getDefaultEventEnd(!start.hasTime(), start); - } - - fakeEvent = sourceSeg ? createObject(sourceSeg.event) : {}; // mask the original event object if possible - fakeEvent.start = start; - fakeEvent.end = end; - fakeEvent.allDay = !(start.hasTime() || (end && end.hasTime())); // freshly compute allDay - - // this extra className will be useful for differentiating real events from mock events in CSS - fakeEvent.className = (fakeEvent.className || []).concat('fc-helper'); - - // if something external is being dragged in, don't render a resizer - if (!sourceSeg) { - fakeEvent.editable = false; - } - - this.renderHelper(fakeEvent, sourceSeg); // do the actual rendering - }, - - - // Renders a mock event - renderHelper: function(event, sourceSeg) { - // subclasses must implement - }, - - - // Unrenders a mock event - destroyHelper: function() { - // subclasses must implement - }, - - - /* Selection - ------------------------------------------------------------------------------------------------------------------*/ - - - // Renders a visual indication of a selection. Will highlight by default but can be overridden by subclasses. - renderSelection: function(start, end) { - this.renderHighlight(start, end); - }, - - - // Unrenders any visual indications of a selection. Will unrender a highlight by default. - destroySelection: function() { - this.destroyHighlight(); - }, - - - /* Highlight - ------------------------------------------------------------------------------------------------------------------*/ - - - // Renders an emphasis on the given date range. `start` is inclusive. `end` is exclusive. - renderHighlight: function(start, end) { - this.renderFill('highlight', this.rangeToSegs(start, end)); - }, - - - // Unrenders the emphasis on a date range - destroyHighlight: function() { - this.destroyFill('highlight'); - }, - - - // Generates an array of classNames for rendering the highlight. Used by the fill system. - highlightSegClasses: function() { - return [ 'fc-highlight' ]; - }, - - - /* Fill System (highlight, background events, business hours) - ------------------------------------------------------------------------------------------------------------------*/ - - - // Renders a set of rectangles over the given segments of time. - // Returns a subset of segs, the segs that were actually rendered. - // Responsible for populating this.elsByFill - renderFill: function(type, segs) { - // subclasses must implement - }, - - - // Unrenders a specific type of fill that is currently rendered on the grid - destroyFill: function(type) { - var el = this.elsByFill[type]; - - if (el) { - el.remove(); - delete this.elsByFill[type]; - } - }, - - - // Renders and assigns an `el` property for each fill segment. Generic enough to work with different types. - // Only returns segments that successfully rendered. - // To be harnessed by renderFill (implemented by subclasses). - // Analagous to renderFgSegEls. - renderFillSegEls: function(type, segs) { - var _this = this; - var segElMethod = this[type + 'SegEl']; - var html = ''; - var renderedSegs = []; - var i; - - if (segs.length) { - - // build a large concatenation of segment HTML - for (i = 0; i < segs.length; i++) { - html += this.fillSegHtml(type, segs[i]); - } - - // Grab individual elements from the combined HTML string. Use each as the default rendering. - // Then, compute the 'el' for each segment. - $(html).each(function(i, node) { - var seg = segs[i]; - var el = $(node); - - // allow custom filter methods per-type - if (segElMethod) { - el = segElMethod.call(_this, seg, el); - } - - if (el) { // custom filters did not cancel the render - el = $(el); // allow custom filter to return raw DOM node - - // correct element type? (would be bad if a non-TD were inserted into a table for example) - if (el.is(_this.fillSegTag)) { - seg.el = el; - renderedSegs.push(seg); - } - } - }); - } - - return renderedSegs; - }, - - - fillSegTag: 'div', // subclasses can override - - - // Builds the HTML needed for one fill segment. Generic enought o work with different types. - fillSegHtml: function(type, seg) { - var classesMethod = this[type + 'SegClasses']; // custom hooks per-type - var stylesMethod = this[type + 'SegStyles']; // - var classes = classesMethod ? classesMethod.call(this, seg) : []; - var styles = stylesMethod ? stylesMethod.call(this, seg) : ''; // a semi-colon separated CSS property string - - return '<' + this.fillSegTag + - (classes.length ? ' class="' + classes.join(' ') + '"' : '') + - (styles ? ' style="' + styles + '"' : '') + - ' />'; - }, - - - /* Generic rendering utilities for subclasses - ------------------------------------------------------------------------------------------------------------------*/ - - - // Renders a day-of-week header row - headHtml: function() { - return '' + - '
    ' + - '' + - '' + - this.rowHtml('head') + // leverages RowRenderer - '' + - '
    ' + - '
    '; - }, - - - // Used by the `headHtml` method, via RowRenderer, for rendering the HTML of a day-of-week header cell - headCellHtml: function(row, col, date) { - var view = this.view; - var calendar = view.calendar; - var colFormat = view.opt('columnFormat'); - - return '' + - '' + - htmlEscape(calendar.formatDate(date, colFormat)) + - ''; - }, - - - // Renders the HTML for a single-day background cell - bgCellHtml: function(row, col, date) { - var view = this.view; - var classes = this.getDayClasses(date); - - classes.unshift('fc-day', view.widgetContentClass); - - return ''; - }, - - - // Computes HTML classNames for a single-day cell - getDayClasses: function(date) { - var view = this.view; - var today = view.calendar.getNow().stripTime(); - var classes = [ 'fc-' + dayIDs[date.day()] ]; - - if ( - view.name === 'month' && - date.month() != view.intervalStart.month() - ) { - classes.push('fc-other-month'); - } - - if (date.isSame(today, 'day')) { - classes.push( - 'fc-today', - view.highlightStateClass - ); - } - else if (date < today) { - classes.push('fc-past'); - } - else { - classes.push('fc-future'); - } - - return classes; - } - -}); - -;; - -/* Event-rendering and event-interaction methods for the abstract Grid class -----------------------------------------------------------------------------------------------------------------------*/ - -$.extend(Grid.prototype, { - - mousedOverSeg: null, // the segment object the user's mouse is over. null if over nothing - isDraggingSeg: false, // is a segment being dragged? boolean - isResizingSeg: false, // is a segment being resized? boolean - segs: null, // the event segments currently rendered in the grid - - - // Renders the given events onto the grid - renderEvents: function(events) { - var segs = this.eventsToSegs(events); - var bgSegs = []; - var fgSegs = []; - var i, seg; - - for (i = 0; i < segs.length; i++) { - seg = segs[i]; - - if (isBgEvent(seg.event)) { - bgSegs.push(seg); - } - else { - fgSegs.push(seg); - } - } - - // Render each different type of segment. - // Each function may return a subset of the segs, segs that were actually rendered. - bgSegs = this.renderBgSegs(bgSegs) || bgSegs; - fgSegs = this.renderFgSegs(fgSegs) || fgSegs; - - this.segs = bgSegs.concat(fgSegs); - }, - - - // Unrenders all events currently rendered on the grid - destroyEvents: function() { - this.triggerSegMouseout(); // trigger an eventMouseout if user's mouse is over an event - - this.destroyFgSegs(); - this.destroyBgSegs(); - - this.segs = null; - }, - - - // Retrieves all rendered segment objects currently rendered on the grid - getSegs: function() { - return this.segs || []; - }, - - - /* Foreground Segment Rendering - ------------------------------------------------------------------------------------------------------------------*/ - - - // Renders foreground event segments onto the grid. May return a subset of segs that were rendered. - renderFgSegs: function(segs) { - // subclasses must implement - }, - - - // Unrenders all currently rendered foreground segments - destroyFgSegs: function() { - // subclasses must implement - }, - - - // Renders and assigns an `el` property for each foreground event segment. - // Only returns segments that successfully rendered. - // A utility that subclasses may use. - renderFgSegEls: function(segs, disableResizing) { - var view = this.view; - var html = ''; - var renderedSegs = []; - var i; - - if (segs.length) { // don't build an empty html string - - // build a large concatenation of event segment HTML - for (i = 0; i < segs.length; i++) { - html += this.fgSegHtml(segs[i], disableResizing); - } - - // Grab individual elements from the combined HTML string. Use each as the default rendering. - // Then, compute the 'el' for each segment. An el might be null if the eventRender callback returned false. - $(html).each(function(i, node) { - var seg = segs[i]; - var el = view.resolveEventEl(seg.event, $(node)); - - if (el) { - el.data('fc-seg', seg); // used by handlers - seg.el = el; - renderedSegs.push(seg); - } - }); - } - - return renderedSegs; - }, - - - // Generates the HTML for the default rendering of a foreground event segment. Used by renderFgSegEls() - fgSegHtml: function(seg, disableResizing) { - // subclasses should implement - }, - - - /* Background Segment Rendering - ------------------------------------------------------------------------------------------------------------------*/ - - - // Renders the given background event segments onto the grid. - // Returns a subset of the segs that were actually rendered. - renderBgSegs: function(segs) { - return this.renderFill('bgEvent', segs); - }, - - - // Unrenders all the currently rendered background event segments - destroyBgSegs: function() { - this.destroyFill('bgEvent'); - }, - - - // Renders a background event element, given the default rendering. Called by the fill system. - bgEventSegEl: function(seg, el) { - return this.view.resolveEventEl(seg.event, el); // will filter through eventRender - }, - - - // Generates an array of classNames to be used for the default rendering of a background event. - // Called by the fill system. - bgEventSegClasses: function(seg) { - var event = seg.event; - var source = event.source || {}; - - return [ 'fc-bgevent' ].concat( - event.className, - source.className || [] - ); - }, - - - // Generates a semicolon-separated CSS string to be used for the default rendering of a background event. - // Called by the fill system. - // TODO: consolidate with getEventSkinCss? - bgEventSegStyles: function(seg) { - var view = this.view; - var event = seg.event; - var source = event.source || {}; - var eventColor = event.color; - var sourceColor = source.color; - var optionColor = view.opt('eventColor'); - var backgroundColor = - event.backgroundColor || - eventColor || - source.backgroundColor || - sourceColor || - view.opt('eventBackgroundColor') || - optionColor; - - if (backgroundColor) { - return 'background-color:' + backgroundColor; - } - - return ''; - }, - - - // Generates an array of classNames to be used for the rendering business hours overlay. Called by the fill system. - businessHoursSegClasses: function(seg) { - return [ 'fc-nonbusiness', 'fc-bgevent' ]; - }, - - - /* Handlers - ------------------------------------------------------------------------------------------------------------------*/ - - - // Attaches event-element-related handlers to the container element and leverage bubbling - bindSegHandlers: function() { - var _this = this; - var view = this.view; - - $.each( - { - mouseenter: function(seg, ev) { - _this.triggerSegMouseover(seg, ev); - }, - mouseleave: function(seg, ev) { - _this.triggerSegMouseout(seg, ev); - }, - click: function(seg, ev) { - return view.trigger('eventClick', this, seg.event, ev); // can return `false` to cancel - }, - mousedown: function(seg, ev) { - if ($(ev.target).is('.fc-resizer') && view.isEventResizable(seg.event)) { - _this.segResizeMousedown(seg, ev); - } - else if (view.isEventDraggable(seg.event)) { - _this.segDragMousedown(seg, ev); - } - } - }, - function(name, func) { - // attach the handler to the container element and only listen for real event elements via bubbling - _this.el.on(name, '.fc-event-container > *', function(ev) { - var seg = $(this).data('fc-seg'); // grab segment data. put there by View::renderEvents - - // only call the handlers if there is not a drag/resize in progress - if (seg && !_this.isDraggingSeg && !_this.isResizingSeg) { - return func.call(this, seg, ev); // `this` will be the event element - } - }); - } - ); - }, - - - // Updates internal state and triggers handlers for when an event element is moused over - triggerSegMouseover: function(seg, ev) { - if (!this.mousedOverSeg) { - this.mousedOverSeg = seg; - this.view.trigger('eventMouseover', seg.el[0], seg.event, ev); - } - }, - - - // Updates internal state and triggers handlers for when an event element is moused out. - // Can be given no arguments, in which case it will mouseout the segment that was previously moused over. - triggerSegMouseout: function(seg, ev) { - ev = ev || {}; // if given no args, make a mock mouse event - - if (this.mousedOverSeg) { - seg = seg || this.mousedOverSeg; // if given no args, use the currently moused-over segment - this.mousedOverSeg = null; - this.view.trigger('eventMouseout', seg.el[0], seg.event, ev); - } - }, - - - /* Dragging - ------------------------------------------------------------------------------------------------------------------*/ - - - // Called when the user does a mousedown on an event, which might lead to dragging. - // Generic enough to work with any type of Grid. - segDragMousedown: function(seg, ev) { - var _this = this; - var view = this.view; - var calendar = view.calendar; - var el = seg.el; - var event = seg.event; - var newStart, newEnd; - - // A clone of the original element that will move with the mouse - var mouseFollower = new MouseFollower(seg.el, { - parentEl: view.el, - opacity: view.opt('dragOpacity'), - revertDuration: view.opt('dragRevertDuration'), - zIndex: 2 // one above the .fc-view - }); - - // Tracks mouse movement over the *view's* coordinate map. Allows dragging and dropping between subcomponents - // of the view. - var dragListener = new DragListener(view.coordMap, { - distance: 5, - scroll: view.opt('dragScroll'), - listenStart: function(ev) { - mouseFollower.hide(); // don't show until we know this is a real drag - mouseFollower.start(ev); - }, - dragStart: function(ev) { - _this.triggerSegMouseout(seg, ev); // ensure a mouseout on the manipulated event has been reported - _this.isDraggingSeg = true; - view.hideEvent(event); // hide all event segments. our mouseFollower will take over - view.trigger('eventDragStart', el[0], event, ev, {}); // last argument is jqui dummy - }, - cellOver: function(cell, date) { - var origDate = seg.cellDate || dragListener.origDate; - var res = _this.computeDraggedEventDates(seg, origDate, date); - newStart = res.start; - newEnd = res.end; - - if (calendar.isEventAllowedInRange(event, newStart, res.visibleEnd)) { // allowed to drop here? - if (view.renderDrag(newStart, newEnd, seg)) { // have the view render a visual indication - mouseFollower.hide(); // if the view is already using a mock event "helper", hide our own - } - else { - mouseFollower.show(); - } - } - else { - // have the helper follow the mouse (no snapping) with a warning-style cursor - newStart = null; // mark an invalid drop date - mouseFollower.show(); - disableCursor(); - } - }, - cellOut: function() { // called before mouse moves to a different cell OR moved out of all cells - newStart = null; - view.destroyDrag(); // unrender whatever was done in view.renderDrag - mouseFollower.show(); // show in case we are moving out of all cells - enableCursor(); - }, - dragStop: function(ev) { - var hasChanged = newStart && !newStart.isSame(event.start); - - // do revert animation if hasn't changed. calls a callback when finished (whether animation or not) - mouseFollower.stop(!hasChanged, function() { - _this.isDraggingSeg = false; - view.destroyDrag(); - view.showEvent(event); - view.trigger('eventDragStop', el[0], event, ev, {}); // last argument is jqui dummy - - if (hasChanged) { - view.eventDrop(el[0], event, newStart, ev); // will rerender all events... - } - }); - - enableCursor(); - }, - listenStop: function() { - mouseFollower.stop(); // put in listenStop in case there was a mousedown but the drag never started - } - }); - - dragListener.mousedown(ev); // start listening, which will eventually lead to a dragStart - }, - - - // Given a segment, the dates where a drag began and ended, calculates the Event Object's new start and end dates. - // Might return a `null` end (even when forceEventDuration is on). - computeDraggedEventDates: function(seg, dragStartDate, dropDate) { - var view = this.view; - var event = seg.event; - var start = event.start; - var end = view.calendar.getEventEnd(event); - var delta; - var newStart; - var newEnd; - var newAllDay; - var visibleEnd; - - if (dropDate.hasTime() === dragStartDate.hasTime()) { - delta = dayishDiff(dropDate, dragStartDate); - newStart = start.clone().add(delta); - if (event.end === null) { // do we need to compute an end? - newEnd = null; - } - else { - newEnd = end.clone().add(delta); - } - newAllDay = event.allDay; // keep it the same - } - else { - // if switching from day <-> timed, start should be reset to the dropped date, and the end cleared - newStart = dropDate; - newEnd = null; // end should be cleared - newAllDay = !dropDate.hasTime(); - } - - // compute what the end date will appear to be - visibleEnd = newEnd || view.calendar.getDefaultEventEnd(newAllDay, newStart); - - return { start: newStart, end: newEnd, visibleEnd: visibleEnd }; - }, - - - /* Resizing - ------------------------------------------------------------------------------------------------------------------*/ - - - // Called when the user does a mousedown on an event's resizer, which might lead to resizing. - // Generic enough to work with any type of Grid. - segResizeMousedown: function(seg, ev) { - var _this = this; - var view = this.view; - var calendar = view.calendar; - var el = seg.el; - var event = seg.event; - var start = event.start; - var end = view.calendar.getEventEnd(event); - var newEnd = null; - var dragListener; - - function destroy() { // resets the rendering to show the original event - _this.destroyResize(); - view.showEvent(event); - } - - // Tracks mouse movement over the *grid's* coordinate map - dragListener = new DragListener(this.coordMap, { - distance: 5, - scroll: view.opt('dragScroll'), - dragStart: function(ev) { - _this.triggerSegMouseout(seg, ev); // ensure a mouseout on the manipulated event has been reported - _this.isResizingSeg = true; - view.trigger('eventResizeStart', el[0], event, ev, {}); // last argument is jqui dummy - }, - cellOver: function(cell, date) { - // compute the new end. don't allow it to go before the event's start - if (date.isBefore(start)) { // allows comparing ambig to non-ambig - date = start; - } - newEnd = date.clone().add(_this.cellDuration); // make it an exclusive end - - if (calendar.isEventAllowedInRange(event, start, newEnd)) { // allowed to be resized here? - if (newEnd.isSame(end)) { - newEnd = null; // mark an invalid resize - destroy(); - } - else { - _this.renderResize(start, newEnd, seg); - view.hideEvent(event); - } - } - else { - newEnd = null; // mark an invalid resize - destroy(); - disableCursor(); - } - }, - cellOut: function() { // called before mouse moves to a different cell OR moved out of all cells - newEnd = null; - destroy(); - enableCursor(); - }, - dragStop: function(ev) { - _this.isResizingSeg = false; - destroy(); - enableCursor(); - view.trigger('eventResizeStop', el[0], event, ev, {}); // last argument is jqui dummy - - if (newEnd) { - view.eventResize(el[0], event, newEnd, ev); // will rerender all events... - } - } - }); - - dragListener.mousedown(ev); // start listening, which will eventually lead to a dragStart - }, - - - /* Rendering Utils - ------------------------------------------------------------------------------------------------------------------*/ - - - // Generic utility for generating the HTML classNames for an event segment's element - getSegClasses: function(seg, isDraggable, isResizable) { - var event = seg.event; - var classes = [ - 'fc-event', - seg.isStart ? 'fc-start' : 'fc-not-start', - seg.isEnd ? 'fc-end' : 'fc-not-end' - ].concat( - event.className, - event.source ? event.source.className : [] - ); - - if (isDraggable) { - classes.push('fc-draggable'); - } - if (isResizable) { - classes.push('fc-resizable'); - } - - return classes; - }, - - - // Utility for generating a CSS string with all the event skin-related properties - getEventSkinCss: function(event) { - var view = this.view; - var source = event.source || {}; - var eventColor = event.color; - var sourceColor = source.color; - var optionColor = view.opt('eventColor'); - var backgroundColor = - event.backgroundColor || - eventColor || - source.backgroundColor || - sourceColor || - view.opt('eventBackgroundColor') || - optionColor; - var borderColor = - event.borderColor || - eventColor || - source.borderColor || - sourceColor || - view.opt('eventBorderColor') || - optionColor; - var textColor = - event.textColor || - source.textColor || - view.opt('eventTextColor'); - var statements = []; - if (backgroundColor) { - statements.push('background-color:' + backgroundColor); - } - if (borderColor) { - statements.push('border-color:' + borderColor); - } - if (textColor) { - statements.push('color:' + textColor); - } - return statements.join(';'); - }, - - - /* Converting events -> ranges -> segs - ------------------------------------------------------------------------------------------------------------------*/ - - - // Converts an array of event objects into an array of event segment objects. - // A custom `rangeToSegsFunc` may be given for arbitrarily slicing up events. - eventsToSegs: function(events, rangeToSegsFunc) { - var eventRanges = this.eventsToRanges(events); - var segs = []; - var i; - - for (i = 0; i < eventRanges.length; i++) { - segs.push.apply( - segs, - this.eventRangeToSegs(eventRanges[i], rangeToSegsFunc) - ); - } - - return segs; - }, - - - // Converts an array of events into an array of "range" objects. - // A "range" object is a plain object with start/end properties denoting the time it covers. Also an event property. - // For "normal" events, this will be identical to the event's start/end, but for "inverse-background" events, - // will create an array of ranges that span the time *not* covered by the given event. - eventsToRanges: function(events) { - var _this = this; - var eventsById = groupEventsById(events); - var ranges = []; - - // group by ID so that related inverse-background events can be rendered together - $.each(eventsById, function(id, eventGroup) { - if (eventGroup.length) { - ranges.push.apply( - ranges, - isInverseBgEvent(eventGroup[0]) ? - _this.eventsToInverseRanges(eventGroup) : - _this.eventsToNormalRanges(eventGroup) - ); - } - }); - - return ranges; - }, - - - // Converts an array of "normal" events (not inverted rendering) into a parallel array of ranges - eventsToNormalRanges: function(events) { - var calendar = this.view.calendar; - var ranges = []; - var i, event; - var eventStart, eventEnd; - - for (i = 0; i < events.length; i++) { - event = events[i]; - - // make copies and normalize by stripping timezone - eventStart = event.start.clone().stripZone(); - eventEnd = calendar.getEventEnd(event).stripZone(); - - ranges.push({ - event: event, - start: eventStart, - end: eventEnd, - eventStartMS: +eventStart, - eventDurationMS: eventEnd - eventStart - }); - } - - return ranges; - }, - - - // Converts an array of events, with inverse-background rendering, into an array of range objects. - // The range objects will cover all the time NOT covered by the events. - eventsToInverseRanges: function(events) { - var view = this.view; - var viewStart = view.start.clone().stripZone(); // normalize timezone - var viewEnd = view.end.clone().stripZone(); // normalize timezone - var normalRanges = this.eventsToNormalRanges(events); // will give us normalized dates we can use w/o copies - var inverseRanges = []; - var event0 = events[0]; // assign this to each range's `.event` - var start = viewStart; // the end of the previous range. the start of the new range - var i, normalRange; - - // ranges need to be in order. required for our date-walking algorithm - normalRanges.sort(compareNormalRanges); - - for (i = 0; i < normalRanges.length; i++) { - normalRange = normalRanges[i]; - - // add the span of time before the event (if there is any) - if (normalRange.start > start) { // compare millisecond time (skip any ambig logic) - inverseRanges.push({ - event: event0, - start: start, - end: normalRange.start - }); - } - - start = normalRange.end; - } - - // add the span of time after the last event (if there is any) - if (start < viewEnd) { // compare millisecond time (skip any ambig logic) - inverseRanges.push({ - event: event0, - start: start, - end: viewEnd - }); - } - - return inverseRanges; - }, - - - // Slices the given event range into one or more segment objects. - // A `rangeToSegsFunc` custom slicing function can be given. - eventRangeToSegs: function(eventRange, rangeToSegsFunc) { - var segs; - var i, seg; - - if (rangeToSegsFunc) { - segs = rangeToSegsFunc(eventRange.start, eventRange.end); - } - else { - segs = this.rangeToSegs(eventRange.start, eventRange.end); // defined by the subclass - } - - for (i = 0; i < segs.length; i++) { - seg = segs[i]; - seg.event = eventRange.event; - seg.eventStartMS = eventRange.eventStartMS; - seg.eventDurationMS = eventRange.eventDurationMS; - } - - return segs; - } - -}); - - -/* Utilities -----------------------------------------------------------------------------------------------------------------------*/ - - -function isBgEvent(event) { // returns true if background OR inverse-background - var rendering = getEventRendering(event); - return rendering === 'background' || rendering === 'inverse-background'; -} - - -function isInverseBgEvent(event) { - return getEventRendering(event) === 'inverse-background'; -} - - -function getEventRendering(event) { - return firstDefined((event.source || {}).rendering, event.rendering); -} - - -function groupEventsById(events) { - var eventsById = {}; - var i, event; - - for (i = 0; i < events.length; i++) { - event = events[i]; - (eventsById[event._id] || (eventsById[event._id] = [])).push(event); - } - - return eventsById; -} - - -// A cmp function for determining which non-inverted "ranges" (see above) happen earlier -function compareNormalRanges(range1, range2) { - return range1.eventStartMS - range2.eventStartMS; // earlier ranges go first -} - - -// A cmp function for determining which segments should take visual priority -// DOES NOT WORK ON INVERTED BACKGROUND EVENTS because they have no eventStartMS/eventDurationMS -function compareSegs(seg1, seg2) { - return seg1.eventStartMS - seg2.eventStartMS || // earlier events go first - seg2.eventDurationMS - seg1.eventDurationMS || // tie? longer events go first - seg2.event.allDay - seg1.event.allDay || // tie? put all-day events first (booleans cast to 0/1) - (seg1.event.title || '').localeCompare(seg2.event.title); // tie? alphabetically by title -} - - -;; - -/* A component that renders a grid of whole-days that runs horizontally. There can be multiple rows, one per week. -----------------------------------------------------------------------------------------------------------------------*/ - -function DayGrid(view) { - Grid.call(this, view); // call the super-constructor -} - - -DayGrid.prototype = createObject(Grid.prototype); // declare the super-class -$.extend(DayGrid.prototype, { - - numbersVisible: false, // should render a row for day/week numbers? manually set by the view - cellDuration: moment.duration({ days: 1 }), // required for Grid.event.js. Each cell is always a single day - bottomCoordPadding: 0, // hack for extending the hit area for the last row of the coordinate grid - - rowEls: null, // set of fake row elements - dayEls: null, // set of whole-day elements comprising the row's background - helperEls: null, // set of cell skeleton elements for rendering the mock event "helper" - - - // Renders the rows and columns into the component's `this.el`, which should already be assigned. - // isRigid determins whether the individual rows should ignore the contents and be a constant height. - // Relies on the view's colCnt and rowCnt. In the future, this component should probably be self-sufficient. - render: function(isRigid) { - var view = this.view; - var html = ''; - var row; - - for (row = 0; row < view.rowCnt; row++) { - html += this.dayRowHtml(row, isRigid); - } - this.el.html(html); - - this.rowEls = this.el.find('.fc-row'); - this.dayEls = this.el.find('.fc-day'); - - // run all the day cells through the dayRender callback - this.dayEls.each(function(i, node) { - var date = view.cellToDate(Math.floor(i / view.colCnt), i % view.colCnt); - view.trigger('dayRender', null, date, $(node)); - }); - - Grid.prototype.render.call(this); // call the super-method - }, - - - destroy: function() { - this.destroySegPopover(); - }, - - - // Generates the HTML for a single row. `row` is the row number. - dayRowHtml: function(row, isRigid) { - var view = this.view; - var classes = [ 'fc-row', 'fc-week', view.widgetContentClass ]; - - if (isRigid) { - classes.push('fc-rigid'); - } - - return '' + - '
    ' + - '
    ' + - '' + - this.rowHtml('day', row) + // leverages RowRenderer. calls dayCellHtml() - '
    ' + - '
    ' + - '
    ' + - '' + - (this.numbersVisible ? - '' + - this.rowHtml('number', row) + // leverages RowRenderer. View will define render method - '' : - '' - ) + - '
    ' + - '
    ' + - '
    '; - }, - - - // Renders the HTML for a whole-day cell. Will eventually end up in the day-row's background. - // We go through a 'day' row type instead of just doing a 'bg' row type so that the View can do custom rendering - // specifically for whole-day rows, whereas a 'bg' might also be used for other purposes (TimeGrid bg for example). - dayCellHtml: function(row, col, date) { - return this.bgCellHtml(row, col, date); - }, - - - /* Coordinates & Cells - ------------------------------------------------------------------------------------------------------------------*/ - - - // Populates the empty `rows` and `cols` arrays with coordinates of the cells. For CoordGrid. - buildCoords: function(rows, cols) { - var colCnt = this.view.colCnt; - var e, n, p; - - this.dayEls.slice(0, colCnt).each(function(i, _e) { // iterate the first row of day elements - e = $(_e); - n = e.offset().left; - if (i) { - p[1] = n; - } - p = [ n ]; - cols[i] = p; - }); - p[1] = n + e.outerWidth(); - - this.rowEls.each(function(i, _e) { - e = $(_e); - n = e.offset().top; - if (i) { - p[1] = n; - } - p = [ n ]; - rows[i] = p; - }); - p[1] = n + e.outerHeight() + this.bottomCoordPadding; // hack to extend hit area of last row - }, - - - // Converts a cell to a date - getCellDate: function(cell) { - return this.view.cellToDate(cell); // leverages the View's cell system - }, - - - // Gets the whole-day element associated with the cell - getCellDayEl: function(cell) { - return this.dayEls.eq(cell.row * this.view.colCnt + cell.col); - }, - - - // Converts a range with an inclusive `start` and an exclusive `end` into an array of segment objects - rangeToSegs: function(start, end) { - return this.view.rangeToSegments(start, end); // leverages the View's cell system - }, - - - /* Event Drag Visualization - ------------------------------------------------------------------------------------------------------------------*/ - - - // Renders a visual indication of an event hovering over the given date(s). - // `end` can be null, as well as `seg`. See View's documentation on renderDrag for more info. - // A returned value of `true` signals that a mock "helper" event has been rendered. - renderDrag: function(start, end, seg) { - var opacity; - - // always render a highlight underneath - this.renderHighlight( - start, - end || this.view.calendar.getDefaultEventEnd(true, start) - ); - - // if a segment from the same calendar but another component is being dragged, render a helper event - if (seg && !seg.el.closest(this.el).length) { - - this.renderRangeHelper(start, end, seg); - - opacity = this.view.opt('dragOpacity'); - if (opacity !== undefined) { - this.helperEls.css('opacity', opacity); - } - - return true; // a helper has been rendered - } - }, - - - // Unrenders any visual indication of a hovering event - destroyDrag: function() { - this.destroyHighlight(); - this.destroyHelper(); - }, - - - /* Event Resize Visualization - ------------------------------------------------------------------------------------------------------------------*/ - - - // Renders a visual indication of an event being resized - renderResize: function(start, end, seg) { - this.renderHighlight(start, end); - this.renderRangeHelper(start, end, seg); - }, - - - // Unrenders a visual indication of an event being resized - destroyResize: function() { - this.destroyHighlight(); - this.destroyHelper(); - }, - - - /* Event Helper - ------------------------------------------------------------------------------------------------------------------*/ - - - // Renders a mock "helper" event. `sourceSeg` is the associated internal segment object. It can be null. - renderHelper: function(event, sourceSeg) { - var helperNodes = []; - var segs = this.eventsToSegs([ event ]); - var rowStructs; - - segs = this.renderFgSegEls(segs); // assigns each seg's el and returns a subset of segs that were rendered - rowStructs = this.renderSegRows(segs); - - // inject each new event skeleton into each associated row - this.rowEls.each(function(row, rowNode) { - var rowEl = $(rowNode); // the .fc-row - var skeletonEl = $('
    '); // will be absolutely positioned - var skeletonTop; - - // If there is an original segment, match the top position. Otherwise, put it at the row's top level - if (sourceSeg && sourceSeg.row === row) { - skeletonTop = sourceSeg.el.position().top; - } - else { - skeletonTop = rowEl.find('.fc-content-skeleton tbody').position().top; - } - - skeletonEl.css('top', skeletonTop) - .find('table') - .append(rowStructs[row].tbodyEl); - - rowEl.append(skeletonEl); - helperNodes.push(skeletonEl[0]); - }); - - this.helperEls = $(helperNodes); // array -> jQuery set - }, - - - // Unrenders any visual indication of a mock helper event - destroyHelper: function() { - if (this.helperEls) { - this.helperEls.remove(); - this.helperEls = null; - } - }, - - - /* Fill System (highlight, background events, business hours) - ------------------------------------------------------------------------------------------------------------------*/ - - - fillSegTag: 'td', // override the default tag name - - - // Renders a set of rectangles over the given segments of days. - // Only returns segments that successfully rendered. - renderFill: function(type, segs) { - var nodes = []; - var i, seg; - var skeletonEl; - - segs = this.renderFillSegEls(type, segs); // assignes `.el` to each seg. returns successfully rendered segs - - for (i = 0; i < segs.length; i++) { - seg = segs[i]; - skeletonEl = this.renderFillRow(type, seg); - this.rowEls.eq(seg.row).append(skeletonEl); - nodes.push(skeletonEl[0]); - } - - this.elsByFill[type] = $(nodes); - - return segs; - }, - - - // Generates the HTML needed for one row of a fill. Requires the seg's el to be rendered. - renderFillRow: function(type, seg) { - var colCnt = this.view.colCnt; - var startCol = seg.leftCol; - var endCol = seg.rightCol + 1; - var skeletonEl; - var trEl; - - skeletonEl = $( - '
    ' + - '
    ' + - '
    ' - ); - trEl = skeletonEl.find('tr'); - - if (startCol > 0) { - trEl.append(''); - } - - trEl.append( - seg.el.attr('colspan', endCol - startCol) - ); - - if (endCol < colCnt) { - trEl.append(''); - } - - this.bookendCells(trEl, type); - - return skeletonEl; - } - -}); - -;; - -/* Event-rendering methods for the DayGrid class -----------------------------------------------------------------------------------------------------------------------*/ - -$.extend(DayGrid.prototype, { - - rowStructs: null, // an array of objects, each holding information about a row's foreground event-rendering - - - // Unrenders all events currently rendered on the grid - destroyEvents: function() { - this.destroySegPopover(); // removes the "more.." events popover - Grid.prototype.destroyEvents.apply(this, arguments); // calls the super-method - }, - - - // Retrieves all rendered segment objects currently rendered on the grid - getSegs: function() { - return Grid.prototype.getSegs.call(this) // get the segments from the super-method - .concat(this.popoverSegs || []); // append the segments from the "more..." popover - }, - - - // Renders the given background event segments onto the grid - renderBgSegs: function(segs) { - - // don't render timed background events - var allDaySegs = $.grep(segs, function(seg) { - return seg.event.allDay; - }); - - return Grid.prototype.renderBgSegs.call(this, allDaySegs); // call the super-method - }, - - - // Renders the given foreground event segments onto the grid - renderFgSegs: function(segs) { - var rowStructs; - - // render an `.el` on each seg - // returns a subset of the segs. segs that were actually rendered - segs = this.renderFgSegEls(segs); - - rowStructs = this.rowStructs = this.renderSegRows(segs); - - // append to each row's content skeleton - this.rowEls.each(function(i, rowNode) { - $(rowNode).find('.fc-content-skeleton > table').append( - rowStructs[i].tbodyEl - ); - }); - - return segs; // return only the segs that were actually rendered - }, - - - // Unrenders all currently rendered foreground event segments - destroyFgSegs: function() { - var rowStructs = this.rowStructs || []; - var rowStruct; - - while ((rowStruct = rowStructs.pop())) { - rowStruct.tbodyEl.remove(); - } - - this.rowStructs = null; - }, - - - // Uses the given events array to generate elements that should be appended to each row's content skeleton. - // Returns an array of rowStruct objects (see the bottom of `renderSegRow`). - // PRECONDITION: each segment shoud already have a rendered and assigned `.el` - renderSegRows: function(segs) { - var rowStructs = []; - var segRows; - var row; - - segRows = this.groupSegRows(segs); // group into nested arrays - - // iterate each row of segment groupings - for (row = 0; row < segRows.length; row++) { - rowStructs.push( - this.renderSegRow(row, segRows[row]) - ); - } - - return rowStructs; - }, - - - // Builds the HTML to be used for the default element for an individual segment - fgSegHtml: function(seg, disableResizing) { - var view = this.view; - var isRTL = view.opt('isRTL'); - var event = seg.event; - var isDraggable = view.isEventDraggable(event); - var isResizable = !disableResizing && event.allDay && seg.isEnd && view.isEventResizable(event); - var classes = this.getSegClasses(seg, isDraggable, isResizable); - var skinCss = this.getEventSkinCss(event); - var timeHtml = ''; - var titleHtml; - - classes.unshift('fc-day-grid-event'); - - // Only display a timed events time if it is the starting segment - if (!event.allDay && seg.isStart) { - timeHtml = '' + htmlEscape(view.getEventTimeText(event)) + ''; - } - - titleHtml = - '' + - (htmlEscape(event.title || '') || ' ') + // we always want one line of height - ''; - - return '
    ' + - '
    ' + - (isRTL ? - titleHtml + ' ' + timeHtml : // put a natural space in between - timeHtml + ' ' + titleHtml // - ) + - '
    ' + - (isResizable ? - '
    ' : - '' - ) + - ''; - }, - - - // Given a row # and an array of segments all in the same row, render a element, a skeleton that contains - // the segments. Returns object with a bunch of internal data about how the render was calculated. - renderSegRow: function(row, rowSegs) { - var view = this.view; - var colCnt = view.colCnt; - var segLevels = this.buildSegLevels(rowSegs); // group into sub-arrays of levels - var levelCnt = Math.max(1, segLevels.length); // ensure at least one level - var tbody = $(''); - var segMatrix = []; // lookup for which segments are rendered into which level+col cells - var cellMatrix = []; // lookup for all elements of the level+col matrix - var loneCellMatrix = []; // lookup for elements that only take up a single column - var i, levelSegs; - var col; - var tr; - var j, seg; - var td; - - // populates empty cells from the current column (`col`) to `endCol` - function emptyCellsUntil(endCol) { - while (col < endCol) { - // try to grab a cell from the level above and extend its rowspan. otherwise, create a fresh cell - td = (loneCellMatrix[i - 1] || [])[col]; - if (td) { - td.attr( - 'rowspan', - parseInt(td.attr('rowspan') || 1, 10) + 1 - ); - } - else { - td = $(''); - tr.append(td); - } - cellMatrix[i][col] = td; - loneCellMatrix[i][col] = td; - col++; - } - } - - for (i = 0; i < levelCnt; i++) { // iterate through all levels - levelSegs = segLevels[i]; - col = 0; - tr = $(''); - - segMatrix.push([]); - cellMatrix.push([]); - loneCellMatrix.push([]); - - // levelCnt might be 1 even though there are no actual levels. protect against this. - // this single empty row is useful for styling. - if (levelSegs) { - for (j = 0; j < levelSegs.length; j++) { // iterate through segments in level - seg = levelSegs[j]; - - emptyCellsUntil(seg.leftCol); - - // create a container that occupies or more columns. append the event element. - td = $('').append(seg.el); - if (seg.leftCol != seg.rightCol) { - td.attr('colspan', seg.rightCol - seg.leftCol + 1); - } - else { // a single-column segment - loneCellMatrix[i][col] = td; - } - - while (col <= seg.rightCol) { - cellMatrix[i][col] = td; - segMatrix[i][col] = seg; - col++; - } - - tr.append(td); - } - } - - emptyCellsUntil(colCnt); // finish off the row - this.bookendCells(tr, 'eventSkeleton'); - tbody.append(tr); - } - - return { // a "rowStruct" - row: row, // the row number - tbodyEl: tbody, - cellMatrix: cellMatrix, - segMatrix: segMatrix, - segLevels: segLevels, - segs: rowSegs - }; - }, - - - // Stacks a flat array of segments, which are all assumed to be in the same row, into subarrays of vertical levels. - buildSegLevels: function(segs) { - var levels = []; - var i, seg; - var j; - - // Give preference to elements with certain criteria, so they have - // a chance to be closer to the top. - segs.sort(compareSegs); - - for (i = 0; i < segs.length; i++) { - seg = segs[i]; - - // loop through levels, starting with the topmost, until the segment doesn't collide with other segments - for (j = 0; j < levels.length; j++) { - if (!isDaySegCollision(seg, levels[j])) { - break; - } - } - // `j` now holds the desired subrow index - seg.level = j; - - // create new level array if needed and append segment - (levels[j] || (levels[j] = [])).push(seg); - } - - // order segments left-to-right. very important if calendar is RTL - for (j = 0; j < levels.length; j++) { - levels[j].sort(compareDaySegCols); - } - - return levels; - }, - - - // Given a flat array of segments, return an array of sub-arrays, grouped by each segment's row - groupSegRows: function(segs) { - var view = this.view; - var segRows = []; - var i; - - for (i = 0; i < view.rowCnt; i++) { - segRows.push([]); - } - - for (i = 0; i < segs.length; i++) { - segRows[segs[i].row].push(segs[i]); - } - - return segRows; - } - -}); - - -// Computes whether two segments' columns collide. They are assumed to be in the same row. -function isDaySegCollision(seg, otherSegs) { - var i, otherSeg; - - for (i = 0; i < otherSegs.length; i++) { - otherSeg = otherSegs[i]; - - if ( - otherSeg.leftCol <= seg.rightCol && - otherSeg.rightCol >= seg.leftCol - ) { - return true; - } - } - - return false; -} - - -// A cmp function for determining the leftmost event -function compareDaySegCols(a, b) { - return a.leftCol - b.leftCol; -} - -;; - -/* Methods relate to limiting the number events for a given day on a DayGrid -----------------------------------------------------------------------------------------------------------------------*/ -// NOTE: all the segs being passed around in here are foreground segs - -$.extend(DayGrid.prototype, { - - - segPopover: null, // the Popover that holds events that can't fit in a cell. null when not visible - popoverSegs: null, // an array of segment objects that the segPopover holds. null when not visible - - - destroySegPopover: function() { - if (this.segPopover) { - this.segPopover.hide(); // will trigger destruction of `segPopover` and `popoverSegs` - } - }, - - - // Limits the number of "levels" (vertically stacking layers of events) for each row of the grid. - // `levelLimit` can be false (don't limit), a number, or true (should be computed). - limitRows: function(levelLimit) { - var rowStructs = this.rowStructs || []; - var row; // row # - var rowLevelLimit; - - for (row = 0; row < rowStructs.length; row++) { - this.unlimitRow(row); - - if (!levelLimit) { - rowLevelLimit = false; - } - else if (typeof levelLimit === 'number') { - rowLevelLimit = levelLimit; - } - else { - rowLevelLimit = this.computeRowLevelLimit(row); - } - - if (rowLevelLimit !== false) { - this.limitRow(row, rowLevelLimit); - } - } - }, - - - // Computes the number of levels a row will accomodate without going outside its bounds. - // Assumes the row is "rigid" (maintains a constant height regardless of what is inside). - // `row` is the row number. - computeRowLevelLimit: function(row) { - var rowEl = this.rowEls.eq(row); // the containing "fake" row div - var rowHeight = rowEl.height(); // TODO: cache somehow? - var trEls = this.rowStructs[row].tbodyEl.children(); - var i, trEl; - - // Reveal one level at a time and stop when we find one out of bounds - for (i = 0; i < trEls.length; i++) { - trEl = trEls.eq(i).removeClass('fc-limited'); // get and reveal - if (trEl.position().top + trEl.outerHeight() > rowHeight) { - return i; - } - } - - return false; // should not limit at all - }, - - - // Limits the given grid row to the maximum number of levels and injects "more" links if necessary. - // `row` is the row number. - // `levelLimit` is a number for the maximum (inclusive) number of levels allowed. - limitRow: function(row, levelLimit) { - var _this = this; - var view = this.view; - var rowStruct = this.rowStructs[row]; - var moreNodes = []; // array of "more" links and DOM nodes - var col = 0; // col # - var cell; - var levelSegs; // array of segment objects in the last allowable level, ordered left-to-right - var cellMatrix; // a matrix (by level, then column) of all jQuery elements in the row - var limitedNodes; // array of temporarily hidden level and segment DOM nodes - var i, seg; - var segsBelow; // array of segment objects below `seg` in the current `col` - var totalSegsBelow; // total number of segments below `seg` in any of the columns `seg` occupies - var colSegsBelow; // array of segment arrays, below seg, one for each column (offset from segs's first column) - var td, rowspan; - var segMoreNodes; // array of "more" cells that will stand-in for the current seg's cell - var j; - var moreTd, moreWrap, moreLink; - - // Iterates through empty level cells and places "more" links inside if need be - function emptyCellsUntil(endCol) { // goes from current `col` to `endCol` - while (col < endCol) { - cell = { row: row, col: col }; - segsBelow = _this.getCellSegs(cell, levelLimit); - if (segsBelow.length) { - td = cellMatrix[levelLimit - 1][col]; - moreLink = _this.renderMoreLink(cell, segsBelow); - moreWrap = $('
    ').append(moreLink); - td.append(moreWrap); - moreNodes.push(moreWrap[0]); - } - col++; - } - } - - if (levelLimit && levelLimit < rowStruct.segLevels.length) { // is it actually over the limit? - levelSegs = rowStruct.segLevels[levelLimit - 1]; - cellMatrix = rowStruct.cellMatrix; - - limitedNodes = rowStruct.tbodyEl.children().slice(levelLimit) // get level elements past the limit - .addClass('fc-limited').get(); // hide elements and get a simple DOM-nodes array - - // iterate though segments in the last allowable level - for (i = 0; i < levelSegs.length; i++) { - seg = levelSegs[i]; - emptyCellsUntil(seg.leftCol); // process empty cells before the segment - - // determine *all* segments below `seg` that occupy the same columns - colSegsBelow = []; - totalSegsBelow = 0; - while (col <= seg.rightCol) { - cell = { row: row, col: col }; - segsBelow = this.getCellSegs(cell, levelLimit); - colSegsBelow.push(segsBelow); - totalSegsBelow += segsBelow.length; - col++; - } - - if (totalSegsBelow) { // do we need to replace this segment with one or many "more" links? - td = cellMatrix[levelLimit - 1][seg.leftCol]; // the segment's parent cell - rowspan = td.attr('rowspan') || 1; - segMoreNodes = []; - - // make a replacement for each column the segment occupies. will be one for each colspan - for (j = 0; j < colSegsBelow.length; j++) { - moreTd = $('').attr('rowspan', rowspan); - segsBelow = colSegsBelow[j]; - cell = { row: row, col: seg.leftCol + j }; - moreLink = this.renderMoreLink(cell, [ seg ].concat(segsBelow)); // count seg as hidden too - moreWrap = $('
    ').append(moreLink); - moreTd.append(moreWrap); - segMoreNodes.push(moreTd[0]); - moreNodes.push(moreTd[0]); - } - - td.addClass('fc-limited').after($(segMoreNodes)); // hide original and inject replacements - limitedNodes.push(td[0]); - } - } - - emptyCellsUntil(view.colCnt); // finish off the level - rowStruct.moreEls = $(moreNodes); // for easy undoing later - rowStruct.limitedEls = $(limitedNodes); // for easy undoing later - } - }, - - - // Reveals all levels and removes all "more"-related elements for a grid's row. - // `row` is a row number. - unlimitRow: function(row) { - var rowStruct = this.rowStructs[row]; - - if (rowStruct.moreEls) { - rowStruct.moreEls.remove(); - rowStruct.moreEls = null; - } - - if (rowStruct.limitedEls) { - rowStruct.limitedEls.removeClass('fc-limited'); - rowStruct.limitedEls = null; - } - }, - - - // Renders an element that represents hidden event element for a cell. - // Responsible for attaching click handler as well. - renderMoreLink: function(cell, hiddenSegs) { - var _this = this; - var view = this.view; - - return $('') - .text( - this.getMoreLinkText(hiddenSegs.length) - ) - .on('click', function(ev) { - var clickOption = view.opt('eventLimitClick'); - var date = view.cellToDate(cell); - var moreEl = $(this); - var dayEl = _this.getCellDayEl(cell); - var allSegs = _this.getCellSegs(cell); - - // rescope the segments to be within the cell's date - var reslicedAllSegs = _this.resliceDaySegs(allSegs, date); - var reslicedHiddenSegs = _this.resliceDaySegs(hiddenSegs, date); - - if (typeof clickOption === 'function') { - // the returned value can be an atomic option - clickOption = view.trigger('eventLimitClick', null, { - date: date, - dayEl: dayEl, - moreEl: moreEl, - segs: reslicedAllSegs, - hiddenSegs: reslicedHiddenSegs - }, ev); - } - - if (clickOption === 'popover') { - _this.showSegPopover(date, cell, moreEl, reslicedAllSegs); - } - else if (typeof clickOption === 'string') { // a view name - view.calendar.zoomTo(date, clickOption); - } - }); - }, - - - // Reveals the popover that displays all events within a cell - showSegPopover: function(date, cell, moreLink, segs) { - var _this = this; - var view = this.view; - var moreWrap = moreLink.parent(); // the
    wrapper around the - var topEl; // the element we want to match the top coordinate of - var options; - - if (view.rowCnt == 1) { - topEl = this.view.el; // will cause the popover to cover any sort of header - } - else { - topEl = this.rowEls.eq(cell.row); // will align with top of row - } - - options = { - className: 'fc-more-popover', - content: this.renderSegPopoverContent(date, segs), - parentEl: this.el, - top: topEl.offset().top, - autoHide: true, // when the user clicks elsewhere, hide the popover - viewportConstrain: view.opt('popoverViewportConstrain'), - hide: function() { - // destroy everything when the popover is hidden - _this.segPopover.destroy(); - _this.segPopover = null; - _this.popoverSegs = null; - } - }; - - // Determine horizontal coordinate. - // We use the moreWrap instead of the to avoid border confusion. - if (view.opt('isRTL')) { - options.right = moreWrap.offset().left + moreWrap.outerWidth() + 1; // +1 to be over cell border - } - else { - options.left = moreWrap.offset().left - 1; // -1 to be over cell border - } - - this.segPopover = new Popover(options); - this.segPopover.show(); - }, - - - // Builds the inner DOM contents of the segment popover - renderSegPopoverContent: function(date, segs) { - var view = this.view; - var isTheme = view.opt('theme'); - var title = date.format(view.opt('dayPopoverFormat')); - var content = $( - '
    ' + - '' + - '' + - htmlEscape(title) + - '' + - '
    ' + - '
    ' + - '
    ' + - '
    ' + - '
    ' - ); - var segContainer = content.find('.fc-event-container'); - var i; - - // render each seg's `el` and only return the visible segs - segs = this.renderFgSegEls(segs, true); // disableResizing=true - this.popoverSegs = segs; - - for (i = 0; i < segs.length; i++) { - - // because segments in the popover are not part of a grid coordinate system, provide a hint to any - // grids that want to do drag-n-drop about which cell it came from - segs[i].cellDate = date; - - segContainer.append(segs[i].el); - } - - return content; - }, - - - // Given the events within an array of segment objects, reslice them to be in a single day - resliceDaySegs: function(segs, dayDate) { - - // build an array of the original events - var events = $.map(segs, function(seg) { - return seg.event; - }); - - var dayStart = dayDate.clone().stripTime(); - var dayEnd = dayStart.clone().add(1, 'days'); - - // slice the events with a custom slicing function - return this.eventsToSegs( - events, - function(rangeStart, rangeEnd) { - var seg = intersectionToSeg(rangeStart, rangeEnd, dayStart, dayEnd); // if no intersection, undefined - return seg ? [ seg ] : []; // must return an array of segments - } - ); - }, - - - // Generates the text that should be inside a "more" link, given the number of events it represents - getMoreLinkText: function(num) { - var view = this.view; - var opt = view.opt('eventLimitText'); - - if (typeof opt === 'function') { - return opt(num); - } - else { - return '+' + num + ' ' + opt; - } - }, - - - // Returns segments within a given cell. - // If `startLevel` is specified, returns only events including and below that level. Otherwise returns all segs. - getCellSegs: function(cell, startLevel) { - var segMatrix = this.rowStructs[cell.row].segMatrix; - var level = startLevel || 0; - var segs = []; - var seg; - - while (level < segMatrix.length) { - seg = segMatrix[level][cell.col]; - if (seg) { - segs.push(seg); - } - level++; - } - - return segs; - } - -}); - -;; - -/* A component that renders one or more columns of vertical time slots -----------------------------------------------------------------------------------------------------------------------*/ - -function TimeGrid(view) { - Grid.call(this, view); // call the super-constructor -} - - -TimeGrid.prototype = createObject(Grid.prototype); // define the super-class -$.extend(TimeGrid.prototype, { - - slotDuration: null, // duration of a "slot", a distinct time segment on given day, visualized by lines - snapDuration: null, // granularity of time for dragging and selecting - - minTime: null, // Duration object that denotes the first visible time of any given day - maxTime: null, // Duration object that denotes the exclusive visible end time of any given day - - dayEls: null, // cells elements in the day-row background - slatEls: null, // elements running horizontally across all columns - - slatTops: null, // an array of top positions, relative to the container. last item holds bottom of last slot - - helperEl: null, // cell skeleton element for rendering the mock event "helper" - - businessHourSegs: null, - - - // Renders the time grid into `this.el`, which should already be assigned. - // Relies on the view's colCnt. In the future, this component should probably be self-sufficient. - render: function() { - this.processOptions(); - - this.el.html(this.renderHtml()); - - this.dayEls = this.el.find('.fc-day'); - this.slatEls = this.el.find('.fc-slats tr'); - - this.computeSlatTops(); - - this.renderBusinessHours(); - - Grid.prototype.render.call(this); // call the super-method - }, - - - renderBusinessHours: function() { - var events = this.view.calendar.getBusinessHoursEvents(); - this.businessHourSegs = this.renderFill('businessHours', this.eventsToSegs(events), 'bgevent'); - }, - - - // Renders the basic HTML skeleton for the grid - renderHtml: function() { - return '' + - '
    ' + - '' + - this.rowHtml('slotBg') + // leverages RowRenderer, which will call slotBgCellHtml - '
    ' + - '
    ' + - '
    ' + - '' + - this.slatRowHtml() + - '
    ' + - '
    '; - }, - - - // Renders the HTML for a vertical background cell behind the slots. - // This method is distinct from 'bg' because we wanted a new `rowType` so the View could customize the rendering. - slotBgCellHtml: function(row, col, date) { - return this.bgCellHtml(row, col, date); - }, - - - // Generates the HTML for the horizontal "slats" that run width-wise. Has a time axis on a side. Depends on RTL. - slatRowHtml: function() { - var view = this.view; - var calendar = view.calendar; - var isRTL = view.opt('isRTL'); - var html = ''; - var slotNormal = this.slotDuration.asMinutes() % 15 === 0; - var slotTime = moment.duration(+this.minTime); // wish there was .clone() for durations - var slotDate; // will be on the view's first day, but we only care about its time - var minutes; - var axisHtml; - - // Calculate the time for each slot - while (slotTime < this.maxTime) { - slotDate = view.start.clone().time(slotTime); // will be in UTC but that's good. to avoid DST issues - minutes = slotDate.minutes(); - - axisHtml = - '' + - ((!slotNormal || !minutes) ? // if irregular slot duration, or on the hour, then display the time - '' + // for matchCellWidths - htmlEscape(calendar.formatDate(slotDate, view.opt('axisFormat'))) + - '' : - '' - ) + - ''; - - html += - '' + - (!isRTL ? axisHtml : '') + - '' + - (isRTL ? axisHtml : '') + - ""; - - slotTime.add(this.slotDuration); - } - - return html; - }, - - - // Parses various options into properties of this object - processOptions: function() { - var view = this.view; - var slotDuration = view.opt('slotDuration'); - var snapDuration = view.opt('snapDuration'); - - slotDuration = moment.duration(slotDuration); - snapDuration = snapDuration ? moment.duration(snapDuration) : slotDuration; - - this.slotDuration = slotDuration; - this.snapDuration = snapDuration; - this.cellDuration = snapDuration; // important to assign this for Grid.events.js - - this.minTime = moment.duration(view.opt('minTime')); - this.maxTime = moment.duration(view.opt('maxTime')); - }, - - - // Slices up a date range into a segment for each column - rangeToSegs: function(rangeStart, rangeEnd) { - var view = this.view; - var segs = []; - var seg; - var col; - var cellDate; - var colStart, colEnd; - - // normalize - rangeStart = rangeStart.clone().stripZone(); - rangeEnd = rangeEnd.clone().stripZone(); - - for (col = 0; col < view.colCnt; col++) { - cellDate = view.cellToDate(0, col); // use the View's cell system for this - colStart = cellDate.clone().time(this.minTime); - colEnd = cellDate.clone().time(this.maxTime); - seg = intersectionToSeg(rangeStart, rangeEnd, colStart, colEnd); - if (seg) { - seg.col = col; - segs.push(seg); - } - } - - return segs; - }, - - - /* Coordinates - ------------------------------------------------------------------------------------------------------------------*/ - - - // Called when there is a window resize/zoom and we need to recalculate coordinates for the grid - resize: function() { - this.computeSlatTops(); - this.updateSegVerticals(); - }, - - - // Populates the given empty `rows` and `cols` arrays with offset positions of the "snap" cells. - // "Snap" cells are different the slots because they might have finer granularity. - buildCoords: function(rows, cols) { - var colCnt = this.view.colCnt; - var originTop = this.el.offset().top; - var snapTime = moment.duration(+this.minTime); - var p = null; - var e, n; - - this.dayEls.slice(0, colCnt).each(function(i, _e) { - e = $(_e); - n = e.offset().left; - if (p) { - p[1] = n; - } - p = [ n ]; - cols[i] = p; - }); - p[1] = n + e.outerWidth(); - - p = null; - while (snapTime < this.maxTime) { - n = originTop + this.computeTimeTop(snapTime); - if (p) { - p[1] = n; - } - p = [ n ]; - rows.push(p); - snapTime.add(this.snapDuration); - } - p[1] = originTop + this.computeTimeTop(snapTime); // the position of the exclusive end - }, - - - // Gets the datetime for the given slot cell - getCellDate: function(cell) { - var view = this.view; - var calendar = view.calendar; - - return calendar.rezoneDate( // since we are adding a time, it needs to be in the calendar's timezone - view.cellToDate(0, cell.col) // View's coord system only accounts for start-of-day for column - .time(this.minTime + this.snapDuration * cell.row) - ); - }, - - - // Gets the element that represents the whole-day the cell resides on - getCellDayEl: function(cell) { - return this.dayEls.eq(cell.col); - }, - - - // Computes the top coordinate, relative to the bounds of the grid, of the given date. - // A `startOfDayDate` must be given for avoiding ambiguity over how to treat midnight. - computeDateTop: function(date, startOfDayDate) { - return this.computeTimeTop( - moment.duration( - date.clone().stripZone() - startOfDayDate.clone().stripTime() - ) - ); - }, - - - // Computes the top coordinate, relative to the bounds of the grid, of the given time (a Duration). - computeTimeTop: function(time) { - var slatCoverage = (time - this.minTime) / this.slotDuration; // floating-point value of # of slots covered - var slatIndex; - var slatRemainder; - var slatTop; - var slatBottom; - - // constrain. because minTime/maxTime might be customized - slatCoverage = Math.max(0, slatCoverage); - slatCoverage = Math.min(this.slatEls.length, slatCoverage); - - slatIndex = Math.floor(slatCoverage); // an integer index of the furthest whole slot - slatRemainder = slatCoverage - slatIndex; - slatTop = this.slatTops[slatIndex]; // the top position of the furthest whole slot - - if (slatRemainder) { // time spans part-way into the slot - slatBottom = this.slatTops[slatIndex + 1]; - return slatTop + (slatBottom - slatTop) * slatRemainder; // part-way between slots - } - else { - return slatTop; - } - }, - - - // Queries each `slatEl` for its position relative to the grid's container and stores it in `slatTops`. - // Includes the the bottom of the last slat as the last item in the array. - computeSlatTops: function() { - var tops = []; - var top; - - this.slatEls.each(function(i, node) { - top = $(node).position().top; - tops.push(top); - }); - - tops.push(top + this.slatEls.last().outerHeight()); // bottom of the last slat - - this.slatTops = tops; - }, - - - /* Event Drag Visualization - ------------------------------------------------------------------------------------------------------------------*/ - - - // Renders a visual indication of an event being dragged over the specified date(s). - // `end` and `seg` can be null. See View's documentation on renderDrag for more info. - renderDrag: function(start, end, seg) { - var opacity; - - if (seg) { // if there is event information for this drag, render a helper event - this.renderRangeHelper(start, end, seg); - - opacity = this.view.opt('dragOpacity'); - if (opacity !== undefined) { - this.helperEl.css('opacity', opacity); - } - - return true; // signal that a helper has been rendered - } - else { - // otherwise, just render a highlight - this.renderHighlight( - start, - end || this.view.calendar.getDefaultEventEnd(false, start) - ); - } - }, - - - // Unrenders any visual indication of an event being dragged - destroyDrag: function() { - this.destroyHelper(); - this.destroyHighlight(); - }, - - - /* Event Resize Visualization - ------------------------------------------------------------------------------------------------------------------*/ - - - // Renders a visual indication of an event being resized - renderResize: function(start, end, seg) { - this.renderRangeHelper(start, end, seg); - }, - - - // Unrenders any visual indication of an event being resized - destroyResize: function() { - this.destroyHelper(); - }, - - - /* Event Helper - ------------------------------------------------------------------------------------------------------------------*/ - - - // Renders a mock "helper" event. `sourceSeg` is the original segment object and might be null (an external drag) - renderHelper: function(event, sourceSeg) { - var segs = this.eventsToSegs([ event ]); - var tableEl; - var i, seg; - var sourceEl; - - segs = this.renderFgSegEls(segs); // assigns each seg's el and returns a subset of segs that were rendered - tableEl = this.renderSegTable(segs); - - // Try to make the segment that is in the same row as sourceSeg look the same - for (i = 0; i < segs.length; i++) { - seg = segs[i]; - if (sourceSeg && sourceSeg.col === seg.col) { - sourceEl = sourceSeg.el; - seg.el.css({ - left: sourceEl.css('left'), - right: sourceEl.css('right'), - 'margin-left': sourceEl.css('margin-left'), - 'margin-right': sourceEl.css('margin-right') - }); - } - } - - this.helperEl = $('
    ') - .append(tableEl) - .appendTo(this.el); - }, - - - // Unrenders any mock helper event - destroyHelper: function() { - if (this.helperEl) { - this.helperEl.remove(); - this.helperEl = null; - } - }, - - - /* Selection - ------------------------------------------------------------------------------------------------------------------*/ - - - // Renders a visual indication of a selection. Overrides the default, which was to simply render a highlight. - renderSelection: function(start, end) { - if (this.view.opt('selectHelper')) { // this setting signals that a mock helper event should be rendered - this.renderRangeHelper(start, end); - } - else { - this.renderHighlight(start, end); - } - }, - - - // Unrenders any visual indication of a selection - destroySelection: function() { - this.destroyHelper(); - this.destroyHighlight(); - }, - - - /* Fill System (highlight, background events, business hours) - ------------------------------------------------------------------------------------------------------------------*/ - - - // Renders a set of rectangles over the given time segments. - // Only returns segments that successfully rendered. - renderFill: function(type, segs, className) { - var view = this.view; - var segCols; - var skeletonEl; - var trEl; - var col, colSegs; - var tdEl; - var containerEl; - var dayDate; - var i, seg; - - if (segs.length) { - - segs = this.renderFillSegEls(type, segs); // assignes `.el` to each seg. returns successfully rendered segs - segCols = this.groupSegCols(segs); // group into sub-arrays, and assigns 'col' to each seg - - className = className || type.toLowerCase(); - skeletonEl = $( - '
    ' + - '
    ' + - '
    ' - ); - trEl = skeletonEl.find('tr'); - - for (col = 0; col < segCols.length; col++) { - colSegs = segCols[col]; - tdEl = $('').appendTo(trEl); - - if (colSegs.length) { - containerEl = $('
    ').appendTo(tdEl); - dayDate = view.cellToDate(0, col); - - for (i = 0; i < colSegs.length; i++) { - seg = colSegs[i]; - containerEl.append( - seg.el.css({ - top: this.computeDateTop(seg.start, dayDate), - bottom: -this.computeDateTop(seg.end, dayDate) // the y position of the bottom edge - }) - ); - } - } - } - - this.bookendCells(trEl, type); - - this.el.append(skeletonEl); - this.elsByFill[type] = skeletonEl; - } - - return segs; - } - -}); - -;; - -/* Event-rendering methods for the TimeGrid class -----------------------------------------------------------------------------------------------------------------------*/ - -$.extend(TimeGrid.prototype, { - - eventSkeletonEl: null, // has cells with event-containers, which contain absolutely positioned event elements - - - // Renders the given foreground event segments onto the grid - renderFgSegs: function(segs) { - segs = this.renderFgSegEls(segs); // returns a subset of the segs. segs that were actually rendered - - this.el.append( - this.eventSkeletonEl = $('
    ') - .append(this.renderSegTable(segs)) - ); - - return segs; // return only the segs that were actually rendered - }, - - - // Unrenders all currently rendered foreground event segments - destroyFgSegs: function(segs) { - if (this.eventSkeletonEl) { - this.eventSkeletonEl.remove(); - this.eventSkeletonEl = null; - } - }, - - - // Renders and returns the portion of the event-skeleton. - // Returns an object with properties 'tbodyEl' and 'segs'. - renderSegTable: function(segs) { - var tableEl = $('
    '); - var trEl = tableEl.find('tr'); - var segCols; - var i, seg; - var col, colSegs; - var containerEl; - - segCols = this.groupSegCols(segs); // group into sub-arrays, and assigns 'col' to each seg - - this.computeSegVerticals(segs); // compute and assign top/bottom - - for (col = 0; col < segCols.length; col++) { // iterate each column grouping - colSegs = segCols[col]; - placeSlotSegs(colSegs); // compute horizontal coordinates, z-index's, and reorder the array - - containerEl = $('
    '); - - // assign positioning CSS and insert into container - for (i = 0; i < colSegs.length; i++) { - seg = colSegs[i]; - seg.el.css(this.generateSegPositionCss(seg)); - - // if the height is short, add a className for alternate styling - if (seg.bottom - seg.top < 30) { - seg.el.addClass('fc-short'); - } - - containerEl.append(seg.el); - } - - trEl.append($('').append(containerEl)); - } - - this.bookendCells(trEl, 'eventSkeleton'); - - return tableEl; - }, - - - // Refreshes the CSS top/bottom coordinates for each segment element. Probably after a window resize/zoom. - // Repositions business hours segs too, so not just for events. Maybe shouldn't be here. - updateSegVerticals: function() { - var allSegs = (this.segs || []).concat(this.businessHourSegs || []); - var i; - - this.computeSegVerticals(allSegs); - - for (i = 0; i < allSegs.length; i++) { - allSegs[i].el.css( - this.generateSegVerticalCss(allSegs[i]) - ); - } - }, - - - // For each segment in an array, computes and assigns its top and bottom properties - computeSegVerticals: function(segs) { - var i, seg; - - for (i = 0; i < segs.length; i++) { - seg = segs[i]; - seg.top = this.computeDateTop(seg.start, seg.start); - seg.bottom = this.computeDateTop(seg.end, seg.start); - } - }, - - - // Renders the HTML for a single event segment's default rendering - fgSegHtml: function(seg, disableResizing) { - var view = this.view; - var event = seg.event; - var isDraggable = view.isEventDraggable(event); - var isResizable = !disableResizing && seg.isEnd && view.isEventResizable(event); - var classes = this.getSegClasses(seg, isDraggable, isResizable); - var skinCss = this.getEventSkinCss(event); - var timeText; - var fullTimeText; // more verbose time text. for the print stylesheet - var startTimeText; // just the start time text - - classes.unshift('fc-time-grid-event'); - - if (view.isMultiDayEvent(event)) { // if the event appears to span more than one day... - // Don't display time text on segments that run entirely through a day. - // That would appear as midnight-midnight and would look dumb. - // Otherwise, display the time text for the *segment's* times (like 6pm-midnight or midnight-10am) - if (seg.isStart || seg.isEnd) { - timeText = view.getEventTimeText(seg.start, seg.end); - fullTimeText = view.getEventTimeText(seg.start, seg.end, 'LT'); - startTimeText = view.getEventTimeText(seg.start, null); - } - } else { - // Display the normal time text for the *event's* times - timeText = view.getEventTimeText(event); - fullTimeText = view.getEventTimeText(event, 'LT'); - startTimeText = view.getEventTimeText(event.start, null); - } - - return '' + - '
    ' + - (timeText ? - '
    ' + - '' + htmlEscape(timeText) + '' + - '
    ' : - '' - ) + - (event.title ? - '
    ' + - htmlEscape(event.title) + - '
    ' : - '' - ) + - '
    ' + - '
    ' + - (isResizable ? - '
    ' : - '' - ) + - ''; - }, - - - // Generates an object with CSS properties/values that should be applied to an event segment element. - // Contains important positioning-related properties that should be applied to any event element, customized or not. - generateSegPositionCss: function(seg) { - var view = this.view; - var isRTL = view.opt('isRTL'); - var shouldOverlap = view.opt('slotEventOverlap'); - var backwardCoord = seg.backwardCoord; // the left side if LTR. the right side if RTL. floating-point - var forwardCoord = seg.forwardCoord; // the right side if LTR. the left side if RTL. floating-point - var props = this.generateSegVerticalCss(seg); // get top/bottom first - var left; // amount of space from left edge, a fraction of the total width - var right; // amount of space from right edge, a fraction of the total width - - if (shouldOverlap) { - // double the width, but don't go beyond the maximum forward coordinate (1.0) - forwardCoord = Math.min(1, backwardCoord + (forwardCoord - backwardCoord) * 2); - } - - if (isRTL) { - left = 1 - forwardCoord; - right = backwardCoord; - } - else { - left = backwardCoord; - right = 1 - forwardCoord; - } - - props.zIndex = seg.level + 1; // convert from 0-base to 1-based - props.left = left * 100 + '%'; - props.right = right * 100 + '%'; - - if (shouldOverlap && seg.forwardPressure) { - // add padding to the edge so that forward stacked events don't cover the resizer's icon - props[isRTL ? 'marginLeft' : 'marginRight'] = 10 * 2; // 10 is a guesstimate of the icon's width - } - - return props; - }, - - - // Generates an object with CSS properties for the top/bottom coordinates of a segment element - generateSegVerticalCss: function(seg) { - return { - top: seg.top, - bottom: -seg.bottom // flipped because needs to be space beyond bottom edge of event container - }; - }, - - - // Given a flat array of segments, return an array of sub-arrays, grouped by each segment's col - groupSegCols: function(segs) { - var view = this.view; - var segCols = []; - var i; - - for (i = 0; i < view.colCnt; i++) { - segCols.push([]); - } - - for (i = 0; i < segs.length; i++) { - segCols[segs[i].col].push(segs[i]); - } - - return segCols; - } - -}); - - -// Given an array of segments that are all in the same column, sets the backwardCoord and forwardCoord on each. -// Also reorders the given array by date! -function placeSlotSegs(segs) { - var levels; - var level0; - var i; - - segs.sort(compareSegs); // order by date - levels = buildSlotSegLevels(segs); - computeForwardSlotSegs(levels); - - if ((level0 = levels[0])) { - - for (i = 0; i < level0.length; i++) { - computeSlotSegPressures(level0[i]); - } - - for (i = 0; i < level0.length; i++) { - computeSlotSegCoords(level0[i], 0, 0); - } - } -} - - -// Builds an array of segments "levels". The first level will be the leftmost tier of segments if the calendar is -// left-to-right, or the rightmost if the calendar is right-to-left. Assumes the segments are already ordered by date. -function buildSlotSegLevels(segs) { - var levels = []; - var i, seg; - var j; - - for (i=0; i seg2.top && seg1.top < seg2.bottom; -} - - -// A cmp function for determining which forward segment to rely on more when computing coordinates. -function compareForwardSlotSegs(seg1, seg2) { - // put higher-pressure first - return seg2.forwardPressure - seg1.forwardPressure || - // put segments that are closer to initial edge first (and favor ones with no coords yet) - (seg1.backwardCoord || 0) - (seg2.backwardCoord || 0) || - // do normal sorting... - compareSegs(seg1, seg2); -} - -;; - -/* An abstract class from which other views inherit from -----------------------------------------------------------------------------------------------------------------------*/ -// Newer methods should be written as prototype methods, not in the monster `View` function at the bottom. - -View.prototype = { - - calendar: null, // owner Calendar object - coordMap: null, // a CoordMap object for converting pixel regions to dates - el: null, // the view's containing element. set by Calendar - - // important Moments - start: null, // the date of the very first cell - end: null, // the date after the very last cell - intervalStart: null, // the start of the interval of time the view represents (1st of month for month view) - intervalEnd: null, // the exclusive end of the interval of time the view represents - - // used for cell-to-date and date-to-cell calculations - rowCnt: null, // # of weeks - colCnt: null, // # of days displayed in a week - - isSelected: false, // boolean whether cells are user-selected or not - - // subclasses can optionally use a scroll container - scrollerEl: null, // the element that will most likely scroll when content is too tall - scrollTop: null, // cached vertical scroll value - - // classNames styled by jqui themes - widgetHeaderClass: null, - widgetContentClass: null, - highlightStateClass: null, - - // document handlers, bound to `this` object - documentMousedownProxy: null, - documentDragStartProxy: null, - - - // Serves as a "constructor" to suppliment the monster `View` constructor below - init: function() { - var tm = this.opt('theme') ? 'ui' : 'fc'; - - this.widgetHeaderClass = tm + '-widget-header'; - this.widgetContentClass = tm + '-widget-content'; - this.highlightStateClass = tm + '-state-highlight'; - - // save references to `this`-bound handlers - this.documentMousedownProxy = $.proxy(this, 'documentMousedown'); - this.documentDragStartProxy = $.proxy(this, 'documentDragStart'); - }, - - - // Renders the view inside an already-defined `this.el`. - // Subclasses should override this and then call the super method afterwards. - render: function() { - this.updateSize(); - this.trigger('viewRender', this, this, this.el); - - // attach handlers to document. do it here to allow for destroy/rerender - $(document) - .on('mousedown', this.documentMousedownProxy) - .on('dragstart', this.documentDragStartProxy); // jqui drag - }, - - - // Clears all view rendering, event elements, and unregisters handlers - destroy: function() { - this.unselect(); - this.trigger('viewDestroy', this, this, this.el); - this.destroyEvents(); - this.el.empty(); // removes inner contents but leaves the element intact - - $(document) - .off('mousedown', this.documentMousedownProxy) - .off('dragstart', this.documentDragStartProxy); - }, - - - // Used to determine what happens when the users clicks next/prev. Given -1 for prev, 1 for next. - // Should apply the delta to `date` (a Moment) and return it. - incrementDate: function(date, delta) { - // subclasses should implement - }, - - - /* Dimensions - ------------------------------------------------------------------------------------------------------------------*/ - - - // Refreshes anything dependant upon sizing of the container element of the grid - updateSize: function(isResize) { - if (isResize) { - this.recordScroll(); - } - this.updateHeight(); - this.updateWidth(); - }, - - - // Refreshes the horizontal dimensions of the calendar - updateWidth: function() { - // subclasses should implement - }, - - - // Refreshes the vertical dimensions of the calendar - updateHeight: function() { - var calendar = this.calendar; // we poll the calendar for height information - - this.setHeight( - calendar.getSuggestedViewHeight(), - calendar.isHeightAuto() - ); - }, - - - // Updates the vertical dimensions of the calendar to the specified height. - // if `isAuto` is set to true, height becomes merely a suggestion and the view should use its "natural" height. - setHeight: function(height, isAuto) { - // subclasses should implement - }, - - - // Given the total height of the view, return the number of pixels that should be used for the scroller. - // Utility for subclasses. - computeScrollerHeight: function(totalHeight) { - var both = this.el.add(this.scrollerEl); - var otherHeight; // cumulative height of everything that is not the scrollerEl in the view (header+borders) - - // fuckin IE8/9/10/11 sometimes returns 0 for dimensions. this weird hack was the only thing that worked - both.css({ - position: 'relative', // cause a reflow, which will force fresh dimension recalculation - left: -1 // ensure reflow in case the el was already relative. negative is less likely to cause new scroll - }); - otherHeight = this.el.outerHeight() - this.scrollerEl.height(); // grab the dimensions - both.css({ position: '', left: '' }); // undo hack - - return totalHeight - otherHeight; - }, - - - // Called for remembering the current scroll value of the scroller. - // Should be called before there is a destructive operation (like removing DOM elements) that might inadvertently - // change the scroll of the container. - recordScroll: function() { - if (this.scrollerEl) { - this.scrollTop = this.scrollerEl.scrollTop(); - } - }, - - - // Set the scroll value of the scroller to the previously recorded value. - // Should be called after we know the view's dimensions have been restored following some type of destructive - // operation (like temporarily removing DOM elements). - restoreScroll: function() { - if (this.scrollTop !== null) { - this.scrollerEl.scrollTop(this.scrollTop); - } - }, - - - /* Events - ------------------------------------------------------------------------------------------------------------------*/ - - - // Renders the events onto the view. - // Should be overriden by subclasses. Subclasses should call the super-method afterwards. - renderEvents: function(events) { - this.segEach(function(seg) { - this.trigger('eventAfterRender', seg.event, seg.event, seg.el); - }); - this.trigger('eventAfterAllRender'); - }, - - - // Removes event elements from the view. - // Should be overridden by subclasses. Should call this super-method FIRST, then subclass DOM destruction. - destroyEvents: function() { - this.segEach(function(seg) { - this.trigger('eventDestroy', seg.event, seg.event, seg.el); - }); - }, - - - // Given an event and the default element used for rendering, returns the element that should actually be used. - // Basically runs events and elements through the eventRender hook. - resolveEventEl: function(event, el) { - var custom = this.trigger('eventRender', event, event, el); - - if (custom === false) { // means don't render at all - el = null; - } - else if (custom && custom !== true) { - el = $(custom); - } - - return el; - }, - - - // Hides all rendered event segments linked to the given event - showEvent: function(event) { - this.segEach(function(seg) { - seg.el.css('visibility', ''); - }, event); - }, - - - // Shows all rendered event segments linked to the given event - hideEvent: function(event) { - this.segEach(function(seg) { - seg.el.css('visibility', 'hidden'); - }, event); - }, - - - // Iterates through event segments. Goes through all by default. - // If the optional `event` argument is specified, only iterates through segments linked to that event. - // The `this` value of the callback function will be the view. - segEach: function(func, event) { - var segs = this.getSegs(); - var i; - - for (i = 0; i < segs.length; i++) { - if (!event || segs[i].event._id === event._id) { - func.call(this, segs[i]); - } - } - }, - - - // Retrieves all the rendered segment objects for the view - getSegs: function() { - // subclasses must implement - }, - - - /* Event Drag Visualization - ------------------------------------------------------------------------------------------------------------------*/ - - - // Renders a visual indication of an event hovering over the specified date. - // `end` is a Moment and might be null. - // `seg` might be null. if specified, it is the segment object of the event being dragged. - // otherwise, an external event from outside the calendar is being dragged. - renderDrag: function(start, end, seg) { - // subclasses should implement - }, - - - // Unrenders a visual indication of event hovering - destroyDrag: function() { - // subclasses should implement - }, - - - // Handler for accepting externally dragged events being dropped in the view. - // Gets called when jqui's 'dragstart' is fired. - documentDragStart: function(ev, ui) { - var _this = this; - var calendar = this.calendar; - var eventStart = null; // a null value signals an unsuccessful drag - var eventEnd = null; - var visibleEnd = null; // will be calculated event when no eventEnd - var el; - var accept; - var meta; - var eventProps; // if an object, signals an event should be created upon drop - var dragListener; - - if (this.opt('droppable')) { // only listen if this setting is on - el = $(ev.target); - - // Test that the dragged element passes the dropAccept selector or filter function. - // FYI, the default is "*" (matches all) - accept = this.opt('dropAccept'); - if ($.isFunction(accept) ? accept.call(el[0], el) : el.is(accept)) { - - meta = getDraggedElMeta(el); // data for possibly creating an event - eventProps = meta.eventProps; - - // listener that tracks mouse movement over date-associated pixel regions - dragListener = new DragListener(this.coordMap, { - cellOver: function(cell, cellDate) { - eventStart = cellDate; - eventEnd = meta.duration ? eventStart.clone().add(meta.duration) : null; - visibleEnd = eventEnd || calendar.getDefaultEventEnd(!eventStart.hasTime(), eventStart); - - // keep the start/end up to date when dragging - if (eventProps) { - $.extend(eventProps, { start: eventStart, end: eventEnd }); - } - - if (calendar.isExternalDragAllowedInRange(eventStart, visibleEnd, eventProps)) { - _this.renderDrag(eventStart, visibleEnd); - } - else { - eventStart = null; // signal unsuccessful - disableCursor(); - } - }, - cellOut: function() { - eventStart = null; - _this.destroyDrag(); - enableCursor(); - } - }); - - // gets called, only once, when jqui drag is finished - $(document).one('dragstop', function(ev, ui) { - var renderedEvents; - - _this.destroyDrag(); - enableCursor(); - - if (eventStart) { // element was dropped on a valid date/time cell - - // if dropped on an all-day cell, and element's metadata specified a time, set it - if (meta.startTime && !eventStart.hasTime()) { - eventStart.time(meta.startTime); - } - - // trigger 'drop' regardless of whether element represents an event - _this.trigger('drop', el[0], eventStart, ev, ui); - - // create an event from the given properties and the latest dates - if (eventProps) { - renderedEvents = calendar.renderEvent(eventProps, meta.stick); - _this.trigger('eventReceive', null, renderedEvents[0]); // signal an external event landed - } - } - }); - - dragListener.startDrag(ev); // start listening immediately - } - } - }, - - - /* Selection - ------------------------------------------------------------------------------------------------------------------*/ - - - // Selects a date range on the view. `start` and `end` are both Moments. - // `ev` is the native mouse event that begin the interaction. - select: function(start, end, ev) { - this.unselect(ev); - this.renderSelection(start, end); - this.reportSelection(start, end, ev); - }, - - - // Renders a visual indication of the selection - renderSelection: function(start, end) { - // subclasses should implement - }, - - - // Called when a new selection is made. Updates internal state and triggers handlers. - reportSelection: function(start, end, ev) { - this.isSelected = true; - this.trigger('select', null, start, end, ev); - }, - - - // Undoes a selection. updates in the internal state and triggers handlers. - // `ev` is the native mouse event that began the interaction. - unselect: function(ev) { - if (this.isSelected) { - this.isSelected = false; - this.destroySelection(); - this.trigger('unselect', null, ev); - } - }, - - - // Unrenders a visual indication of selection - destroySelection: function() { - // subclasses should implement - }, - - - // Handler for unselecting when the user clicks something and the 'unselectAuto' setting is on - documentMousedown: function(ev) { - var ignore; - - // is there a selection, and has the user made a proper left click? - if (this.isSelected && this.opt('unselectAuto') && isPrimaryMouseButton(ev)) { - - // only unselect if the clicked element is not identical to or inside of an 'unselectCancel' element - ignore = this.opt('unselectCancel'); - if (!ignore || !$(ev.target).closest(ignore).length) { - this.unselect(ev); - } - } - } - -}; - - -// We are mixing JavaScript OOP design patterns here by putting methods and member variables in the closed scope of the -// constructor. Going forward, methods should be part of the prototype. -function View(calendar) { - var t = this; - - // exports - t.calendar = calendar; - t.opt = opt; - t.trigger = trigger; - t.isEventDraggable = isEventDraggable; - t.isEventResizable = isEventResizable; - t.eventDrop = eventDrop; - t.eventResize = eventResize; - - // imports - var reportEventChange = calendar.reportEventChange; - - // locals - var options = calendar.options; - var nextDayThreshold = moment.duration(options.nextDayThreshold); - - - t.init(); // the "constructor" that concerns the prototype methods - - - function opt(name) { - var v = options[name]; - if ($.isPlainObject(v) && !isForcedAtomicOption(name)) { - return smartProperty(v, t.name); - } - return v; - } - - - function trigger(name, thisObj) { - return calendar.trigger.apply( - calendar, - [name, thisObj || t].concat(Array.prototype.slice.call(arguments, 2), [t]) - ); - } - - - - /* Event Editable Boolean Calculations - ------------------------------------------------------------------------------*/ - - - function isEventDraggable(event) { - var source = event.source || {}; - - return firstDefined( - event.startEditable, - source.startEditable, - opt('eventStartEditable'), - event.editable, - source.editable, - opt('editable') - ); - } - - - function isEventResizable(event) { - var source = event.source || {}; - - return firstDefined( - event.durationEditable, - source.durationEditable, - opt('eventDurationEditable'), - event.editable, - source.editable, - opt('editable') - ); - } - - - - /* Event Elements - ------------------------------------------------------------------------------*/ - - - // Compute the text that should be displayed on an event's element. - // Based off the settings of the view. Possible signatures: - // .getEventTimeText(event, formatStr) - // .getEventTimeText(startMoment, endMoment, formatStr) - // .getEventTimeText(startMoment, null, formatStr) - // `timeFormat` is used but the `formatStr` argument can be used to override. - t.getEventTimeText = function(event, formatStr) { - var start; - var end; - - if (typeof event === 'object' && typeof formatStr === 'object') { - // first two arguments are actually moments (or null). shift arguments. - start = event; - end = formatStr; - formatStr = arguments[2]; - } - else { - // otherwise, an event object was the first argument - start = event.start; - end = event.end; - } - - formatStr = formatStr || opt('timeFormat'); - - if (end && opt('displayEventEnd')) { - return calendar.formatRange(start, end, formatStr); - } - else { - return calendar.formatDate(start, formatStr); - } - }; - - - - /* Event Modification Reporting - ---------------------------------------------------------------------------------*/ - - - function eventDrop(el, event, newStart, ev) { - var mutateResult = calendar.mutateEvent(event, newStart, null); - - trigger( - 'eventDrop', - el, - event, - mutateResult.dateDelta, - function() { - mutateResult.undo(); - reportEventChange(); - }, - ev, - {} // jqui dummy - ); - - reportEventChange(); - } - - - function eventResize(el, event, newEnd, ev) { - var mutateResult = calendar.mutateEvent(event, null, newEnd); - - trigger( - 'eventResize', - el, - event, - mutateResult.durationDelta, - function() { - mutateResult.undo(); - reportEventChange(); - }, - ev, - {} // jqui dummy - ); - - reportEventChange(); - } - - - // ==================================================================================================== - // Utilities for day "cells" - // ==================================================================================================== - // The "basic" views are completely made up of day cells. - // The "agenda" views have day cells at the top "all day" slot. - // This was the obvious common place to put these utilities, but they should be abstracted out into - // a more meaningful class (like DayEventRenderer). - // ==================================================================================================== - - - // For determining how a given "cell" translates into a "date": - // - // 1. Convert the "cell" (row and column) into a "cell offset" (the # of the cell, cronologically from the first). - // Keep in mind that column indices are inverted with isRTL. This is taken into account. - // - // 2. Convert the "cell offset" to a "day offset" (the # of days since the first visible day in the view). - // - // 3. Convert the "day offset" into a "date" (a Moment). - // - // The reverse transformation happens when transforming a date into a cell. - - - // exports - t.isHiddenDay = isHiddenDay; - t.skipHiddenDays = skipHiddenDays; - t.getCellsPerWeek = getCellsPerWeek; - t.dateToCell = dateToCell; - t.dateToDayOffset = dateToDayOffset; - t.dayOffsetToCellOffset = dayOffsetToCellOffset; - t.cellOffsetToCell = cellOffsetToCell; - t.cellToDate = cellToDate; - t.cellToCellOffset = cellToCellOffset; - t.cellOffsetToDayOffset = cellOffsetToDayOffset; - t.dayOffsetToDate = dayOffsetToDate; - t.rangeToSegments = rangeToSegments; - t.isMultiDayEvent = isMultiDayEvent; - - - // internals - var hiddenDays = opt('hiddenDays') || []; // array of day-of-week indices that are hidden - var isHiddenDayHash = []; // is the day-of-week hidden? (hash with day-of-week-index -> bool) - var cellsPerWeek; - var dayToCellMap = []; // hash from dayIndex -> cellIndex, for one week - var cellToDayMap = []; // hash from cellIndex -> dayIndex, for one week - var isRTL = opt('isRTL'); - - - // initialize important internal variables - (function() { - - if (opt('weekends') === false) { - hiddenDays.push(0, 6); // 0=sunday, 6=saturday - } - - // Loop through a hypothetical week and determine which - // days-of-week are hidden. Record in both hashes (one is the reverse of the other). - for (var dayIndex=0, cellIndex=0; dayIndex<7; dayIndex++) { - dayToCellMap[dayIndex] = cellIndex; - isHiddenDayHash[dayIndex] = $.inArray(dayIndex, hiddenDays) != -1; - if (!isHiddenDayHash[dayIndex]) { - cellToDayMap[cellIndex] = dayIndex; - cellIndex++; - } - } - - cellsPerWeek = cellIndex; - if (!cellsPerWeek) { - throw 'invalid hiddenDays'; // all days were hidden? bad. - } - - })(); - - - // Is the current day hidden? - // `day` is a day-of-week index (0-6), or a Moment - function isHiddenDay(day) { - if (moment.isMoment(day)) { - day = day.day(); - } - return isHiddenDayHash[day]; - } - - - function getCellsPerWeek() { - return cellsPerWeek; - } - - - // Incrementing the current day until it is no longer a hidden day, returning a copy. - // If the initial value of `date` is not a hidden day, don't do anything. - // Pass `isExclusive` as `true` if you are dealing with an end date. - // `inc` defaults to `1` (increment one day forward each time) - function skipHiddenDays(date, inc, isExclusive) { - var out = date.clone(); - inc = inc || 1; - while ( - isHiddenDayHash[(out.day() + (isExclusive ? inc : 0) + 7) % 7] - ) { - out.add(inc, 'days'); - } - return out; - } - - - // - // TRANSFORMATIONS: cell -> cell offset -> day offset -> date - // - - // cell -> date (combines all transformations) - // Possible arguments: - // - row, col - // - { row:#, col: # } - function cellToDate() { - var cellOffset = cellToCellOffset.apply(null, arguments); - var dayOffset = cellOffsetToDayOffset(cellOffset); - var date = dayOffsetToDate(dayOffset); - return date; - } - - // cell -> cell offset - // Possible arguments: - // - row, col - // - { row:#, col:# } - function cellToCellOffset(row, col) { - var colCnt = t.colCnt; - - // rtl variables. wish we could pre-populate these. but where? - var dis = isRTL ? -1 : 1; - var dit = isRTL ? colCnt - 1 : 0; - - if (typeof row == 'object') { - col = row.col; - row = row.row; - } - var cellOffset = row * colCnt + (col * dis + dit); // column, adjusted for RTL (dis & dit) - - return cellOffset; - } - - // cell offset -> day offset - function cellOffsetToDayOffset(cellOffset) { - var day0 = t.start.day(); // first date's day of week - cellOffset += dayToCellMap[day0]; // normlize cellOffset to beginning-of-week - return Math.floor(cellOffset / cellsPerWeek) * 7 + // # of days from full weeks - cellToDayMap[ // # of days from partial last week - (cellOffset % cellsPerWeek + cellsPerWeek) % cellsPerWeek // crazy math to handle negative cellOffsets - ] - - day0; // adjustment for beginning-of-week normalization - } - - // day offset -> date - function dayOffsetToDate(dayOffset) { - return t.start.clone().add(dayOffset, 'days'); - } - - - // - // TRANSFORMATIONS: date -> day offset -> cell offset -> cell - // - - // date -> cell (combines all transformations) - function dateToCell(date) { - var dayOffset = dateToDayOffset(date); - var cellOffset = dayOffsetToCellOffset(dayOffset); - var cell = cellOffsetToCell(cellOffset); - return cell; - } - - // date -> day offset - function dateToDayOffset(date) { - return date.clone().stripTime().diff(t.start, 'days'); - } - - // day offset -> cell offset - function dayOffsetToCellOffset(dayOffset) { - var day0 = t.start.day(); // first date's day of week - dayOffset += day0; // normalize dayOffset to beginning-of-week - return Math.floor(dayOffset / 7) * cellsPerWeek + // # of cells from full weeks - dayToCellMap[ // # of cells from partial last week - (dayOffset % 7 + 7) % 7 // crazy math to handle negative dayOffsets - ] - - dayToCellMap[day0]; // adjustment for beginning-of-week normalization - } - - // cell offset -> cell (object with row & col keys) - function cellOffsetToCell(cellOffset) { - var colCnt = t.colCnt; - - // rtl variables. wish we could pre-populate these. but where? - var dis = isRTL ? -1 : 1; - var dit = isRTL ? colCnt - 1 : 0; - - var row = Math.floor(cellOffset / colCnt); - var col = ((cellOffset % colCnt + colCnt) % colCnt) * dis + dit; // column, adjusted for RTL (dis & dit) - return { - row: row, - col: col - }; - } - - - // - // Converts a date range into an array of segment objects. - // "Segments" are horizontal stretches of time, sliced up by row. - // A segment object has the following properties: - // - row - // - cols - // - isStart - // - isEnd - // - function rangeToSegments(start, end) { - - var rowCnt = t.rowCnt; - var colCnt = t.colCnt; - var segments = []; // array of segments to return - - // day offset for given date range - var dayRange = computeDayRange(start, end); // convert to a whole-day range - var rangeDayOffsetStart = dateToDayOffset(dayRange.start); - var rangeDayOffsetEnd = dateToDayOffset(dayRange.end); // an exclusive value - - // first and last cell offset for the given date range - // "last" implies inclusivity - var rangeCellOffsetFirst = dayOffsetToCellOffset(rangeDayOffsetStart); - var rangeCellOffsetLast = dayOffsetToCellOffset(rangeDayOffsetEnd) - 1; - - // loop through all the rows in the view - for (var row=0; row