From ce4994dd94994c75111a2fa73c51be32f4b36893 Mon Sep 17 00:00:00 2001 From: Brian Talbot Date: Fri, 4 Jan 2013 13:27:59 -0500 Subject: [PATCH 01/14] studio - revised course overview section collapse button to toggle collapsing/expanding --- cms/static/js/base.js | 14 ++++++++++++++ cms/static/sass/_courseware.scss | 23 +++++++++++++++++++++++ cms/templates/overview.html | 2 +- 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/cms/static/js/base.js b/cms/static/js/base.js index 9fa4489c36..888fcef5b8 100644 --- a/cms/static/js/base.js +++ b/cms/static/js/base.js @@ -42,6 +42,7 @@ $(document).ready(function() { $('.new-unit-item').bind('click', createNewUnit); $('.collapse-all-button').bind('click', collapseAll); + $('.toggle-button-sections').bind('click', toggleSections); // autosave when a field is updated on the subsection page $body.on('keyup', '.subsection-display-name-input, .unit-subtitle, .policy-list-value', checkForNewValue); @@ -130,6 +131,19 @@ function collapseAll(e) { $('.expand-collapse-icon').removeClass('collapse').addClass('expand'); } +function toggleSections(e) { + e.preventDefault(); + + $section = $('.courseware-section'); + $button = $(this); + $labelCollapsed = $('up Collapse All Sections'); + $labelExpanded = $('down Expand All Sections'); + + $section.toggleClass('collapsed'); + var buttonLabel = $section.hasClass('collapsed') ? $labelExpanded : $labelCollapsed; + $button.toggleClass('is-activated').html(buttonLabel); +} + function editSectionPublishDate(e) { e.preventDefault(); $modal = $('.edit-subsection-publish-settings').show(); diff --git a/cms/static/sass/_courseware.scss b/cms/static/sass/_courseware.scss index e2037916cb..6a8be8e5ea 100644 --- a/cms/static/sass/_courseware.scss +++ b/cms/static/sass/_courseware.scss @@ -512,6 +512,29 @@ input.courseware-unit-search-input { } } +.toggle-button-sections { + position: relative; + float: right; + margin-top: 10px; + + font-size: 13px; + color: $darkGrey; + + .ss-icon { + @include border-radius(20px); + position: relative; + top: -1px; + display: inline-block; + margin-right: 2px; + line-height: 5px; + font-size: 11px; + } + + .label { + display: inline-block; + } +} + .new-section-name, .new-subsection-name-input { width: 515px; diff --git a/cms/templates/overview.html b/cms/templates/overview.html index 2a46908c55..a20531200e 100644 --- a/cms/templates/overview.html +++ b/cms/templates/overview.html @@ -122,7 +122,7 @@
% for section in sections: From 6b8944ad6be23d1a9e034f0551b04d3cfbae7c06 Mon Sep 17 00:00:00 2001 From: Brian Talbot Date: Mon, 7 Jan 2013 09:07:40 -0500 Subject: [PATCH 02/14] studio - section expanding/collapsing UI - wip --- cms/static/js/base.js | 17 +++++++++++++---- cms/static/sass/_courseware.scss | 24 +++++++++++++----------- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/cms/static/js/base.js b/cms/static/js/base.js index 888fcef5b8..086a535994 100644 --- a/cms/static/js/base.js +++ b/cms/static/js/base.js @@ -41,7 +41,12 @@ $(document).ready(function() { $('.unit .item-actions .delete-button').bind('click', deleteUnit); $('.new-unit-item').bind('click', createNewUnit); - $('.collapse-all-button').bind('click', collapseAll); + // toggling overview section details + $(function(){ + if($('.courseware-section').length > 0) { + $('.toggle-button-sections').addClass('is-shown'); + } + }); $('.toggle-button-sections').bind('click', toggleSections); // autosave when a field is updated on the subsection page @@ -135,13 +140,17 @@ function toggleSections(e) { e.preventDefault(); $section = $('.courseware-section'); + sectionCount = $section.length; $button = $(this); $labelCollapsed = $('up Collapse All Sections'); $labelExpanded = $('down Expand All Sections'); - $section.toggleClass('collapsed'); - var buttonLabel = $section.hasClass('collapsed') ? $labelExpanded : $labelCollapsed; - $button.toggleClass('is-activated').html(buttonLabel); + if (sectionCount > 0) { + $section.toggleClass('collapsed'); + $section.find('.expand-collapse-icon').toggleClass('collapse expand'); + var buttonLabel = $section.hasClass('collapsed') ? $labelExpanded : $labelCollapsed; + $button.toggleClass('is-activated').html(buttonLabel); + } } function editSectionPublishDate(e) { diff --git a/cms/static/sass/_courseware.scss b/cms/static/sass/_courseware.scss index 6a8be8e5ea..2fe4605a33 100644 --- a/cms/static/sass/_courseware.scss +++ b/cms/static/sass/_courseware.scss @@ -422,6 +422,14 @@ input.courseware-unit-search-input { float: left; margin: 29px 6px 16px 16px; @include transition(none); + + &.expand { + background-position: 0 0; + } + + &.collapsed { + + } } .drag-handle { @@ -501,18 +509,8 @@ input.courseware-unit-search-input { } } -.collapse-all-button { - float: right; - margin-top: 10px; - font-size: 13px; - color: $darkGrey; - - .collapse-all-icon { - margin-right: 6px; - } -} - .toggle-button-sections { + display: none; position: relative; float: right; margin-top: 10px; @@ -520,6 +518,10 @@ input.courseware-unit-search-input { font-size: 13px; color: $darkGrey; + &.is-shown { + display: block; + } + .ss-icon { @include border-radius(20px); position: relative; From 2019c9d037d9b9153ea113eac122aae3ba19ed0a Mon Sep 17 00:00:00 2001 From: Don Mitchell Date: Wed, 9 Jan 2013 09:47:43 -0500 Subject: [PATCH 03/14] Bug 107 --- cms/djangoapps/contentstore/views.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cms/djangoapps/contentstore/views.py b/cms/djangoapps/contentstore/views.py index 4cbf6b5d30..560485eb26 100644 --- a/cms/djangoapps/contentstore/views.py +++ b/cms/djangoapps/contentstore/views.py @@ -973,6 +973,11 @@ def course_info_updates(request, org, course, provided_id=None): # ??? No way to check for access permission afaik # get current updates location = ['i4x', org, course, 'course_info', "updates"] + + # Hmmm, provided_id is coming as empty string on create whereas I believe it used to be None :-( + # Possibly due to my removing the seemingly redundant pattern in urls.py + if provided_id == '': + provided_id = None # check that logged in user has permissions to this item if not has_access(request.user, location): From 62a70170cf9c6e6208ec793042781f8117877c37 Mon Sep 17 00:00:00 2001 From: Don Mitchell Date: Wed, 9 Jan 2013 09:55:50 -0500 Subject: [PATCH 04/14] Updated unit test for the create operation related to bug 107 --- .../contentstore/tests/test_course_updates.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/cms/djangoapps/contentstore/tests/test_course_updates.py b/cms/djangoapps/contentstore/tests/test_course_updates.py index b05754d214..96e4468b31 100644 --- a/cms/djangoapps/contentstore/tests/test_course_updates.py +++ b/cms/djangoapps/contentstore/tests/test_course_updates.py @@ -1,8 +1,6 @@ from cms.djangoapps.contentstore.tests.test_course_settings import CourseTestCase from django.core.urlresolvers import reverse import json -from cms.djangoapps.contentstore.course_info_model import update_course_updates - class CourseUpdateTest(CourseTestCase): def test_course_update(self): @@ -14,14 +12,17 @@ class CourseUpdateTest(CourseTestCase): content = '' payload = { 'content' : content, 'date' : 'January 8, 2013'} - # No means to post w/ provided_id missing. django doesn't handle. So, go direct for the create - payload = update_course_updates(['i4x', self.course_location.org, self.course_location.course, 'course_info', "updates"] , payload) + url = reverse('course_info', kwargs={'org' : self.course_location.org, 'course' : self.course_location.course, + 'provided_id' : ''}) + + resp = self.client.post(url, json.dumps(payload), "application/json") + + payload= json.loads(resp.content) + + self.assertHTMLEqual(content, payload['content'], "single iframe") url = reverse('course_info', kwargs={'org' : self.course_location.org, 'course' : self.course_location.course, 'provided_id' : payload['id']}) - - self.assertHTMLEqual(content, payload['content'], "single iframe") - content += '
div

p

' payload['content'] = content resp = self.client.post(url, json.dumps(payload), "application/json") From fd600e5be2563b0ed41831f031e43e3527cade95 Mon Sep 17 00:00:00 2001 From: Chris Dodge Date: Wed, 9 Jan 2013 10:38:32 -0500 Subject: [PATCH 05/14] add some simple in-mem caching for course TOC. This is a problem when running against Mongo since courses are created/disposed very frequently --- common/lib/xmodule/xmodule/course_module.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/common/lib/xmodule/xmodule/course_module.py b/common/lib/xmodule/xmodule/course_module.py index f8e18a9355..01f7572582 100644 --- a/common/lib/xmodule/xmodule/course_module.py +++ b/common/lib/xmodule/xmodule/course_module.py @@ -6,6 +6,7 @@ from xmodule.modulestore import Location from xmodule.seq_module import SequenceDescriptor, SequenceModule from xmodule.timeparse import parse_time, stringify_time from xmodule.util.decorators import lazyproperty +from datetime import datetime import json import logging import requests @@ -18,6 +19,8 @@ log = logging.getLogger(__name__) edx_xml_parser = etree.XMLParser(dtd_validation=False, load_dtd=False, remove_comments=True, remove_blank_text=True) +_cached_toc = {} + class CourseDescriptor(SequenceDescriptor): module_class = SequenceModule @@ -50,6 +53,17 @@ class CourseDescriptor(SequenceDescriptor): """ toc_url = self.book_url + 'toc.xml' + try: + # see if we already fetched this + if toc_url in _cached_toc: + (table_of_contents, timestamp) = _cached_toc[toc_url] + age = datetime.now() - timestamp + # expire every 10 minutes + if age.seconds < 600: + return table_of_contents + except Exception as err: + pass + # Get the table of contents from S3 log.info("Retrieving textbook table of contents from %s" % toc_url) try: @@ -62,6 +76,7 @@ class CourseDescriptor(SequenceDescriptor): # TOC is XML. Parse it try: table_of_contents = etree.fromstring(r.text) + _cached_toc[toc_url] = (table_of_contents, datetime.now()) except Exception as err: msg = 'Error %s: Unable to parse XML for textbook table of contents at %s' % (err, toc_url) log.error(msg) From 9b72d1147392a5348c2055d5173d15629cf9b159 Mon Sep 17 00:00:00 2001 From: Chris Dodge Date: Wed, 9 Jan 2013 10:47:29 -0500 Subject: [PATCH 06/14] add some comments to the change --- common/lib/xmodule/xmodule/course_module.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/common/lib/xmodule/xmodule/course_module.py b/common/lib/xmodule/xmodule/course_module.py index 01f7572582..4d3b2b1e00 100644 --- a/common/lib/xmodule/xmodule/course_module.py +++ b/common/lib/xmodule/xmodule/course_module.py @@ -53,6 +53,13 @@ class CourseDescriptor(SequenceDescriptor): """ toc_url = self.book_url + 'toc.xml' + # cdodge: I've added this caching of TOC because in Mongo-backed instances (but not Filesystem stores) + # course modules have a very short lifespan and are constantly being created and torn down. + # Since this module in the __init__() method does a synchronous call to AWS to get the TOC + # this is causing a big performance problem. So let's be a bit smarter about this and cache + # each fetch and store in-mem for 10 minutes. + # NOTE: I have to get this onto sandbox ASAP as we're having runtime failures. I'd like to swing back and + # rewrite to use the traditional Django in-memory cache. try: # see if we already fetched this if toc_url in _cached_toc: From 19fa439326cf28c8f8ee5a9f9aee33f93ef9d7b8 Mon Sep 17 00:00:00 2001 From: Brian Talbot Date: Wed, 9 Jan 2013 12:31:32 -0500 Subject: [PATCH 07/14] studio - firming up section-wide collapsing/expanding functionality --- cms/static/js/base.js | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/cms/static/js/base.js b/cms/static/js/base.js index 086a535994..5863cb8ca4 100644 --- a/cms/static/js/base.js +++ b/cms/static/js/base.js @@ -131,10 +131,10 @@ $(document).ready(function() { }); }); -function collapseAll(e) { - $('.branch').addClass('collapsed'); - $('.expand-collapse-icon').removeClass('collapse').addClass('expand'); -} +// function collapseAll(e) { +// $('.branch').addClass('collapsed'); +// $('.expand-collapse-icon').removeClass('collapse').addClass('expand'); +// } function toggleSections(e) { e.preventDefault(); @@ -145,11 +145,15 @@ function toggleSections(e) { $labelCollapsed = $('up Collapse All Sections'); $labelExpanded = $('down Expand All Sections'); - if (sectionCount > 0) { - $section.toggleClass('collapsed'); - $section.find('.expand-collapse-icon').toggleClass('collapse expand'); - var buttonLabel = $section.hasClass('collapsed') ? $labelExpanded : $labelCollapsed; - $button.toggleClass('is-activated').html(buttonLabel); + var buttonLabel = $button.hasClass('is-activated') ? $labelCollapsed : $labelExpanded; + $button.toggleClass('is-activated').html(buttonLabel); + + if($button.hasClass('is-activated')) { + $section.addClass('collapsed'); + $section.find('.expand-collapse-icon').removeClass('collapsed').addClass('expand'); + } else { + $section.removeClass('collapsed'); + $section.find('.expand-collapse-icon').removeClass('expand').addClass('collapse'); } } From e11706ef07818e4cd0be83300ac47fe338bd7b5b Mon Sep 17 00:00:00 2001 From: Chris Dodge Date: Wed, 9 Jan 2013 15:53:22 -0500 Subject: [PATCH 08/14] change over the 'get all discussion models' to use get_items() which is better supported in Mongo-backed stores --- .../xmodule/xmodule/modulestore/__init__.py | 2 +- .../lib/xmodule/xmodule/modulestore/mongo.py | 2 +- common/lib/xmodule/xmodule/modulestore/xml.py | 12 ++++-- lms/djangoapps/django_comment_client/utils.py | 43 ++++++++++--------- 4 files changed, 34 insertions(+), 25 deletions(-) diff --git a/common/lib/xmodule/xmodule/modulestore/__init__.py b/common/lib/xmodule/xmodule/modulestore/__init__.py index 2a47b26eaa..3de55dbc6c 100644 --- a/common/lib/xmodule/xmodule/modulestore/__init__.py +++ b/common/lib/xmodule/xmodule/modulestore/__init__.py @@ -284,7 +284,7 @@ class ModuleStore(object): """ raise NotImplementedError - def get_items(self, location, depth=0): + def get_items(self, location, course_id=None, depth=0): """ Returns a list of XModuleDescriptor instances for the items that match location. Any element of location that is None is treated diff --git a/common/lib/xmodule/xmodule/modulestore/mongo.py b/common/lib/xmodule/xmodule/modulestore/mongo.py index c65c031c9a..cdd8076431 100644 --- a/common/lib/xmodule/xmodule/modulestore/mongo.py +++ b/common/lib/xmodule/xmodule/modulestore/mongo.py @@ -262,7 +262,7 @@ class MongoModuleStore(ModuleStoreBase): """ return self.get_item(location) - def get_items(self, location, depth=0): + def get_items(self, location, course_id=None, depth=0): items = self.collection.find( location_to_query(location), sort=[('revision', pymongo.ASCENDING)], diff --git a/common/lib/xmodule/xmodule/modulestore/xml.py b/common/lib/xmodule/xmodule/modulestore/xml.py index b7f1b0da02..47a9ec282e 100644 --- a/common/lib/xmodule/xmodule/modulestore/xml.py +++ b/common/lib/xmodule/xmodule/modulestore/xml.py @@ -513,16 +513,22 @@ class XMLModuleStore(ModuleStoreBase): raise NotImplementedError("XMLModuleStores can't guarantee that definitions" " are unique. Use get_instance.") - def get_items(self, location, depth=0): + def get_items(self, location, course_id=None, depth=0): items = [] - for _, modules in self.modules.iteritems(): - for mod_loc, module in modules.iteritems(): + def _add_get_items(self, location, modules): + for mod_loc, module in modules.iteritems(): # Locations match if each value in `location` is None or if the value from `location` # matches the value from `mod_loc` if all(goal is None or goal == value for goal, value in zip(location, mod_loc)): items.append(module) + if course_id is None: + for _, modules in self.modules.iteritems(): + _add_get_items(self, location, modules) + else: + _add_get_items(self, location, self.modules[course_id]) + return items diff --git a/lms/djangoapps/django_comment_client/utils.py b/lms/djangoapps/django_comment_client/utils.py index 71fc38c0e1..bd49d1d86f 100644 --- a/lms/djangoapps/django_comment_client/utils.py +++ b/lms/djangoapps/django_comment_client/utils.py @@ -127,6 +127,7 @@ def sort_map_entries(category_map): sort_map_entries(category_map["subcategories"][title]) category_map["children"] = [x[0] for x in sorted(things, key=lambda x: x[1]["sort_key"])] + def initialize_discussion_info(course): global _DISCUSSIONINFO @@ -134,32 +135,34 @@ def initialize_discussion_info(course): return course_id = course.id - all_modules = get_full_modules()[course_id] discussion_id_map = {} - unexpanded_category_map = defaultdict(list) - for location, module in all_modules.items(): - if location.category == 'discussion': - skip_module = False - for key in ('id', 'discussion_category', 'for'): - if key not in module.metadata: - log.warning("Required key '%s' not in discussion %s, leaving out of category map" % (key, module.location)) - skip_module = True + #all_modules = get_full_modules()[course_id] - if skip_module: - continue + all_modules = modulestore().get_items(['i4x', course.location.org, course.location.course, 'discussion', None], course_id=course_id) - id = module.metadata['id'] - category = module.metadata['discussion_category'] - title = module.metadata['for'] - sort_key = module.metadata.get('sort_key', title) - category = " / ".join([x.strip() for x in category.split("/")]) - last_category = category.split("/")[-1] - discussion_id_map[id] = {"location": location, "title": last_category + " / " + title} - unexpanded_category_map[category].append({"title": title, "id": id, - "sort_key": sort_key, "start_date": module.start}) + for module in all_modules: + logging.debug('{0}'.format(module.location)) + skip_module = False + for key in ('id', 'discussion_category', 'for'): + if key not in module.metadata: + log.warning("Required key '%s' not in discussion %s, leaving out of category map" % (key, module.location)) + skip_module = True + + if skip_module: + continue + + id = module.metadata['id'] + category = module.metadata['discussion_category'] + title = module.metadata['for'] + sort_key = module.metadata.get('sort_key', title) + category = " / ".join([x.strip() for x in category.split("/")]) + last_category = category.split("/")[-1] + discussion_id_map[id] = {"location": module.location, "title": last_category + " / " + title} + unexpanded_category_map[category].append({"title": title, "id": id, + "sort_key": sort_key, "start_date": module.start}) category_map = {"entries": defaultdict(dict), "subcategories": defaultdict(dict)} for category_path, entries in unexpanded_category_map.items(): From d4f30b378e212210b72547918a44513af8c835cb Mon Sep 17 00:00:00 2001 From: Chris Dodge Date: Wed, 9 Jan 2013 16:05:09 -0500 Subject: [PATCH 09/14] remove commented out line and add a new comment. also remove debugging trace output --- lms/djangoapps/django_comment_client/utils.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lms/djangoapps/django_comment_client/utils.py b/lms/djangoapps/django_comment_client/utils.py index bd49d1d86f..1f39ebfcfd 100644 --- a/lms/djangoapps/django_comment_client/utils.py +++ b/lms/djangoapps/django_comment_client/utils.py @@ -139,12 +139,10 @@ def initialize_discussion_info(course): discussion_id_map = {} unexpanded_category_map = defaultdict(list) - #all_modules = get_full_modules()[course_id] - + # get all discussion models within this course_id all_modules = modulestore().get_items(['i4x', course.location.org, course.location.course, 'discussion', None], course_id=course_id) for module in all_modules: - logging.debug('{0}'.format(module.location)) skip_module = False for key in ('id', 'discussion_category', 'for'): if key not in module.metadata: From 96a7db62cd7c8d68211c16785a0aecf1f8cc353e Mon Sep 17 00:00:00 2001 From: Don Mitchell Date: Wed, 9 Jan 2013 17:55:02 -0500 Subject: [PATCH 10/14] Fixed time picker race condition for grace period. Still quirky in that in rounds down times from :01-:09 to :00 (and perhaps others). I think that's a bug or setting in timepicker. --- cms/static/js/views/settings/main_settings_view.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/cms/static/js/views/settings/main_settings_view.js b/cms/static/js/views/settings/main_settings_view.js index 31b8586d5a..9037d4510c 100644 --- a/cms/static/js/views/settings/main_settings_view.js +++ b/cms/static/js/views/settings/main_settings_view.js @@ -388,6 +388,9 @@ CMS.Views.Settings.Grading = CMS.Views.ValidatingView.extend({ var graceEle = this.$el.find('#course-grading-graceperiod'); graceEle.timepicker({'timeFormat' : 'H:i'}); // init doesn't take setTime if (this.model.has('grace_period')) graceEle.timepicker('setTime', this.model.gracePeriodToDate()); + // remove any existing listeners to keep them from piling on b/c render gets called frequently + graceEle.off('change', this.setGracePeriod); + graceEle.on('change', this, this.setGracePeriod); return this; }, @@ -398,14 +401,16 @@ CMS.Views.Settings.Grading = CMS.Views.ValidatingView.extend({ fieldToSelectorMap : { 'grace_period' : 'course-grading-graceperiod' }, + setGracePeriod : function(event) { + event.data.clearValidationErrors(); + var newVal = event.data.model.dateToGracePeriod($(event.currentTarget).timepicker('getTime')); + if (event.data.model.get('grace_period') != newVal) event.data.model.save('grace_period', newVal); + }, updateModel : function(event) { if (!this.selectorToField[event.currentTarget.id]) return; switch (this.selectorToField[event.currentTarget.id]) { - case 'grace_period': - this.clearValidationErrors(); - var newVal = this.model.dateToGracePeriod($(event.currentTarget).timepicker('getTime')); - if (this.model.get('grace_period') != newVal) this.model.save('grace_period', newVal); + case 'grace_period': // handled above break; default: From 04582f4e7cc22b853cce3a8cde22b16189182c95 Mon Sep 17 00:00:00 2001 From: Don Mitchell Date: Thu, 10 Jan 2013 11:05:14 -0500 Subject: [PATCH 11/14] Update timepicker b/c it wasn't handling minutes from 01-09 and they'd fixed it --- .../vendor/timepicker/jquery.timepicker.css | 13 +- .../js/vendor/timepicker/jquery.timepicker.js | 246 ++++++++++++------ .../timepicker/jquery.timepicker.min.js | 2 +- 3 files changed, 174 insertions(+), 87 deletions(-) mode change 100755 => 100644 common/static/js/vendor/timepicker/jquery.timepicker.js diff --git a/common/static/js/vendor/timepicker/jquery.timepicker.css b/common/static/js/vendor/timepicker/jquery.timepicker.css index ad6dae98b8..0586ef16c3 100755 --- a/common/static/js/vendor/timepicker/jquery.timepicker.css +++ b/common/static/js/vendor/timepicker/jquery.timepicker.css @@ -1,18 +1,17 @@ .ui-timepicker-list { overflow-y: auto; height: 150px; - width: 7.5em; + width: 6.5em; background: #fff; - border: 1px solid #8891a1; + border: 1px solid #ddd; margin: 0; padding: 0; list-style: none; - -webkit-box-shadow: 0 5px 10px rgba(0,0,0,0.1); - -moz-box-shadow: 0 5px 10px rgba(0,0,0,0.1); - box-shadow: 0 5px 10px rgba(0,0,0,0.1); + -webkit-box-shadow:0 5px 10px rgba(0,0,0,0.2); + -moz-box-shadow:0 5px 10px rgba(0,0,0,0.2); + box-shadow:0 5px 10px rgba(0,0,0,0.2); outline: none; - z-index: 100001; - font-size: 12px; + z-index: 10001; } .ui-timepicker-list.ui-timepicker-with-duration { diff --git a/common/static/js/vendor/timepicker/jquery.timepicker.js b/common/static/js/vendor/timepicker/jquery.timepicker.js old mode 100755 new mode 100644 index 3a462dd436..fb35f99ed2 --- a/common/static/js/vendor/timepicker/jquery.timepicker.js +++ b/common/static/js/vendor/timepicker/jquery.timepicker.js @@ -2,16 +2,22 @@ jquery-timepicker http://jonthornton.github.com/jquery-timepicker/ -requires jQuery 1.6+ - -version: 1.2.2 +requires jQuery 1.7+ ************************/ -!(function($) -{ - var _baseDate = new Date(); _baseDate.setHours(0); _baseDate.setMinutes(0); _baseDate.setSeconds(0); +(function (factory) { + if (typeof define === 'function' && define.amd) { + // AMD. Register as an anonymous module. + define(['jquery'], factory); + } else { + // Browser globals + factory(jQuery); + } +}(function ($) { + var _baseDate = _generateBaseDate(); var _ONE_DAY = 86400; + var _closeEvent = 'ontouchstart' in document ? 'touchstart' : 'mousedown'; var _defaults = { className: null, minTime: null, @@ -22,7 +28,9 @@ version: 1.2.2 timeFormat: 'g:ia', scrollDefaultNow: false, scrollDefaultTime: false, - selectOnBlur: false + selectOnBlur: false, + forceRoundTime: false, + appendTo: 'body' }; var _lang = { decimal: '.', @@ -30,6 +38,7 @@ version: 1.2.2 hr: 'hr', hrs: 'hrs' }; + var globalInit = false; var methods = { @@ -78,31 +87,45 @@ version: 1.2.2 self.data('timepicker-settings', settings); self.attr('autocomplete', 'off'); - self.click(methods.show).focus(methods.show).blur(_formatValue).keydown(_keyhandler); + self.on('click.timepicker focus.timepicker', methods.show); + self.on('blur.timepicker', _formatValue); + self.on('keydown.timepicker', _keyhandler); self.addClass('ui-timepicker-input'); - if (self.val()) { - var prettyTime = _int2time(_time2int(self.val()), settings.timeFormat); - self.val(prettyTime); + _formatValue.call(self.get(0)); + + if (!globalInit) { + // close the dropdown when container loses focus + $('body').on(_closeEvent, function(e) { + var target = $(e.target); + var input = target.closest('.ui-timepicker-input'); + if (input.length === 0 && target.closest('.ui-timepicker-list').length === 0) { + methods.hide(); + } + }); + globalInit = true; } - - // close the dropdown when container loses focus - $("body").attr("tabindex", -1).focusin(function(e) { - if ($(e.target).closest('.ui-timepicker-input').length == 0 && $(e.target).closest('.ui-timepicker-list').length == 0) { - methods.hide(); - } - }); - }); }, show: function(e) { var self = $(this); + + if ('ontouchstart' in document) { + // block the keyboard on mobile devices + self.blur(); + } + var list = self.data('timepicker-list'); + // check if input is readonly + if (self.attr('readonly')) { + return; + } + // check if list needs to be rendered - if (!list || list.length == 0) { + if (!list || list.length === 0) { _render(self); list = self.data('timepicker-list'); } @@ -121,16 +144,12 @@ version: 1.2.2 // make sure other pickers are hidden methods.hide(); - - var topMargin = parseInt(self.css('marginTop').slice(0, -2)); - if (!topMargin) topMargin = 0; // correct for IE returning "auto" - if ((self.offset().top + self.outerHeight(true) + list.outerHeight()) > $(window).height() + $(window).scrollTop()) { // position the dropdown on top - list.css({ 'left':(self.offset().left), 'top': self.offset().top + topMargin - list.outerHeight() }); + list.css({ 'left':(self.offset().left), 'top': self.offset().top - list.outerHeight() }); } else { // put it under the input - list.css({ 'left':(self.offset().left), 'top': self.offset().top + topMargin + self.outerHeight() }); + list.css({ 'left':(self.offset().left), 'top': self.offset().top + self.outerHeight() }); } list.show(); @@ -140,13 +159,13 @@ version: 1.2.2 var selected = list.find('.ui-timepicker-selected'); if (!selected.length) { - if (self.val()) { - selected = _findRow(self, list, _time2int(self.val())); - } else if (settings.minTime === null && settings.scrollDefaultNow) { - selected = _findRow(self, list, _time2int(new Date())); - } else if (settings.scrollDefaultTime !== false) { - selected = _findRow(self, list, _time2int(settings.scrollDefaultTime)); - } + if (self.val()) { + selected = _findRow(self, list, _time2int(self.val())); + } else if (settings.scrollDefaultNow) { + selected = _findRow(self, list, _time2int(new Date())); + } else if (settings.scrollDefaultTime !== false) { + selected = _findRow(self, list, _time2int(settings.scrollDefaultTime)); + } } if (selected && selected.length) { @@ -165,7 +184,8 @@ version: 1.2.2 var list = $(this); var self = list.data('timepicker-input'); var settings = self.data('timepicker-settings'); - if (settings.selectOnBlur) { + + if (settings && settings.selectOnBlur) { _selectValue(self); } @@ -226,8 +246,29 @@ version: 1.2.2 var self = $(this); var prettyTime = _int2time(_time2int(value), self.data('timepicker-settings').timeFormat); self.val(prettyTime); - } + }, + remove: function() + { + var self = $(this); + + // check if this element is a timepicker + if (!self.hasClass('ui-timepicker-input')) { + return; + } + + self.removeAttr('autocomplete', 'off'); + self.removeClass('ui-timepicker-input'); + self.removeData('timepicker-settings'); + self.off('.timepicker'); + + // timepicker-list won't be present unless the user has interacted with this timepicker + if (self.data('timepicker-list')) { + self.data('timepicker-list').remove(); + } + + self.removeData('timepicker-list'); + } }; // private methods @@ -251,7 +292,7 @@ version: 1.2.2 list.css({'display':'none', 'position': 'absolute' }); - if (settings.minTime !== null && settings.showDuration) { + if ((settings.minTime !== null || settings.durationTime !== null) && settings.showDuration) { list.addClass('ui-timepicker-with-duration'); } @@ -267,14 +308,14 @@ version: 1.2.2 for (var i=start; i <= end; i += settings.step*60) { var timeInt = i%_ONE_DAY; var row = $('
  • '); - row.data('time', timeInt) + row.data('time', timeInt); row.text(_int2time(timeInt, settings.timeFormat)); - if (settings.minTime !== null && settings.showDuration) { + if ((settings.minTime !== null || settings.durationTime !== null) && settings.showDuration) { var duration = $(''); duration.addClass('ui-timepicker-duration'); duration.text(' ('+_int2duration(i - durStart)+')'); - row.append(duration) + row.append(duration); } list.append(row); @@ -283,10 +324,16 @@ version: 1.2.2 list.data('timepicker-input', self); self.data('timepicker-list', list); - $('body').append(list); + var appendTo = settings.appendTo; + if (typeof appendTo === 'string') { + appendTo = $(appendTo); + } else if (typeof appendTo === 'function') { + appendTo = appendTo(self); + } + appendTo.append(list); _setSelected(self, list); - list.delegate('li', 'click', { 'timepicker': self }, function(e) { + list.on('click', 'li', function(e) { self.addClass('ui-timepicker-hideme'); self[0].focus(); @@ -297,7 +344,17 @@ version: 1.2.2 _selectValue(self); list.hide(); }); - }; + } + + function _generateBaseDate() + { + var _baseDate = new Date(); + var _currentTimezoneOffset = _baseDate.getTimezoneOffset()*60000; + _baseDate.setHours(0); _baseDate.setMinutes(0); _baseDate.setSeconds(0); + var _baseDateTimezoneOffset = _baseDate.getTimezoneOffset()*60000; + + return new Date(_baseDate.valueOf() - _baseDateTimezoneOffset + _currentTimezoneOffset); + } function _findRow(self, list, value) { @@ -307,13 +364,16 @@ version: 1.2.2 var settings = self.data('timepicker-settings'); var out = false; + var halfStep = settings.step*30; // loop through the menu items list.find('li').each(function(i, obj) { var jObj = $(obj); + var offset = jObj.data('time') - value; + // check if the value is less than half a step from each row - if (Math.abs(jObj.data('time') - value) <= settings.step*30) { + if (Math.abs(offset) < halfStep || offset == halfStep) { out = jObj; return false; } @@ -333,12 +393,33 @@ version: 1.2.2 function _formatValue() { - if (this.value == '') { + if (this.value === '') { return; } var self = $(this); - var prettyTime = _int2time(_time2int(this.value), self.data('timepicker-settings').timeFormat); + var seconds = _time2int(this.value); + + if (seconds === null) { + self.trigger('timeFormatError'); + return; + } + + var settings = self.data('timepicker-settings'); + + if (settings.forceRoundTime) { + var offset = seconds % (settings.step*60); // step is in minutes + + if (offset >= settings.step*30) { + // if offset is larger than a half step, round up + seconds += (settings.step*60) - offset; + } else { + // round down + seconds -= offset; + } + } + + var prettyTime = _int2time(seconds, settings.timeFormat); self.val(prettyTime); } @@ -353,7 +434,7 @@ version: 1.2.2 } else { return true; } - }; + } switch (e.keyCode) { @@ -362,13 +443,11 @@ version: 1.2.2 methods.hide.apply(this); e.preventDefault(); return false; - break; case 38: // up var selected = list.find('.ui-timepicker-selected'); if (!selected.length) { - var selected; list.children().each(function(i, obj) { if ($(obj).position().top > 0) { selected = $(obj); @@ -389,10 +468,9 @@ version: 1.2.2 break; case 40: // down - var selected = list.find('.ui-timepicker-selected'); + selected = list.find('.ui-timepicker-selected'); - if (selected.length == 0) { - var selected; + if (selected.length === 0) { list.children().each(function(i, obj) { if ($(obj).position().top > 0) { selected = $(obj); @@ -417,7 +495,10 @@ version: 1.2.2 list.hide(); break; - case 9: + case 9: //tab + methods.hide(); + break; + case 16: case 17: case 18: @@ -436,11 +517,11 @@ version: 1.2.2 list.find('li').removeClass('ui-timepicker-selected'); return; } - }; + } function _selectValue(self) { - var settings = self.data('timepicker-settings') + var settings = self.data('timepicker-settings'); var list = self.data('timepicker-list'); var timeValue = null; @@ -448,12 +529,12 @@ version: 1.2.2 if (cursor.length) { // selected value found - var timeValue = cursor.data('time'); + timeValue = cursor.data('time'); } else if (self.val()) { // no selected value; fall back on input value - var timeValue = _time2int(self.val()); + timeValue = _time2int(self.val()); _setSelected(self, list); } @@ -464,14 +545,14 @@ version: 1.2.2 } self.trigger('change').trigger('changeTime'); - }; + } function _int2duration(seconds) { var minutes = Math.round(seconds/60); var duration; - if (minutes < 60) { + if (Math.abs(minutes) < 60) { duration = [minutes, _lang.mins]; } else if (minutes == 60) { duration = ['1', _lang.hr]; @@ -482,16 +563,21 @@ version: 1.2.2 } return duration.join(' '); - }; + } function _int2time(seconds, format) { + if (seconds === null) { + return; + } + var time = new Date(_baseDate.valueOf() + (seconds*1000)); var output = ''; + var hour, code; for (var i=0; i 9) ? hour : '0'+hour; break; @@ -532,7 +618,7 @@ version: 1.2.2 break; case 's': - var seconds = time.getSeconds(); + seconds = time.getSeconds(); output += (seconds > 9) ? seconds : '0'+seconds; break; @@ -542,40 +628,42 @@ version: 1.2.2 } return output; - }; + } function _time2int(timeString) { - if (timeString == '') return null; + if (timeString === '') return null; if (timeString+0 == timeString) return timeString; if (typeof(timeString) == 'object') { - timeString = timeString.getHours()+':'+timeString.getMinutes(); + timeString = timeString.getHours()+':'+timeString.getMinutes()+':'+timeString.getSeconds(); } var d = new Date(0); - var time = timeString.toLowerCase().match(/(\d+)(?::(\d\d))?\s*([pa]?)/); + var time = timeString.toLowerCase().match(/(\d{1,2})(?::(\d{1,2}))?(?::(\d{2}))?\s*([pa]?)/); if (!time) { return null; } - var hour = parseInt(time[1]*1); + var hour = parseInt(time[1]*1, 10); + var hours; - if (time[3]) { + if (time[4]) { if (hour == 12) { - var hours = (time[3] == 'p') ? 12 : 0; + hours = (time[4] == 'p') ? 12 : 0; } else { - var hours = (hour + (time[3] == 'p' ? 12 : 0)); + hours = (hour + (time[4] == 'p' ? 12 : 0)); } } else { - var hours = hour; + hours = hour; } var minutes = ( time[2]*1 || 0 ); - return hours*3600 + minutes*60; - }; + var seconds = ( time[3]*1 || 0 ); + return hours*3600 + minutes*60 + seconds; + } // Plugin entry $.fn.timepicker = function(method) @@ -584,4 +672,4 @@ version: 1.2.2 else if(typeof method === "object" || !method) { return methods.init.apply(this, arguments); } else { $.error("Method "+ method + " does not exist on jQuery.timepicker"); } }; -})(jQuery); \ No newline at end of file +})); diff --git a/common/static/js/vendor/timepicker/jquery.timepicker.min.js b/common/static/js/vendor/timepicker/jquery.timepicker.min.js index 1678150ab1..53f80af4b2 100755 --- a/common/static/js/vendor/timepicker/jquery.timepicker.min.js +++ b/common/static/js/vendor/timepicker/jquery.timepicker.min.js @@ -1 +1 @@ -!function(e){function o(t){var r=t.data("timepicker-settings"),i=t.data("timepicker-list");i&&i.length&&(i.remove(),t.data("timepicker-list",!1)),i=e("
      "),i.attr("tabindex",-1),i.addClass("ui-timepicker-list"),r.className&&i.addClass(r.className),i.css({display:"none",position:"absolute"}),r.minTime!==null&&r.showDuration&&i.addClass("ui-timepicker-with-duration");var s=r.durationTime!==null?r.durationTime:r.minTime,o=r.minTime!==null?r.minTime:0,u=r.maxTime!==null?r.maxTime:o+n-1;u<=o&&(u+=n);for(var f=o;f<=u;f+=r.step*60){var l=f%n,d=e("
    • ");d.data("time",l),d.text(p(l,r.timeFormat));if(r.minTime!==null&&r.showDuration){var v=e("");v.addClass("ui-timepicker-duration"),v.text(" ("+h(f-s)+")"),d.append(v)}i.append(d)}i.data("timepicker-input",t),t.data("timepicker-list",i),e("body").append(i),a(t,i),i.delegate("li","click",{timepicker:t},function(n){t.addClass("ui-timepicker-hideme"),t[0].focus(),i.find("li").removeClass("ui-timepicker-selected"),e(this).addClass("ui-timepicker-selected"),c(t),i.hide()})}function u(t,n,r){if(!r&&r!==0)return!1;var i=t.data("timepicker-settings"),s=!1;return n.find("li").each(function(t,n){var o=e(n);if(Math.abs(o.data("time")-r)<=i.step*30)return s=o,!1}),s}function a(e,t){var n=d(e.val()),r=u(e,t,n);r&&r.addClass("ui-timepicker-selected")}function f(){if(this.value=="")return;var t=e(this),n=p(d(this.value),t.data("timepicker-settings").timeFormat);t.val(n)}function l(t){var n=e(this),r=n.data("timepicker-list");if(!r.is(":visible")){if(t.keyCode!=40)return!0;n.focus()}switch(t.keyCode){case 13:return c(n),s.hide.apply(this),t.preventDefault(),!1;case 38:var i=r.find(".ui-timepicker-selected");if(!i.length){var i;r.children().each(function(t,n){if(e(n).position().top>0)return i=e(n),!1}),i.addClass("ui-timepicker-selected")}else i.is(":first-child")||(i.removeClass("ui-timepicker-selected"),i.prev().addClass("ui-timepicker-selected"),i.prev().position().top0)return i=e(n),!1}),i.addClass("ui-timepicker-selected")}else i.is(":last-child")||(i.removeClass("ui-timepicker-selected"),i.next().addClass("ui-timepicker-selected"),i.next().position().top+2*i.outerHeight()>r.outerHeight()&&r.scrollTop(r.scrollTop()+i.outerHeight()));break;case 27:r.find("li").removeClass("ui-timepicker-selected"),r.hide();break;case 9:case 16:case 17:case 18:case 19:case 20:case 33:case 34:case 35:case 36:case 37:case 39:case 45:return;default:r.find("li").removeClass("ui-timepicker-selected");return}}function c(e){var t=e.data("timepicker-settings"),n=e.data("timepicker-list"),r=null,i=n.find(".ui-timepicker-selected");if(i.length)var r=i.data("time");else if(e.val()){var r=d(e.val());a(e,n)}if(r!==null){var s=p(r,t.timeFormat);e.attr("value",s)}e.trigger("change").trigger("changeTime")}function h(e){var t=Math.round(e/60),n;if(t<60)n=[t,i.mins];else if(t==60)n=["1",i.hr];else{var r=(t/60).toFixed(1);i.decimal!="."&&(r=r.replace(".",i.decimal)),n=[r,i.hrs]}return n.join(" ")}function p(e,n){var r=new Date(t.valueOf()+e*1e3),i="";for(var s=0;s11?"pm":"am";break;case"A":i+=r.getHours()>11?"PM":"AM";break;case"g":var u=r.getHours()%12;i+=u==0?"12":u;break;case"G":i+=r.getHours();break;case"h":var u=r.getHours()%12;u!=0&&u<10&&(u="0"+u),i+=u==0?"12":u;break;case"H":var u=r.getHours();i+=u>9?u:"0"+u;break;case"i":var a=r.getMinutes();i+=a>9?a:"0"+a;break;case"s":var e=r.getSeconds();i+=e>9?e:"0"+e;break;default:i+=o}}return i}function d(e){if(e=="")return null;if(e+0==e)return e;typeof e=="object"&&(e=e.getHours()+":"+e.getMinutes());var t=new Date(0),n=e.toLowerCase().match(/(\d+)(?::(\d\d))?\s*([pa]?)/);if(!n)return null;var r=parseInt(n[1]*1);if(n[3])if(r==12)var i=n[3]=="p"?12:0;else var i=r+(n[3]=="p"?12:0);else var i=r;var s=n[2]*1||0;return i*3600+s*60}var t=new Date;t.setHours(0),t.setMinutes(0),t.setSeconds(0);var n=86400,r={className:null,minTime:null,maxTime:null,durationTime:null,step:30,showDuration:!1,timeFormat:"g:ia",scrollDefaultNow:!1,scrollDefaultTime:!1,selectOnBlur:!1},i={decimal:".",mins:"mins",hr:"hr",hrs:"hrs"},s={init:function(t){return this.each(function(){var n=e(this);if(n[0].tagName=="SELECT"){var o=e(""),u={type:"text",value:n.val()},a=n[0].attributes;for(var c=0;ce(window).height()+e(window).scrollTop()?r.css({left:n.offset().left,top:n.offset().top+i-r.outerHeight()}):r.css({left:n.offset().left,top:n.offset().top+i+n.outerHeight()}),r.show();var a=n.data("timepicker-settings"),f=r.find(".ui-timepicker-selected");f.length||(n.val()?f=u(n,r,d(n.val())):a.minTime===null&&a.scrollDefaultNow?f=u(n,r,d(new Date)):a.scrollDefaultTime!==!1&&(f=u(n,r,d(a.scrollDefaultTime))));if(f&&f.length){var l=r.scrollTop()+f.position().top-f.outerHeight();r.scrollTop(l)}else r.scrollTop(0);n.trigger("showTimepicker")},hide:function(t){e(".ui-timepicker-list:visible").each(function(){var t=e(this),n=t.data("timepicker-input"),r=n.data("timepicker-settings");r.selectOnBlur&&c(n),t.hide(),n.trigger("hideTimepicker")})},option:function(t,n){var r=e(this),i=r.data("timepicker-settings"),s=r.data("timepicker-list");if(typeof t=="object")i=e.extend(i,t);else if(typeof t=="string"&&typeof n!="undefined")i[t]=n;else if(typeof t=="string")return i[t];i.minTime&&(i.minTime=d(i.minTime)),i.maxTime&&(i.maxTime=d(i.maxTime)),i.durationTime&&(i.durationTime=d(i.durationTime)),r.data("timepicker-settings",i),s&&(s.remove(),r.data("timepicker-list",!1))},getSecondsFromMidnight:function(){return d(e(this).val())},getTime:function(){return new Date(t.valueOf()+d(e(this).val())*1e3)},setTime:function(t){var n=e(this),r=p(d(t),n.data("timepicker-settings").timeFormat);n.val(r)}};e.fn.timepicker=function(t){if(s[t])return s[t].apply(this,Array.prototype.slice.call(arguments,1));if(typeof t=="object"||!t)return s.init.apply(this,arguments);e.error("Method "+t+" does not exist on jQuery.timepicker")}}(jQuery) \ No newline at end of file +(function(e){typeof define=="function"&&define.amd?define(["jquery"],e):e(jQuery)})(function(e){function a(t){var r=t.data("timepicker-settings"),i=t.data("timepicker-list");i&&i.length&&(i.remove(),t.data("timepicker-list",!1)),i=e("
        "),i.attr("tabindex",-1),i.addClass("ui-timepicker-list"),r.className&&i.addClass(r.className),i.css({display:"none",position:"absolute"}),(r.minTime!==null||r.durationTime!==null)&&r.showDuration&&i.addClass("ui-timepicker-with-duration");var s=r.durationTime!==null?r.durationTime:r.minTime,o=r.minTime!==null?r.minTime:0,u=r.maxTime!==null?r.maxTime:o+n-1;u<=o&&(u+=n);for(var a=o;a<=u;a+=r.step*60){var f=a%n,l=e("
      • ");l.data("time",f),l.text(m(f,r.timeFormat));if((r.minTime!==null||r.durationTime!==null)&&r.showDuration){var h=e("");h.addClass("ui-timepicker-duration"),h.text(" ("+v(a-s)+")"),l.append(h)}i.append(l)}i.data("timepicker-input",t),t.data("timepicker-list",i);var p=r.appendTo;typeof p=="string"?p=e(p):typeof p=="function"&&(p=p(t)),p.append(i),c(t,i),i.on("click","li",function(n){t.addClass("ui-timepicker-hideme"),t[0].focus(),i.find("li").removeClass("ui-timepicker-selected"),e(this).addClass("ui-timepicker-selected"),d(t),i.hide()})}function f(){var e=new Date,t=e.getTimezoneOffset()*6e4;e.setHours(0),e.setMinutes(0),e.setSeconds(0);var n=e.getTimezoneOffset()*6e4;return new Date(e.valueOf()-n+t)}function l(t,n,r){if(!r&&r!==0)return!1;var i=t.data("timepicker-settings"),s=!1,o=i.step*30;return n.find("li").each(function(t,n){var i=e(n),u=i.data("time")-r;if(Math.abs(u)=r.step*30?n+=r.step*60-i:n-=i}var s=m(n,r.timeFormat);t.val(s)}function p(t){var n=e(this),r=n.data("timepicker-list");if(!r.is(":visible")){if(t.keyCode!=40)return!0;n.focus()}switch(t.keyCode){case 13:return d(n),u.hide.apply(this),t.preventDefault(),!1;case 38:var i=r.find(".ui-timepicker-selected");i.length?i.is(":first-child")||(i.removeClass("ui-timepicker-selected"),i.prev().addClass("ui-timepicker-selected"),i.prev().position().top0)return i=e(n),!1}),i.addClass("ui-timepicker-selected"));break;case 40:i=r.find(".ui-timepicker-selected"),i.length===0?(r.children().each(function(t,n){if(e(n).position().top>0)return i=e(n),!1}),i.addClass("ui-timepicker-selected")):i.is(":last-child")||(i.removeClass("ui-timepicker-selected"),i.next().addClass("ui-timepicker-selected"),i.next().position().top+2*i.outerHeight()>r.outerHeight()&&r.scrollTop(r.scrollTop()+i.outerHeight()));break;case 27:r.find("li").removeClass("ui-timepicker-selected"),r.hide();break;case 9:u.hide();break;case 16:case 17:case 18:case 19:case 20:case 33:case 34:case 35:case 36:case 37:case 39:case 45:return;default:r.find("li").removeClass("ui-timepicker-selected");return}}function d(e){var t=e.data("timepicker-settings"),n=e.data("timepicker-list"),r=null,i=n.find(".ui-timepicker-selected");i.length?r=i.data("time"):e.val()&&(r=g(e.val()),c(e,n));if(r!==null){var s=m(r,t.timeFormat);e.attr("value",s)}e.trigger("change").trigger("changeTime")}function v(e){var t=Math.round(e/60),n;if(Math.abs(t)<60)n=[t,s.mins];else if(t==60)n=["1",s.hr];else{var r=(t/60).toFixed(1);s.decimal!="."&&(r=r.replace(".",s.decimal)),n=[r,s.hrs]}return n.join(" ")}function m(e,n){if(e===null)return;var r=new Date(t.valueOf()+e*1e3),i="",s,o;for(var u=0;u11?"pm":"am";break;case"A":i+=r.getHours()>11?"PM":"AM";break;case"g":s=r.getHours()%12,i+=s===0?"12":s;break;case"G":i+=r.getHours();break;case"h":s=r.getHours()%12,s!==0&&s<10&&(s="0"+s),i+=s===0?"12":s;break;case"H":s=r.getHours(),i+=s>9?s:"0"+s;break;case"i":var a=r.getMinutes();i+=a>9?a:"0"+a;break;case"s":e=r.getSeconds(),i+=e>9?e:"0"+e;break;default:i+=o}}return i}function g(e){if(e==="")return null;if(e+0==e)return e;typeof e=="object"&&(e=e.getHours()+":"+e.getMinutes()+":"+e.getSeconds());var t=new Date(0),n=e.toLowerCase().match(/(\d{1,2})(?::(\d{1,2}))?(?::(\d{2}))?\s*([pa]?)/);if(!n)return null;var r=parseInt(n[1]*1,10),i;n[4]?r==12?i=n[4]=="p"?12:0:i=r+(n[4]=="p"?12:0):i=r;var s=n[2]*1||0,o=n[3]*1||0;return i*3600+s*60+o}var t=f(),n=86400,r="ontouchstart"in document?"touchstart":"mousedown",i={className:null,minTime:null,maxTime:null,durationTime:null,step:30,showDuration:!1,timeFormat:"g:ia",scrollDefaultNow:!1,scrollDefaultTime:!1,selectOnBlur:!1,forceRoundTime:!1,appendTo:"body"},s={decimal:".",mins:"mins",hr:"hr",hrs:"hrs"},o=!1,u={init:function(t){return this.each(function(){var n=e(this);if(n[0].tagName=="SELECT"){var a=e(""),f={type:"text",value:n.val()},l=n[0].attributes;for(var c=0;ce(window).height()+e(window).scrollTop()?r.css({left:n.offset().left,top:n.offset().top-r.outerHeight()}):r.css({left:n.offset().left,top:n.offset().top+n.outerHeight()}),r.show();var i=n.data("timepicker-settings"),s=r.find(".ui-timepicker-selected");s.length||(n.val()?s=l(n,r,g(n.val())):i.scrollDefaultNow?s=l(n,r,g(new Date)):i.scrollDefaultTime!==!1&&(s=l(n,r,g(i.scrollDefaultTime))));if(s&&s.length){var o=r.scrollTop()+s.position().top-s.outerHeight();r.scrollTop(o)}else r.scrollTop(0);n.trigger("showTimepicker")},hide:function(t){e(".ui-timepicker-list:visible").each(function(){var t=e(this),n=t.data("timepicker-input"),r=n.data("timepicker-settings");r&&r.selectOnBlur&&d(n),t.hide(),n.trigger("hideTimepicker")})},option:function(t,n){var r=e(this),i=r.data("timepicker-settings"),s=r.data("timepicker-list");if(typeof t=="object")i=e.extend(i,t);else if(typeof t=="string"&&typeof n!="undefined")i[t]=n;else if(typeof t=="string")return i[t];i.minTime&&(i.minTime=g(i.minTime)),i.maxTime&&(i.maxTime=g(i.maxTime)),i.durationTime&&(i.durationTime=g(i.durationTime)),r.data("timepicker-settings",i),s&&(s.remove(),r.data("timepicker-list",!1))},getSecondsFromMidnight:function(){return g(e(this).val())},getTime:function(){return new Date(t.valueOf()+g(e(this).val())*1e3)},setTime:function(t){var n=e(this),r=m(g(t),n.data("timepicker-settings").timeFormat);n.val(r)},remove:function(){var t=e(this);if(!t.hasClass("ui-timepicker-input"))return;t.removeAttr("autocomplete","off"),t.removeClass("ui-timepicker-input"),t.removeData("timepicker-settings"),t.off(".timepicker"),t.data("timepicker-list")&&t.data("timepicker-list").remove(),t.removeData("timepicker-list")}};e.fn.timepicker=function(t){if(u[t])return u[t].apply(this,Array.prototype.slice.call(arguments,1));if(typeof t=="object"||!t)return u.init.apply(this,arguments);e.error("Method "+t+" does not exist on jQuery.timepicker")}}); \ No newline at end of file From bcafc5fdfb15a1f679a905a70d31f0524774fc33 Mon Sep 17 00:00:00 2001 From: cahrens Date: Thu, 10 Jan 2013 11:07:11 -0500 Subject: [PATCH 12/14] Bug fix for modal cover not going way when click outside of edit (#106). --- .../coffee/src/views/module_edit.coffee | 8 ++++-- cms/static/js/base.js | 28 ++++++------------- 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/cms/static/coffee/src/views/module_edit.coffee b/cms/static/coffee/src/views/module_edit.coffee index b1157f713e..729c4dc2e9 100644 --- a/cms/static/coffee/src/views/module_edit.coffee +++ b/cms/static/coffee/src/views/module_edit.coffee @@ -56,7 +56,7 @@ class CMS.Views.ModuleEdit extends Backbone.View event.preventDefault() data = @module.save() data.metadata = _.extend(data.metadata, @metadata()) - $modalCover.hide() + @hideModal() @model.save(data).done( => # # showToastMessage("Your changes have been saved.", null, 3) @module = null @@ -70,11 +70,15 @@ class CMS.Views.ModuleEdit extends Backbone.View event.preventDefault() @$el.removeClass('editing') @$component_editor().slideUp(150) + @hideModal() + + hideModal: -> $modalCover.hide() + $modalCover.removeClass('is-fixed') clickEditButton: (event) -> event.preventDefault() @$el.addClass('editing') - $modalCover.show() + $modalCover.show().addClass('is-fixed') @$component_editor().slideDown(150) @loadEdit() diff --git a/cms/static/js/base.js b/cms/static/js/base.js index 9fa4489c36..81e37bed72 100644 --- a/cms/static/js/base.js +++ b/cms/static/js/base.js @@ -29,9 +29,7 @@ $(document).ready(function() { $('.expand-collapse-icon').bind('click', toggleSubmodules); $('.visibility-options').bind('change', setVisibility); - $('.unit-history ol a').bind('click', showHistoryModal); $modal.bind('click', hideModal); - $modalCover.bind('click', hideHistoryModal); $modalCover.bind('click', hideModal); $('.assets .upload-button').bind('click', showUploadModal); $('.upload-modal .close-button').bind('click', hideModal); @@ -498,9 +496,14 @@ function hideModal(e) { if(e) { e.preventDefault(); } - $('.file-input').unbind('change', startUpload); - $modal.hide(); - $modalCover.hide(); + // Unit editors do not want the modal cover to hide when users click outside + // of the editor. Users must press Cancel or Save to exit the editor. + // module_edit adds and removes the "is-fixed" class. + if (!$modalCover.hasClass("is-fixed")) { + $('.file-input').unbind('change', startUpload); + $modal.hide(); + $modalCover.hide(); + } } function onKeyUp(e) { @@ -530,21 +533,6 @@ function closeComponentEditor(e) { $(this).closest('.xmodule_edit').removeClass('editing').find('.component-editor').slideUp(150); } - -function showHistoryModal(e) { - e.preventDefault(); - - $modal.show(); - $modalCover.show(); -} - -function hideHistoryModal(e) { - e.preventDefault(); - - $modal.hide(); - $modalCover.hide(); -} - function showDateSetter(e) { e.preventDefault(); var $block = $(this).closest('.due-date-input'); From 4128f37a1f32cc29ab0f97a45db3de22b5588e20 Mon Sep 17 00:00:00 2001 From: Brian Talbot Date: Thu, 10 Jan 2013 13:18:26 -0500 Subject: [PATCH 13/14] studio - moving a component's static view visually below modal while editing --- cms/static/sass/_unit.scss | 11 ++++++++--- cms/templates/component.html | 18 +++++++++++------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/cms/static/sass/_unit.scss b/cms/static/sass/_unit.scss index 62586a2baf..23d708dbc1 100644 --- a/cms/static/sass/_unit.scss +++ b/cms/static/sass/_unit.scss @@ -245,8 +245,8 @@ &.editing { border: 1px solid $lightBluishGrey2; - z-index: 9999; - + z-index: auto; + .drag-handle, .component-actions { display: none; @@ -284,12 +284,17 @@ overflow-x: auto; } + .wrapper-component-editor { + z-index: 9999; + position: relative; + } + .component-editor { @include edit-box; + @include box-shadow(none); display: none; padding: 20px; border-radius: 2px 2px 0 0; - @include box-shadow(none); .metadata_edit { margin-bottom: 20px; diff --git a/cms/templates/component.html b/cms/templates/component.html index b7ad9c3c33..639d22ea12 100644 --- a/cms/templates/component.html +++ b/cms/templates/component.html @@ -1,13 +1,17 @@ -
        -
        - ${editor} -
        - Save - Cancel +
        +
        +
        + ${editor} +
        + Save + Cancel +
        + -${preview} \ No newline at end of file +${preview} + From 76059b52e7a657bff633d5346612f67d984e7aae Mon Sep 17 00:00:00 2001 From: Chris Dodge Date: Thu, 10 Jan 2013 13:24:40 -0500 Subject: [PATCH 14/14] make sure we commit the course module first when importing. There's a sneaky little ordering dependency where we can't save a static tabe until the course module has been saved. This is because - when saving a static tab - we have to scribble on the course module's metadata to point to it. --- .../xmodule/modulestore/xml_importer.py | 95 ++++++++++++------- 1 file changed, 60 insertions(+), 35 deletions(-) diff --git a/common/lib/xmodule/xmodule/modulestore/xml_importer.py b/common/lib/xmodule/xmodule/modulestore/xml_importer.py index 35375d7c51..2fd70f68cd 100644 --- a/common/lib/xmodule/xmodule/modulestore/xml_importer.py +++ b/common/lib/xmodule/xmodule/modulestore/xml_importer.py @@ -120,47 +120,16 @@ def import_from_xml(store, data_dir, course_dirs=None, course_data_path = None course_location = None - # Quick scan to get course Location as well as the course_data_path + + # Quick scan to get course module as we need some info from there. Also we need to make sure that the + # course module is committed first into the store for module in module_store.modules[course_id].itervalues(): if module.category == 'course': course_data_path = path(data_dir) / module.metadata['data_dir'] course_location = module.location - if static_content_store is not None: - _namespace_rename = target_location_namespace if target_location_namespace is not None else module_store.modules[course_id].location - - # first pass to find everything in /static/ - import_static_content(module_store.modules[course_id], course_location, course_data_path, static_content_store, - _namespace_rename, subpath='static') + module = remap_namespace(module, target_location_namespace) - for module in module_store.modules[course_id].itervalues(): - - # remap module to the new namespace - if target_location_namespace is not None: - # This looks a bit wonky as we need to also change the 'name' of the imported course to be what - # the caller passed in - if module.location.category != 'course': - module.location = module.location._replace(tag=target_location_namespace.tag, org=target_location_namespace.org, - course=target_location_namespace.course) - else: - module.location = module.location._replace(tag=target_location_namespace.tag, org=target_location_namespace.org, - course=target_location_namespace.course, name=target_location_namespace.name) - - # then remap children pointers since they too will be re-namespaced - children_locs = module.definition.get('children') - if children_locs is not None: - new_locs = [] - for child in children_locs: - child_loc = Location(child) - new_child_loc = child_loc._replace(tag=target_location_namespace.tag, org=target_location_namespace.org, - course=target_location_namespace.course) - - new_locs.append(new_child_loc.url()) - - module.definition['children'] = new_locs - - - if module.category == 'course': # HACK: for now we don't support progress tabs. There's a special metadata configuration setting for this. module.metadata['hide_progress_tab'] = True @@ -174,12 +143,41 @@ def import_from_xml(store, data_dir, course_dirs=None, {"type": "discussion", "name": "Discussion"}, {"type": "wiki", "name": "Wiki"}] # note, add 'progress' when we can support it on Edge + + store.update_item(module.location, module.definition['data']) + if 'children' in module.definition: + store.update_children(module.location, module.definition['children']) + store.update_metadata(module.location, dict(module.own_metadata)) + # a bit of a hack, but typically the "course image" which is shown on marketing pages is hard coded to /images/course_image.jpg # so let's make sure we import in case there are no other references to it in the modules verify_content_links(module, course_data_path, static_content_store, '/static/images/course_image.jpg') course_items.append(module) + + + # then import all the static content + if static_content_store is not None: + _namespace_rename = target_location_namespace if target_location_namespace is not None else module_store.modules[course_id].location + + # first pass to find everything in /static/ + import_static_content(module_store.modules[course_id], course_location, course_data_path, static_content_store, + _namespace_rename, subpath='static') + + # finally loop through all the modules + for module in module_store.modules[course_id].itervalues(): + + if module.category == 'course': + # we've already saved the course module up at the top of the loop + # so just skip over it in the inner loop + continue + + # remap module to the new namespace + if target_location_namespace is not None: + module = remap_namespace(module, target_location_namespace) + + if 'data' in module.definition: module_data = module.definition['data'] @@ -216,6 +214,33 @@ def import_from_xml(store, data_dir, course_dirs=None, return module_store, course_items +def remap_namespace(module, target_location_namespace): + if target_location_namespace is None: + return module + + # This looks a bit wonky as we need to also change the 'name' of the imported course to be what + # the caller passed in + if module.location.category != 'course': + module.location = module.location._replace(tag=target_location_namespace.tag, org=target_location_namespace.org, + course=target_location_namespace.course) + else: + module.location = module.location._replace(tag=target_location_namespace.tag, org=target_location_namespace.org, + course=target_location_namespace.course, name=target_location_namespace.name) + + # then remap children pointers since they too will be re-namespaced + children_locs = module.definition.get('children') + if children_locs is not None: + new_locs = [] + for child in children_locs: + child_loc = Location(child) + new_child_loc = child_loc._replace(tag=target_location_namespace.tag, org=target_location_namespace.org, + course=target_location_namespace.course) + + new_locs.append(new_child_loc.url()) + + module.definition['children'] = new_locs + + return module def validate_category_hierarcy(module_store, course_id, parent_category, expected_child_category): err_cnt = 0