From 545e1c7a3bc3b07b8e6311ec101e1f0f25deb21e Mon Sep 17 00:00:00 2001 From: Logan Hanks Date: Wed, 11 Jul 2012 16:23:04 -0700 Subject: [PATCH] Clean up the developed apps UI. --- r2/r2/controllers/api.py | 17 ++- r2/r2/lib/js.py | 1 + r2/r2/public/static/css/reddit.css | 55 ++++++++ r2/r2/public/static/js/apps.js | 7 + r2/r2/templates/oauth2authorization.html | 9 +- r2/r2/templates/prefapps.html | 168 ++++++++++++++--------- 6 files changed, 184 insertions(+), 73 deletions(-) create mode 100644 r2/r2/public/static/js/apps.js diff --git a/r2/r2/controllers/api.py b/r2/r2/controllers/api.py index 88106809f..c74417f92 100755 --- a/r2/r2/controllers/api.py +++ b/r2/r2/controllers/api.py @@ -2878,16 +2878,25 @@ class ApiController(RedditController, OAuth2ResourceController): client=VOAuth2ClientDeveloper(), account=VExistingUnameNotSelf('name')) def POST_adddeveloper(self, form, jquery, client, account): - if client and not form.has_error('name'): - client.add_developer(account) - form.set_html('.status', _('developer added')) + if not client: + form.set_html('.status', _('error')) + return + if form.has_errors('name', errors.USER_DOESNT_EXIST, errors.NO_USER): + form.set_html('.status', _('invalid user')) + return + if client.has_developer(account): + form.set_html('.status', _('already added')) + return + client.add_developer(account) + form.set_html('.status', _('developer added')) @validatedForm(VUser(), VModhash(), client=VOAuth2ClientDeveloper(), account=VExistingUnameNotSelf('name')) def POST_removedeveloper(self, form, jquery, client, account): - if client and not form.has_error('name'): + if client and account and not form.has_errors('name'): + g.log.debug('removing developer: %s', account.name) client.remove_developer(account) form.set_html('.status', _('developer removed')) diff --git a/r2/r2/lib/js.py b/r2/r2/lib/js.py index e60528c23..66a2a2090 100755 --- a/r2/r2/lib/js.py +++ b/r2/r2/lib/js.py @@ -277,6 +277,7 @@ module["reddit"] = LocalizedModule("reddit.js", "flair.js", "interestbar.js", "reddit.js", + "apps.js", ) module["mobile"] = LocalizedModule("mobile.js", diff --git a/r2/r2/public/static/css/reddit.css b/r2/r2/public/static/css/reddit.css index e2044b5c7..b125c6352 100755 --- a/r2/r2/public/static/css/reddit.css +++ b/r2/r2/public/static/css/reddit.css @@ -5835,3 +5835,58 @@ tr.gold-accent + tr > td { color: gray; font-weight: bold; } + +.developed-app { + border: solid 1px black; + margin-left: 20px; + margin-bottom: 0.5em; + padding: 7px; + position: relative; + width: 880px; +} + +.developed-app .collapsed { display: none; } +.developed-app img { + height: 64px; + width: 64px; +} + +.app-details { + position: absolute; + top: 7px; + left: 80px; + height: 64px; + margin-left: 0.5em; + vertical-align: top; +} + +.app-details h2 { font-size: medium; } +.app-details h3 { font-size: x-small; } + +.app-description { + font-size: small; + position: absolute; + top: 0px; + left: 200px; + width: 600px; +} + +.edit-app-button { + position: absolute; + bottom: 0px; +} + +.edit-app { display: none; } +.edit-app-form, .edit-app-form form { display: inline-block; } +.edit-app-form input, .edit-app-form textarea { margin: 0px; width: 50ex; } +.edit-app-form input[name="name"] { width: 20ex !important; } +.edit-app-form input[type="submit"] { + margin-left: 10px; + width: auto !important; +} + +.delete-app-button { + position: absolute; + bottom: 7px; + left: 100px; +} diff --git a/r2/r2/public/static/js/apps.js b/r2/r2/public/static/js/apps.js new file mode 100644 index 000000000..dfe0e1359 --- /dev/null +++ b/r2/r2/public/static/js/apps.js @@ -0,0 +1,7 @@ +$(function() { + $(".edit-app-button").click( + function() { + $(this).toggleClass("collapsed"); + $(this).parent().parent().find(".edit-app").slideToggle(); + }); +}); diff --git a/r2/r2/templates/oauth2authorization.html b/r2/r2/templates/oauth2authorization.html index 82ba08428..e2781b025 100644 --- a/r2/r2/templates/oauth2authorization.html +++ b/r2/r2/templates/oauth2authorization.html @@ -26,8 +26,13 @@ <%namespace file="utils.html" import="_md" />
${thing.client.name} icon - ${_md("#[%(app_name)s](%(app_about_url)s) requests to connect with your reddit account." - % dict(app_name=thing.client.name, app_about_url=thing.client.about_url))} + %if thing.client.about_url: + ${_md("#[%(app_name)s](%(app_about_url)s) requests to connect with your reddit account." + % dict(app_name=thing.client.name, app_about_url=thing.client.about_url))} + %else: + ${_md("#%(app_name)s requests to connect with your reddit account." + % dict(app_name=thing.client.name))} + %endif

${_("Allow %(app_name)s to:") % dict(app_name=thing.client.name)}

    diff --git a/r2/r2/templates/prefapps.html b/r2/r2/templates/prefapps.html index a70e0e051..2a7131e20 100644 --- a/r2/r2/templates/prefapps.html +++ b/r2/r2/templates/prefapps.html @@ -26,59 +26,84 @@

    ${_("developed applications")}

    %for app in thing.developed_apps: -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +
    ${_("client id")}${app._id}
    ${_("secret")}${app.secret}
    ${_("name")} - - ${error_field("NO_TEXT", "name")} -
    ${_("description")} - -
    ${_("about url")} - - ${error_field("BAD_URL", "about_url")} -
    ${_("icon url")} - - ${error_field("BAD_URL", "icon_url")} -
    ${_("redirect uri")} - - ${error_field("NO_URL", "redirect_uri")} - ${error_field("BAD_URL", "redirect_uri")} -
    ${_("developers")} - %for dev in app._developers: -

    ${dev.name} +

    + %if app.icon_url: + + %endif +
    +

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

    +

    ${app._id}

    +
    ${app.description}
    + + ${_("edit")} + +
    +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    ${_("secret")}${app.secret}
    ${_("name")} + + ${error_field("NO_TEXT", "name")} +
    ${_("description")} + +
    ${_("about url")} + + ${error_field("BAD_URL", "about_url")} +
    ${_("icon url")} + + ${error_field("BAD_URL", "icon_url")} +
    ${_("redirect uri")} + + ${error_field("NO_URL", "redirect_uri")} + ${error_field("BAD_URL", "redirect_uri")} +
    + + + +
    +
    + + + + - -
    ${_("developers")} + %for dev in app._developers: + ${dev.name} %if c.user == dev: (that's you!) %else: @@ -88,26 +113,35 @@ hidden_data=dict(client_id=app._id, developer=dev._fullname))} %endif -

    - %endfor - add developer: -
    - - - - ${ynbutton(_("delete app"), - "deleted", - "deleteapp", - hidden_data=dict(client_id=app._id))} +
    + %endfor +
    + + + add developer: + +
    +
    +
+
+ ${ynbutton(_("delete app"), + "deleted", + "deleteapp", + hidden_data=dict(client_id=app._id))} +
+
+ %endfor

create another app...

%else:

are you a developer? create an app...

%endif -
+

${_("create application")}