From c372c1fa13f564e282480cb4859a5901c0597105 Mon Sep 17 00:00:00 2001 From: Michal Kolodziejski Date: Wed, 22 Jul 2015 10:20:42 +0200 Subject: [PATCH] Add folder name suggestions --- .gitmodules | 6 +-- ext_modules/jquery-typeahead | 1 + ext_modules/selectize.js | 1 - fabfile.py | 15 +++--- indico/modules/attachments/forms.py | 12 +++-- .../attachments/templates/create_folder.html | 2 +- indico/modules/attachments/util.py | 21 ++++++++ indico/modules/vc/forms.py | 6 +-- indico/modules/vc/views.py | 4 +- indico/web/assets/bundles.py | 11 +--- indico/web/forms/widgets.py | 31 +++++++----- indico/web/templates/forms/selectize_widget.html | 41 --------------- indico/web/templates/forms/typeahead_widget.html | 59 ++++++++++++++++++++++ 13 files changed, 124 insertions(+), 86 deletions(-) create mode 160000 ext_modules/jquery-typeahead delete mode 160000 ext_modules/selectize.js delete mode 100644 indico/web/templates/forms/selectize_widget.html create mode 100644 indico/web/templates/forms/typeahead_widget.html diff --git a/.gitmodules b/.gitmodules index 1a180c482..efcc9f3c9 100644 --- a/.gitmodules +++ b/.gitmodules @@ -41,12 +41,12 @@ [submodule "ext_modules/zeroclipboard"] path = ext_modules/zeroclipboard url = https://github.com/zeroclipboard/zeroclipboard -[submodule "ext_modules/selectize.js"] - path = ext_modules/selectize.js - url = https://github.com/brianreavis/selectize.js.git [submodule "ext_modules/Jed"] path = ext_modules/Jed url = https://github.com/SlexAxton/Jed.git [submodule "ext_modules/dropzone"] path = ext_modules/dropzone url = https://github.com/enyo/dropzone.git +[submodule "ext_modules/jquery-typeahead"] + path = ext_modules/jquery-typeahead + url = https://github.com/running-coder/jquery-typeahead.git diff --git a/ext_modules/jquery-typeahead b/ext_modules/jquery-typeahead new file mode 160000 index 000000000..65561994d --- /dev/null +++ b/ext_modules/jquery-typeahead @@ -0,0 +1 @@ +Subproject commit 65561994de1e14c2c89847386fd951b792e47524 diff --git a/ext_modules/selectize.js b/ext_modules/selectize.js deleted file mode 160000 index cff8cd3b7..000000000 --- a/ext_modules/selectize.js +++ /dev/null @@ -1 +0,0 @@ -Subproject commit cff8cd3b76559bf8e5ce14254d07e719445034c1 diff --git a/fabfile.py b/fabfile.py index 2e35b8f14..9dc328b03 100644 --- a/fabfile.py +++ b/fabfile.py @@ -376,15 +376,14 @@ def install_dropzone_js(): local('cp dist/dropzone.css {0}/'.format(dest_css_dir)) -@recipe('selectize.js') -def install_selectize_js(): - with lcd(os.path.join(env.ext_dir, 'selectize.js')): - dest_js_dir = os.path.join(lib_dir(env.src_dir, 'js'), 'selectize.js/') - dest_css_dir = os.path.join(lib_dir(env.src_dir, 'css'), 'selectize.js/') +@recipe('jquery-typeahead') +def install_jquery_typeahead(): + with lcd(os.path.join(env.ext_dir, 'jquery-typeahead')): + dest_js_dir = lib_dir(env.src_dir, 'js') + dest_css_dir = lib_dir(env.src_dir, 'css') local('mkdir -p {0} {1}'.format(dest_js_dir, dest_css_dir)) - local('cp dist/js/standalone/selectize.js {0}/'.format(dest_js_dir)) - local('cp dist/css/selectize.css {0}/'.format(dest_css_dir)) - local('cp dist/css/selectize.default.css {0}/'.format(dest_css_dir)) + local('cp src/jquery.typeahead.js {0}'.format(dest_js_dir)) + local('cp src/jquery.typeahead.css {0}'.format(dest_css_dir)) # Tasks diff --git a/indico/modules/attachments/forms.py b/indico/modules/attachments/forms.py index ddb854b97..aea051bff 100644 --- a/indico/modules/attachments/forms.py +++ b/indico/modules/attachments/forms.py @@ -16,21 +16,23 @@ from __future__ import unicode_literals + from wtforms.ext.sqlalchemy.fields import QuerySelectField from wtforms.ext.dateutil.fields import DateField from wtforms.fields import BooleanField, TextAreaField from wtforms.fields.html5 import URLField -from wtforms.fields.simple import StringField +from wtforms.fields.simple import StringField, HiddenField from wtforms.validators import DataRequired, Optional from indico.core.db import db from indico.core.db.sqlalchemy.protection import ProtectionMode from indico.modules.attachments.models.folders import AttachmentFolder +from indico.modules.attachments.util import get_default_folder_names from indico.util.i18n import _ from indico.web.forms.base import IndicoForm, generated_data from indico.web.forms.fields import PrincipalListField, IndicoSelectMultipleCheckboxField from indico.web.forms.validators import UsedIf -from indico.web.forms.widgets import SwitchWidget +from indico.web.forms.widgets import SwitchWidget, TypeaheadWidget class AttachmentFormBase(IndicoForm): @@ -81,7 +83,7 @@ class EditAttachmentLinkForm(AttachmentLinkFormMixin, EditAttachmentFormBase): class AttachmentFolderForm(IndicoForm): - title = StringField(_("Name"), [DataRequired()], description=_("The name of the folder.")) + title = HiddenField(_("Name"), [DataRequired()], description=_("The name of the folder."), widget=TypeaheadWidget()) description = TextAreaField(_("Description"), description=_("Description of the folder and its content")) protected = BooleanField(_("Protected"), widget=SwitchWidget()) acl = PrincipalListField(_("Grant Access To"), [UsedIf(lambda form, field: form.protected.data)], @@ -92,6 +94,10 @@ class AttachmentFolderForm(IndicoForm): "access them. You can disable this behavior here, hiding the folder " "for anyone who does not have permission to access it.")) + def __init__(self, *args, **kwargs): + super(AttachmentFolderForm, self).__init__(*args, **kwargs) + self.title.choices = [{'name': value} for value in get_default_folder_names()] + @generated_data def protection_mode(self): return ProtectionMode.protected if self.protected.data else ProtectionMode.inheriting diff --git a/indico/modules/attachments/templates/create_folder.html b/indico/modules/attachments/templates/create_folder.html index 275ec9434..8afdac1bf 100644 --- a/indico/modules/attachments/templates/create_folder.html +++ b/indico/modules/attachments/templates/create_folder.html @@ -6,7 +6,7 @@ {{ form_rows(form, fields=('protected', 'acl')) }} {{ protection_message | safe }} {% call form_footer(attach_form) %} - + {% endcall %} -{% endblock %} diff --git a/indico/web/templates/forms/typeahead_widget.html b/indico/web/templates/forms/typeahead_widget.html new file mode 100644 index 000000000..842163ea6 --- /dev/null +++ b/indico/web/templates/forms/typeahead_widget.html @@ -0,0 +1,59 @@ +{% extends 'forms/base_widget.html' %} + +{% block html %} +
+
+ +
+
+{% endblock %} + +{% block javascript %} + +{% endblock %} -- 2.11.4.GIT