From 5c223a20c1c36ed7d100f8bacbd85665207e06bd Mon Sep 17 00:00:00 2001 From: Logan Hanks Date: Fri, 20 Jul 2012 16:28:25 -0700 Subject: [PATCH] Update page when an app is created or updated. --- r2/r2/controllers/api.py | 13 ++-- r2/r2/lib/pages/pages.py | 7 -- r2/r2/lib/wrapped.pyx | 7 ++ r2/r2/public/static/css/reddit.css | 30 ++++---- r2/r2/public/static/js/apps.js | 28 ++++---- r2/r2/templates/appdeveloper.html | 12 ---- r2/r2/templates/prefapps.html | 109 +++++++++++++++++------------ 7 files changed, 115 insertions(+), 91 deletions(-) delete mode 100644 r2/r2/templates/appdeveloper.html diff --git a/r2/r2/controllers/api.py b/r2/r2/controllers/api.py index 6b94bf583..42dc8195a 100755 --- a/r2/r2/controllers/api.py +++ b/r2/r2/controllers/api.py @@ -40,7 +40,7 @@ from r2.lib.pages import EnemyList, FriendList, ContributorList, ModList, \ UrlParser, WrappedUser, BoringPage from r2.lib.pages import FlairList, FlairCsv, FlairTemplateEditor, \ FlairSelector -from r2.lib.pages import AppDeveloper +from r2.lib.pages import PrefApps from r2.lib.utils.trial_utils import indict, end_trial, trial_info from r2.lib.pages.things import wrap_links, default_thing_wrapper from r2.models.last_modified import LastModified @@ -2862,20 +2862,24 @@ class ApiController(RedditController, OAuth2ResourceController): client.name = name client.description = description client.about_url = about_url or '' - client.icon_url = icon_url or '' client.redirect_uri = redirect_uri client._commit() form.set_html('.status', _('application updated')) + apps = PrefApps([], [client]) + jquery('#developed-app-%s' % client._id).replaceWith( + apps.call('developed_app', client, collapsed=False)) else: # client_id was omitted or empty, creating new OAuth2Client client = OAuth2Client._new(name=name, description=description, about_url=about_url or '', - icon_url=icon_url or '', redirect_uri=redirect_uri) client._commit() client.add_developer(c.user) form.set_html('.status', _('application created')) + apps = PrefApps([], [client]) + jquery('#developed-apps ul').append( + apps.call('developed_app', client, collapsed=False)) @validatedForm(VUser(), VModhash(), @@ -2894,9 +2898,10 @@ class ApiController(RedditController, OAuth2ResourceController): return client.add_developer(account) form.set_html('.status', _('developer added')) + apps = PrefApps([], [client]) (jquery('#app-developer-%s input[name="name"]' % client._id).val('') .closest('.prefright').find('ul').append( - AppDeveloper(client, account).render(style='html'))) + apps.call('editable_developer', client, account))) @validatedForm(VUser(), VModhash(), diff --git a/r2/r2/lib/pages/pages.py b/r2/r2/lib/pages/pages.py index 675448ab9..c5f67e0c6 100755 --- a/r2/r2/lib/pages/pages.py +++ b/r2/r2/lib/pages/pages.py @@ -664,15 +664,8 @@ class PrefApps(Templated): def __init__(self, my_apps, developed_apps): self.my_apps = my_apps self.developed_apps = developed_apps - self.can_upload_icon = media.can_upload_icon() super(PrefApps, self).__init__() -class AppDeveloper(Templated): - def __init__(self, app, dev): - self.app = app - self.dev = dev - super(AppDeveloper, self).__init__() - class PrefDelete(Templated): """Preference form for deleting a user's own account.""" pass diff --git a/r2/r2/lib/wrapped.pyx b/r2/r2/lib/wrapped.pyx index cad505c63..a6b6e6500 100644 --- a/r2/r2/lib/wrapped.pyx +++ b/r2/r2/lib/wrapped.pyx @@ -400,6 +400,13 @@ class Templated(object): if style: del kw['style'] return self._render(attr, style, **kw) + def call(self, name, *args, **kwargs): + from pylons import g + from r2.lib.filters import spaceCompress + res = self.template().get_def(name).render(*args, **kwargs) + if not g.template_debug: + res = spaceCompress(res) + return res class Uncachable(Exception): pass diff --git a/r2/r2/public/static/css/reddit.css b/r2/r2/public/static/css/reddit.css index 73d493c42..0b9ac7237 100755 --- a/r2/r2/public/static/css/reddit.css +++ b/r2/r2/public/static/css/reddit.css @@ -5847,6 +5847,7 @@ tr.gold-accent + tr > td { width: 880px; } +.developed-app.collapsed, .authorized-app { height: 100px; } .developed-app .collapsed { display: none; } .developed-app .ajax-upload-form { @@ -5854,11 +5855,10 @@ tr.gold-accent + tr > td { } .app-details { - position: absolute; - top: 7px; - left: 80px; + display: inline-block; + width: 200px; height: 72px; - margin-left: 0.5em; + margin-left: 1em; vertical-align: top; } @@ -5866,6 +5866,7 @@ tr.gold-accent + tr > td { .app-details h3 { font-size: x-small; } .app-icon { + display: inline-block; width: 72px; height: 72px; line-height: 72px; @@ -5877,27 +5878,32 @@ tr.gold-accent + tr > td { } .app-description { + display: inline-block; font-size: small; - position: absolute; - top: 0px; - left: 200px; - width: 600px; + width: 597px; + height: 80px; + overflow-y: auto; + vertical-align: top; } .app-developers { position: absolute; - left: 200px; - bottom: 0px; + left: 289px; + bottom: 1ex; width: 600px; } .edit-app-button, .revoke-app-button { position: absolute; - bottom: 0px; + bottom: 1ex; + left: 12px; width: 200px; } -.edit-app, .edit-app-icon, .developed-app .collapsed { display: none; } +.edit-app.collapsed, .edit-app-icon, .developed-app .collapsed { + display: none; +} + .edit-app-icon-button { display: block; text-align: center; width: 72px; } .edit-app-form, .edit-app-form form { display: inline-block; } .edit-app-form th, .edit-app-icon th { width: 12ex; } diff --git a/r2/r2/public/static/js/apps.js b/r2/r2/public/static/js/apps.js index bc51a9012..1ce022d13 100644 --- a/r2/r2/public/static/js/apps.js +++ b/r2/r2/public/static/js/apps.js @@ -1,21 +1,25 @@ $(function() { - $(".edit-app-button").click( - function() { - var app = $(this).closest(".developed-app"); - $(this).toggleClass("collapsed"); - app.find(".app-developers").remove(); - app.find(".edit-app").slideToggle(); - }); + $("#developed-apps") + .delegate(".edit-app-button", "click", + function() { + $(this).toggleClass("collapsed").closest(".developed-app") + .removeClass('collapsed') + .find(".app-developers").remove().end() + .find(".edit-app") + .slideToggle().removeClass('collapsed').end(); + }) + .delegate(".edit-app-icon-button", "click", + function() { + $(this).toggleClass("collapsed") + .closest(".developed-app") + .find(".ajax-upload-form").show(); + }); + $("#create-app-button").click( function() { $(this).hide(); $("#create-app").fadeIn(); }); - $(".edit-app-icon-button").click( - function() { - $(this).toggleClass("collapsed"); - $(this).closest(".developed-app").find(".ajax-upload-form").show(); - }); }); function app_revoked(elem, op) { diff --git a/r2/r2/templates/appdeveloper.html b/r2/r2/templates/appdeveloper.html deleted file mode 100644 index 132ddeb61..000000000 --- a/r2/r2/templates/appdeveloper.html +++ /dev/null @@ -1,12 +0,0 @@ -<%namespace file="printablebuttons.html" import="ajax_ynbutton" /> - -
  • -${thing.dev.name} -%if c.user == thing.dev: - (that's you!) -%else: - ${ajax_ynbutton(_("remove"), "removedeveloper", - hidden_data=dict(client_id=thing.app._id, - name=thing.dev.name))} -%endif -
  • diff --git a/r2/r2/templates/prefapps.html b/r2/r2/templates/prefapps.html index dc62d151f..c1796fbff 100644 --- a/r2/r2/templates/prefapps.html +++ b/r2/r2/templates/prefapps.html @@ -1,7 +1,6 @@ -<% from r2.lib.pages import AppDeveloper %> <%namespace name="utils" file="utils.html" /> <%namespace file="utils.html" import="error_field, plain_link" /> -<%namespace file="printablebuttons.html" import="ynbutton" /> +<%namespace file="printablebuttons.html" import="ajax_ynbutton, ynbutton" /> <%def name="icon(app)">
    @@ -28,39 +27,26 @@ %endif -%if thing.my_apps: -

    ${_("authorized applications")}

    +<%def name="editable_developer(app, dev)"> +
  • + ${dev.name} + %if c.user == dev: + ${_("(that's you!)")} + %else: + ${ajax_ynbutton(_("remove"), "removedeveloper", + hidden_data=dict(client_id=app._id, name=dev.name))} + %endif +
  • + - %for app in thing.my_apps: -
    - ${icon(app)} -
    -

    - %if app.about_url: - ${app.name} - %else: - ${app.name} - %endif -

    -
    ${app.description}
    - ${developers(app)} - ${ynbutton(_("revoke access"), - _("revoked"), - "revokeapp", - callback="app_revoked", - hidden_data=dict(client_id=app._id), - _class="revoke-app-button")} -
    -
    - %endfor -%endif - -%if thing.developed_apps: -

    ${_("developed applications")}

    - - %for app in thing.developed_apps: -
    +<%def name="developed_app(app, collapsed=True)"> + + + +%if thing.my_apps: +

    ${_("authorized applications")}

    + + %for app in thing.my_apps: +
    + ${icon(app)} +
    +

    + %if app.about_url: + ${app.name} + %else: + ${app.name} + %endif +

    +
    +
    ${app.description}
    + ${developers(app)} + ${ynbutton(_("revoke access"), + _("revoked"), + "revokeapp", + callback="r.apps.revoked", + hidden_data=dict(client_id=app._id), + _class="revoke-app-button")}
    %endfor -

    create another app...

    -%else: -

    are you a developer? create an app...

    %endif +
    + %if thing.developed_apps: +

    ${_("developed applications")}

    + +
      + %for app in thing.developed_apps: + ${developed_app(app)} + %endfor +
    + %endif +
    +