From 8481937f595b9f2d8ac0a5b60b79a68c0850e6e9 Mon Sep 17 00:00:00 2001 From: Calen Pennington <calen.pennington@gmail.com> Date: Thu, 19 Jul 2012 14:06:53 -0400 Subject: [PATCH] Move Logger and *withPrefix javascript into a common location --- cms/envs/common.py | 14 +++++++++++--- cms/static/coffee/src/main.coffee | 6 +----- .../static/coffee/spec/logger_spec.coffee | 0 common/static/coffee/src/.gitignore | 1 + common/static/coffee/src/ajax_prefix.coffee | 16 ++++++++++++++++ {lms => common}/static/coffee/src/logger.coffee | 4 ++-- lms/envs/common.py | 6 +++++- lms/envs/dev.py | 4 ++-- lms/static/coffee/src/main.coffee | 6 +----- 9 files changed, 39 insertions(+), 18 deletions(-) rename {lms => common}/static/coffee/spec/logger_spec.coffee (100%) create mode 100644 common/static/coffee/src/.gitignore create mode 100644 common/static/coffee/src/ajax_prefix.coffee rename {lms => common}/static/coffee/src/logger.coffee (88%) diff --git a/cms/envs/common.py b/cms/envs/common.py index be398f6cb20..8a7422255a8 100644 --- a/cms/envs/common.py +++ b/cms/envs/common.py @@ -146,10 +146,10 @@ MANAGERS = ADMINS # Static content STATIC_URL = '/static/' ADMIN_MEDIA_PREFIX = '/static/admin/' -STATIC_ROOT = ENV_ROOT / "staticfiles" +STATIC_ROOT = ENV_ROOT / "staticfiles" STATICFILES_DIRS = [ - ('js/vendor', COMMON_ROOT / "static" / "js" / "vendor"), + COMMON_ROOT / "static", PROJECT_ROOT / "static", # This is how you would use the textbook images locally @@ -219,7 +219,15 @@ for idx, filetype, fragment in sorted(fragments): PIPELINE_JS = { 'main': { - 'source_filenames': [pth.replace(PROJECT_ROOT / 'static/', '') for pth in glob2.glob(PROJECT_ROOT / 'static/coffee/src/**/*.coffee')], + 'source_filenames': [ + pth.replace(COMMON_ROOT / 'static/', '') + for pth + in glob2.glob(COMMON_ROOT / 'static/coffee/src/**/*.coffee') + ] + [ + pth.replace(PROJECT_ROOT / 'static/', '') + for pth + in glob2.glob(PROJECT_ROOT / 'static/coffee/src/**/*.coffee') + ], 'output_filename': 'js/application.js', }, 'module-js': { diff --git a/cms/static/coffee/src/main.coffee b/cms/static/coffee/src/main.coffee index 30d459ecc3d..57b6d1ae93c 100644 --- a/cms/static/coffee/src/main.coffee +++ b/cms/static/coffee/src/main.coffee @@ -1,8 +1,4 @@ -jQuery.postWithPrefix = (url, data, callback, type) -> - $.post("#{CMS.prefix}#{url}", data, callback, type) - -jQuery.getWithPrefix = (url, data, callback, type) -> - $.get("#{CMS.prefix}#{url}", data, callback, type) +AjaxPrefix.addAjaxPrefix(jQuery, -> CMS.prefix) @CMS = Models: {} diff --git a/lms/static/coffee/spec/logger_spec.coffee b/common/static/coffee/spec/logger_spec.coffee similarity index 100% rename from lms/static/coffee/spec/logger_spec.coffee rename to common/static/coffee/spec/logger_spec.coffee diff --git a/common/static/coffee/src/.gitignore b/common/static/coffee/src/.gitignore new file mode 100644 index 00000000000..a6c7c2852d0 --- /dev/null +++ b/common/static/coffee/src/.gitignore @@ -0,0 +1 @@ +*.js diff --git a/common/static/coffee/src/ajax_prefix.coffee b/common/static/coffee/src/ajax_prefix.coffee new file mode 100644 index 00000000000..59db5becca1 --- /dev/null +++ b/common/static/coffee/src/ajax_prefix.coffee @@ -0,0 +1,16 @@ +@AjaxPrefix = + addAjaxPrefix: (jQuery, prefix) -> + jQuery.postWithPrefix = (url, data, callback, type) -> + $.post("#{prefix()}#{url}", data, callback, type) + + jQuery.getWithPrefix = (url, data, callback, type) -> + $.get("#{prefix()}#{url}", data, callback, type) + + jQuery.ajaxWithPrefix = (url, settings) -> + if settings? + $.ajax("#{prefix()}#{url}", settings) + else + settings = url + settings.url = "#{prefix()}#{settings.url}" + $.ajax settings + diff --git a/lms/static/coffee/src/logger.coffee b/common/static/coffee/src/logger.coffee similarity index 88% rename from lms/static/coffee/src/logger.coffee rename to common/static/coffee/src/logger.coffee index 414dc4f187b..58395ba8316 100644 --- a/lms/static/coffee/src/logger.coffee +++ b/common/static/coffee/src/logger.coffee @@ -7,8 +7,8 @@ class @Logger @bind: -> window.onunload = -> - $.ajax - url: "#{Courseware.prefix}/event" + $.ajaxWithPrefix + url: "/event" data: event_type: 'page_close' event: '' diff --git a/lms/envs/common.py b/lms/envs/common.py index 24751675b17..a49a7b814f9 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -184,7 +184,7 @@ ADMIN_MEDIA_PREFIX = '/static/admin/' STATIC_ROOT = ENV_ROOT / "staticfiles" STATICFILES_DIRS = [ - ('js/vendor', COMMON_ROOT / "static" / "js" / "vendor"), + COMMON_ROOT / "static", PROJECT_ROOT / "static", ASKBOT_ROOT / "askbot" / "skins", @@ -365,6 +365,10 @@ PIPELINE_JS = { 'application': { # Application will contain all paths not in courseware_only_js 'source_filenames': [ + pth.replace(COMMON_ROOT / 'static/', '') + for pth + in glob2.glob(COMMON_ROOT / 'static/coffee/src/**/*.coffee') + ] + [ pth.replace(PROJECT_ROOT / 'static/', '') for pth in glob2.glob(PROJECT_ROOT / 'static/coffee/src/**/*.coffee')\ if pth not in courseware_only_js diff --git a/lms/envs/dev.py b/lms/envs/dev.py index 487ccfb3e7f..1a2659cb1f3 100644 --- a/lms/envs/dev.py +++ b/lms/envs/dev.py @@ -56,8 +56,8 @@ CACHES = { SECRET_KEY = '85920908f28904ed733fe576320db18cabd7b6cd' ################################ DEBUG TOOLBAR ################################# -#INSTALLED_APPS += ('debug_toolbar',) -#MIDDLEWARE_CLASSES += ('debug_toolbar.middleware.DebugToolbarMiddleware',) +INSTALLED_APPS += ('debug_toolbar',) +MIDDLEWARE_CLASSES += ('debug_toolbar.middleware.DebugToolbarMiddleware',) INTERNAL_IPS = ('127.0.0.1',) DEBUG_TOOLBAR_PANELS = ( diff --git a/lms/static/coffee/src/main.coffee b/lms/static/coffee/src/main.coffee index 06a12e5b6ff..d74035cd2a8 100644 --- a/lms/static/coffee/src/main.coffee +++ b/lms/static/coffee/src/main.coffee @@ -1,8 +1,4 @@ -jQuery.postWithPrefix = (url, data, callback, type) -> - $.post("#{Courseware.prefix}#{url}", data, callback, type) - -jQuery.getWithPrefix = (url, data, callback, type) -> - $.get("#{Courseware.prefix}#{url}", data, callback, type) +AjaxPrefix.addAjaxPrefix(jQuery, -> Courseware.prefix) $ -> $.ajaxSetup -- GitLab