Permalink
Browse files

Initial commit of feedback module

  • Loading branch information...
0 parents commit 2b2c2d350a36bc63e6f2f99a6f406562eaf70be7 @jagregory committed Nov 30, 2011
Showing with 225 additions and 0 deletions.
  1. +2 −0 .gitignore
  2. +34 −0 README.textile
  3. +36 −0 app/controllers/Feedback.java
  4. +17 −0 app/models/Feedback.java
  5. +47 −0 app/views/tags/feedback/label.html
  6. +49 −0 build.xml
  7. +35 −0 commands.py
  8. +4 −0 conf/dependencies.yml
  9. +1 −0 conf/routes
  10. 0 src/play.plugins
@@ -0,0 +1,2 @@
+tmp/
+*.pyc
@@ -0,0 +1,34 @@
+h1. play-feedback
+
+Create a simple AJAX feedback control for your site. Depends on bootstrap-modal.js and jQuery.
+
+h2. Configuring the module
+
+Add the following to your @dependencies.yml@ to enable it:
+
+<pre><code>require:
+ - play
+ - play -> feedback 0.1</code></pre>
+
+Add the routes into your @routes@ file to enable the Google Checkout callback:
+
+<pre><code>* / module:feedback</code></pre>
+
+Optionally, configure your authenticated user session key (this defaults to @username@):
+
+<pre><code># Feedback
+feedback.authenticatedUserSessionKey=**your_key**</code></pre>
+
+h2. Usage
+
+Insert @#{feedback.link /}@ somewhere near the bottom of a page (or for site-wide usage, in your top-level template). This will append some Javascript to the page and on-ready, create a feedback link; when that link is clicked a bootstrap-modal dialog will be shown to submit feedback.
+
+A @Feedback@ entity is used, which stores its data in a table of the same name. No admin page is provided, but it shouldn't be hard to knock one up.
+
+h2. Bugs etc...
+
+The feedback module is provided as-is with no warranty or even expectation that it will work for you. It's been extracted from an in-house solution and only tested on our one system. Feel free to raise issues on our "Github repository":http://github.com/jagregory/play-feedback.
+
+h2. History
+
+* v0.1: Initial version, nothing too fancy
@@ -0,0 +1,36 @@
+package controllers;
+
+import play.*;
+import play.mvc.*;
+
+public class Feedback extends Controller {
+ public static void submit(String message, String url) {
+ if (message == null || message.length() == 0) {
+ return;
+ }
+
+ models.Feedback feedback = new models.Feedback();
+
+ feedback.userId = getUser();
+ feedback.ipAddress = getUserIp();
+ feedback.url = url;
+ feedback.message = message;
+ feedback.save();
+ }
+
+ static String getUser() {
+ Object id = Play.configuration.get("feedback.authenticatedUserSessionKey");
+
+ if (id == null) {
+ id = "username";
+ }
+
+ String user = session.get(id.toString());
+
+ return user != null ? user : "anonymous";
+ }
+
+ static String getUserIp() {
+ return request.remoteAddress;
+ }
+}
@@ -0,0 +1,17 @@
+package models;
+
+import play.db.jpa.*;
+import java.util.Date;
+import javax.persistence.*;
+
+@Entity
+public class Feedback extends Model {
+ public String userId;
+ public String ipAddress;
+ @Lob
+ public String url;
+ @Lob
+ public String message;
+ public Date submitted = new Date();
+ public boolean answered = false;
+}
@@ -0,0 +1,47 @@
+<div id="feedback-modal" class="modal fade" style="display:none">
+ <div class="modal-header">
+ <a href="#" class="close">x</a>
+ <h3>Send us your feedback</h3>
+ </div>
+
+ <form action="@{Feedback.submit}" method="post">
+ <input type="hidden" name="url" value="${request.url}" />
+ <div class="modal-body">
+ <p>Your feedback is much appreciated. Enter anything you want to tell us in the box below and
+ we&rsquo;ll take a look at it ASAP.</p>
+
+ <div class="clearfix">
+ <textarea name="message" style="width:520px;height:100px"></textarea>
+ </div>
+
+ <p class="alert-message success" style="display:none">Thanks, we&rsquo;ve received your feedback!</p>
+ <p class="alert-message error" style="display:none">Sorry, we didn&rsquo;t get your feedback for some reason. Please try again.</p>
+ </div>
+
+ <div class="modal-footer">
+ <button type="submit" class="btn primary">Complete purchase</button>
+ <button class="btn close">Cancel</button>
+ </div>
+ </form>
+</div>
+<script type="text/javascript">
+ $(function() {
+ $('<div id="feedback-kickoff"><a href="javascript:void(0)" data-controls-modal="feedback-modal" data-backdrop="static">Feedback</a></div>"')
+ .appendTo($('body'));
+
+ var popup = $('#feedback-modal');
+ $('form', popup).ajaxForm({
+ success: function() {
+ $('p.success', popup).show();
+
+ setTimeout(function() { popup.modal('hide') }, 2000);
+ },
+ error: function() {
+ $('p.error').show();
+ }
+ });
+ popup.bind('show', function() {
+ $('p.success, p.error').hide();
+ })
+ });
+</script>
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<project name="feedback" default="build" basedir=".">
+
+ <target name="check" unless="play.path">
+ <fail message="Please specify Play framework path using -Dplay.path=/path/to/framework/home" />
+ </target>
+
+ <path id="project.classpath">
+ <pathelement path="${play.path}/framework/classes"/>
+ <fileset dir="${play.path}/framework/lib">
+ <include name="*.jar"/>
+ </fileset>
+ <fileset dir="${play.path}/framework">
+ <include name="*.jar"/>
+ </fileset>
+ <fileset dir="lib">
+ <include name="*.jar"/>
+ </fileset>
+ </path>
+
+ <target name="build" depends="compile">
+ <mkdir dir="lib" />
+ <copy todir="tmp/classes">
+ <fileset dir="src">
+ <include name="**/*.properties"/>
+ <include name="**/*.xml"/>
+ <include name="**/play.plugins"/>
+ <include name="**/play.static"/>
+ </fileset>
+ </copy>
+ <jar destfile="lib/play-feedback.jar" basedir="tmp/classes">
+ <manifest>
+ <section name="Play-module">
+ <attribute name="Specification-Title" value="feedback"/>
+ </section>
+ </manifest>
+ </jar>
+ <delete dir="tmp" />
+ </target>
+
+ <target name="compile" depends="check">
+ <mkdir dir="tmp/classes" />
+ <javac srcdir="src" destdir="tmp/classes" target="1.5" debug="true">
+ <classpath refid="project.classpath" />
+ </javac>
+ </target>
+
+</project>
@@ -0,0 +1,35 @@
+# Here you can create play commands that are specific to the module, and extend existing commands
+
+MODULE = 'feedback'
+
+# Commands that are specific to your module
+
+COMMANDS = ['feedback:hello']
+
+def execute(**kargs):
+ command = kargs.get("command")
+ app = kargs.get("app")
+ args = kargs.get("args")
+ env = kargs.get("env")
+
+ if command == "feedback:hello":
+ print "~ Hello"
+
+
+# This will be executed before any command (new, run...)
+def before(**kargs):
+ command = kargs.get("command")
+ app = kargs.get("app")
+ args = kargs.get("args")
+ env = kargs.get("env")
+
+
+# This will be executed after any command (new, run...)
+def after(**kargs):
+ command = kargs.get("command")
+ app = kargs.get("app")
+ args = kargs.get("args")
+ env = kargs.get("env")
+
+ if command == "new":
+ pass
@@ -0,0 +1,4 @@
+self: play -> feedback 0.1
+
+require:
+ - play
@@ -0,0 +1 @@
+POST /feedback Feedback.submit
No changes.

0 comments on commit 2b2c2d3

Please sign in to comment.