Luke Plant avatar Luke Plant committed 7830064

Removed hard-coding of AJAX urls

Comments (0)

Files changed (3)

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

  * parsing and provide list of allowed CSS classes.
  */
 
-function PresentationControls(wym) {
+function PresentationControls(wym, opts) {
+    this.wym = wym;
+    this.opts = opts;
     this.name = wym._element.get(0).name;
-    this.wym = wym;
     // available_styles: an array of dictionaries corresponding to PresentationInfo objects
     this.available_styles = new Array();
     // stored_headings: an array of 2 elements arrays, [heading level, heading name]
 // Splits the HTML into 'content HTML' and 'presentation'
 PresentationControls.prototype.separate_presentation = function() {
     var self = this;
-    jQuery.post("/semantic/separate_presentation/", { html: self.wym.xhtml() } ,
+    jQuery.post(this.opts.separate_presentation_url, { html: self.wym.xhtml() } ,
 		function(data) {
 		    self.with_good_data(data,
 			function(value) {
 		      html: this.wym.xhtml(),
 		      presentation: JSON.stringify(this.presentation_info)
 		  },
-		  url: "/semantic/combine_presentation/",
+		  url: this.opts.combine_presentation_url,
 		  dataType: "json",
 		  async: false
     }).responseText;
 PresentationControls.prototype.refresh_headings = function() {
     var self = this;
     var html = this.wym.xhtml();
-    jQuery.post("/semantic/extract_headings/", { 'html':html },
+    jQuery.post(this.opts.extract_headings_url, { 'html':html },
 	function(data) {
 	    self.with_good_data(data, function(value) {
 		self.stored_headings = value;
     // Retrieve via AJAX
     // TODO - remove hardcoded URL
     var self = this;
-    jQuery.getJSON("/semantic/retrieve_styles/", {},
+    jQuery.getJSON(this.opts.retrieve_styles_url, {},
 		   function (data) {
 		       self.with_good_data(data, function(value) {
 			   self.available_styles = data.value;
     // TODO - options need to specify the AJAX callbacks
     // we are going to need.
     var wym = this;
-    var c = new PresentationControls(wym);
+    var c = new PresentationControls(wym, options);
 };

semanticeditor/templates/semanticeditor/editorwidget.html

             });
 
             // Enable the 'semantic' plugin
-            wym.semantic({});
+            symanticopts = {
+                extract_headings_url: "{% url semantic.extract_headings %}",
+                retrieve_styles_url: "{% url semantic.retrieve_styles %}",
+                separate_presentation_url: "{% url semantic.separate_presentation %}",
+                combine_presentation_url: "{% url semantic.combine_presentation %}"
+            };
+            wym.semantic(symanticopts);
         },
         //handle click event on dialog's submit button
         postInitDialog: function( wym, wdw ) {

semanticeditor/urls.py

 from semanticeditor.views import extract_headings_view, retrieve_styles, separate_presentation, combine_presentation
 
 urlpatterns = patterns('',
-    url(r'extract_headings/', extract_headings_view),
-    url(r'retrieve_styles/', retrieve_styles),
-    url(r'separate_presentation/', separate_presentation),
-    url(r'combine_presentation/', combine_presentation),
+    url(r'extract_headings/', extract_headings_view, name="semantic.extract_headings"),
+    url(r'retrieve_styles/', retrieve_styles, name="semantic.retrieve_styles"),
+    url(r'separate_presentation/', separate_presentation, name="semantic.separate_presentation"),
+    url(r'combine_presentation/', combine_presentation, name="semantic.combine_presentation"),
 )
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.