Commits

Luke Plant committed a479b2b

More implementation of GUI

  • Participants
  • Parent commits 88fe62e

Comments (0)

Files changed (5)

File semanticeditor/media/semanticeditor/javascript/wymeditor/plugins/semantic/wymeditor.semantic.js

     this.headingsbox_id = id_prefix + 'headings';
     this.optsbox_id = id_prefix + 'optsbox';
     this.setup_controls(container);
+    this.available_styles = new Array();
 }
 
 /*
  *  - called on setup
  * combine_presentation
  *  - called before teardown
- * retrieve_style
+ * retrieve_styles
  *  - called on setup
  * update_headingbox
  *  - called when new info about headings arrives
+ * build_optsbox
+ *  - called when information about available styles arrives
+ *  - needs to create controls
  * update_optsbox
- *  - needs to create controls
- *  - then set them up from stored data
+ *  - remove any existing event handlers
+ *  - sets up control state from stored data
  *  - then add event handlers
+ * optsbox event handlers
+ *  - these need to store style data depending on what
+ *    the user just changed
  * // wrappers for storing data:
  * add_style(heading, pres)
  * remove_style(heading, pres)
  * update_stored_headings
  *  - called when new info about headings arrives
+ * current_heading
  */
 
+function escapeHtml(html) {
+    return html.replace(/\"/g,""")
+	.replace(/</g,"&lt;")
+	.replace(/>/g,"&gt;")
+	.replace(/&/g,"&amp;");
+}
+
 PresentationControls.prototype.setup_controls = function(container) {
     container.after("<div class=\"prescontrolheadings\">Headings:<br/><select size=\"5\" id=\"" + this.headingsbox_id + "\"></select></div>" +
 		    "<div class=\"prescontroloptsboxcont\">Presentation choices:<div class=\"prescontroloptsbox\" id=\"" + this.optsbox_id + "\"></div></div>");
+
+    this.optsbox = jQuery('#' + this.optsbox_id);
+    this.headingscontrol = jQuery('#' + this.headingsbox_id);
+
+    this.retrieve_styles();
     // Event handlers
     this.headingscontrol.change = function(event) {
 	this.update_optsbox();
     };
 };
 
-PresentationControls.prototype.optsbox = function() {
-    return jQuery('#' + this.optsbox_id);
+PresentationControls.prototype.build_optsbox = function() {
+    this.optsbox.empty();
+    var self = this;
+    jQuery.each(this.available_styles, function(i, item) {
+		    // TODO name, value
+		    // TODO - tooltip with description
+		    // TODO event handlers
+		    self.optsbox.append("<div style=\"clear: left;\"><div><label><input type=\"checkbox\" value=\"\"> " + escapeHtml(item.name) + "</label></div></div>");
+    });
 };
 
-PresentationControls.prototype.headingscontrol = function() {
-    return jQuery('#' + this.headingscontrol);
+PresentationControls.prototype.retrieve_styles = function() {
+    // Retrieve via AJAX
+    // TODO - remove hardcoded URL
+    var self = this;
+    jQuery.getJSON("/semantic/retrieve_styles/", {},
+		   function (data) {
+		       // TODO - handle failure
+		       if (data.result == 'ok') {
+			   self.available_styles = data.value;
+			   self.build_optsbox();
+		       }
+		   });
 };
 
+
 // The actual WYMeditor plugin:
 WYMeditor.editor.prototype.semantic = function(options) {
     // TODO - options need to specify the AJAX callbacks

File semanticeditor/urls.py

 from django.conf.urls.defaults import patterns, url
-from semanticeditor.views import extract_headings_view
+from semanticeditor.views import extract_headings_view, retrieve_styles
 
 urlpatterns = patterns('',
     url(r'extract_headings/', extract_headings_view),
+    url(r'retrieve_styles/', retrieve_styles)
 )

File semanticeditor/utils.py

 NEWROW = 'command:newrow'
 NEWCOL = 'command:newcolumn'
 
+
+NEWROW_detail = dict(class_name=NEWROW,
+                     name="New row",
+                     description="TODO")
+
+NEWCOL_detail = dict(class_name=NEWCOL,
+                     name="New column",
+                     description="TODO")
+
+
 MAXCOLS = 4
 COLUMNCLASS = 'col'
 

File semanticeditor/views.py

 from django.utils import simplejson
 from django.core.mail import mail_admins
 from django.utils.translation import ugettext as _
-from semanticeditor.utils import extract_headings, InvalidHtml, IncorrectHeadings
+from semanticeditor.utils import extract_headings, InvalidHtml, IncorrectHeadings, NEWROW_detail, NEWCOL_detail
+from semanticeditor.models import CssClass
 import sys
 
 def json_view(func):
         return failure(e.args[0])
 
     return success(headings)
+
+@json_view
+def retrieve_styles(request):
+    retval = [NEWROW_detail, NEWCOL_detail]
+    retval += [dict(class_name = "class:" + c.class_name,
+                    name = c.name,
+                    description = c.description)
+               for c in CssClass.objects.all()]
+    return success(retval)

File semanticeditor/widgets.py

 
 join = os.path.join
 
-
-
 class SemanticEditor(WYMEditor):
     class Media:
         js = [join(settings.SE_MEDIA_URL, path) for path in