Proof of Concept - Code Review (WIP)

Early alpha version from discovery - for code review, to prepare the list of tasks for the production-grade version.

This is the discussion module as an xblock. This is the work done so far:

* Created a xblock base for discussion.
* Extracted all required javascript dependencies for the xblock resources (no coffeescript used yet)
* Extracted all required sass dependencies for the xblock resources.
* Fix issues to get the the xblock running properly from an external application (jquery-xblock).
* Created a makefile to brings all non-modifed dependencies from LMS. (JS, images, fonts, etc.) 

This proof of concept works well (with minor css issues?) in the LMS and in an  external app.

A screenshot from the xblock in the LMS: 
![demo1](https://cloud.githubusercontent.com/assets/532356/2999240/d23dc234-dd13-11e3-958c-921e888baa2c.png)

A screenshot from the xblock in an external app:
![demo1](https://cloud.githubusercontent.com/assets/532356/2999337/b5a810f6-dd14-11e3-9fff-7c61fe8970b8.png)

TODO LIST -- Questions for the discussion team
--------------------------------------------------------------

- [x] What are all "_filename.html" files in lms/templates/discussion/? It looks like I only need _underscore_templates.html and _thread_list_template.html. I might be wrong. It need some clarification. I think those are for the discussion course page. To confirm.

- [x] Can you clarify what is the difference between discussion stuff AND discussion-inline ? This has been clarify during the meeting. It's the main discussion page available. This will be discussed for another xblock.

- [x] With a djangoapps, how are we going to get the list of resources to fetch for the xblock?

TODO
--------

### Main tasks

- [ ] Code review from forum team
- [ ] Hook on LMS django app to get JS/CSS resources, and contribute to django app to fit the needs of the the XBlock
- [ ] Code cleanup (cf below)
- [x] Write documentation (cf below)
- [x] Fix formatting issues (cf attached screenshots)
- [ ] Studio view (cf below)
- [x] XBlock PR: to allow font files and allow dots in names -- while being safe to not allow things like ../../
- [ ] jquery-xblock PR: do changes from code review of forum id PRs and get them merged: edx-solutions/jquery-xblock: Pull Request #6, apros: Pull Request #81
- [ ] jquery-xblock/XBlock PR: Async loading of JS/deps (includes changes to fragment in XBlock repo)
- [ ] Add unit tests (with make test, and coverage report)
- [ ] QA. Retest the entire xblock with all functionnalities
- [ ] Organize transitioning the XBlock over to the forums team

### Pull Requests to Track

- [ ] https://github.com/edx/XBlock/pull/214
- [ ] https://github.com/edx/edx-platform/pull/3858
- [ ] https://github.com/edx/edx-platform/pull/3829

### Create a standalone Discussion XBlock

The goal of this is to create a standalone discussion xblock similar to ora2. The xblock will contains all dependencies. Since the platform needs also needs the resources for its xmodule, they will be served as python package resources (app). This work has been started by Jim an is available at:

https://github.com/jimabramson/xblock-discussion/compare/6531dd7467b4a0550f3a9330212f8aafc401c6be...jsa%2Fexternalize

For the first implementation, I'd suggest we don't delete anything in the platform, copy all needed dependencies (compiled).  

(Alan): Planned work for the next days.
(Future): Not something to do for the first working implementation.

#### XBlock tasks

- [x] Add all compiled resources from the LMS in the repo. This can be done through the Makefile. (Alan)
- [x] Check more in detail how things are done in discussion_app (Alan)
- [x] Sync Jim's work with my latest alan/alpha2 branch. This PR. (Alan)
- [x] Complete the integration/use of disucssion_app inside the discussion_forum xblock (Alan)
- [x] Ensure the discussion_forum uses the discussion_app properly and that everything is working. (Alan)
- [ ] Include all needed sass files dependencies, ensure we have a minimal  version of all those files and add the automatic compilation. We should create a completely standalone sass styling rather than simply copy all needed files, so we'll have everything needed, not more.  (Future)
- [x] Include all coffescript needed files rather than the JS compiled ones and add automatic compilation. (Future)

#### Platform tasks

Jim, are those platform tasks something you could work on?

- [ ] Add the new xblock as dependency
- [x] Ensure the platform doesn't use the internal discussion assets, but rather use the resources from the xblock discussion_app.
- [ ] ...
### Docs

- [x] Add Readme (include warning about alpha/PoC nature of the repo)
- [x] Installation instructions, with "discussion-forum" in advanced settings. (couldn't use 'discussion' due to the xmodule).
- [ ] Document running tests3
- [x] requirements.txt

### Studio view

- [ ] Finish the studio view, (doesn't currently work): Currently, the xblock doesn't work in studio because it is missing some resources. The first error we can see in the log is "Uncaught ReferenceError: URI is not defined", but there will be more. The reason is that the xblock resources are not fetched. Not sure why but nothing happens after the student_view request.. compared to mentoring which fetch the needed resources. I think this is not a major issue and that the xblock will prossibly be ok in studio with some work. 
- [ ] Remove need for "click on Edit, then save" (limitation, needed for the uuid). (cf comments in PR)
- [ ] Fix forum headers links (next to EDIT - Duplicate/Delete)

### Code cleanup & fixing TODO/hacks in the code

- [ ] Ensure there is no more "TODO" in the code... see TODO CODE list.
- [x] Add all needed dependencies in the xblock package. (ie. mako)
- [ ] The popup window on error is not displayed correctly. This would also be fixed with a djangoapp to serve shared resources.
- [ ] Check the templates, some might be missing a context variable.
- [ ] Fix _filter_dropdown.html template: 
```
File "memory:0x7f3959060e50", line 61, in render_body File "memory:0x7f3959060e50", line 26, in render_dropdown File "memory:0x7f3959060e50", line 117, in render_render_dropdown TypeError: 'Undefined' object has no attribute '__getitem__'. 
```
Some context are missing to display this template.

- [ ] discussion_forum.py: # TODO remove that todo (course_id method)
- [x] discussion_forum.py: # TODO clean the resources... add a get_css()/get_javascript functions and  loop on a resources array
- [x]  discussion_forum.py: # TODO Not use. Remove discussion-inline.css an this code part.
- [ ]  discussion_forum.py: # TODO find a better solution to support attribute initialization
- [ ]  discussion_forum.py: # TODO: change this to create the scenarios you'd like to see in the. Add workbench scenario.
- [x]  static/scss/discussion.scss:/* TODO Remove this block... was for a courseware discussion page? */
- [x]  static/scss/discussion.scss:/* TODO there is no .container when not in the lms.. added .discussion-module here */ This change seems to affect the style in the LMS.
- [x] public/js/vendor/customwmd.js: // TODO I removed the Post body text here.
- [x]  public/js/discussion_block.js:// TODO move studio stuff to its own file
- [x]  public/js/views/discussion_thread_view_inline.js: // TODO not needed in the LMS... externally we get html instead of json. Removed that.. not more appropriate.
- [x]  public/js/views/discussion_thread_view_inline.js: // TODO remove static url!! -> already modified... comment should be "port to coffeescript"
- [x] public/js/views/discussion_thread_profile_view.js: // TODO port to coffeescript!
- [x] public/js/utils.js: // TODO removed the "Loading Content" text span...
- [x]  public/js/utils.js: // TODO: port this new function in coffeescript. (getBaseUrl)
- [x]  public/js/utils.js: // TODO port to coffescript: modified for baseUrl (urlFor)
- [x] public/js/utils.js: // TODO Apply this change to coffescript file: I removed the beforeSend use. in conflict with
- [x]  templates/mustache/_inline_thread_cohorted.mustache: ## TODO removed the "Loading Content" text span...
- [x]  templates/mustache/_inline_thread.mustache: ## TODO removed the "Loading Content" text span..
- [ ]  templates/html/_thread_list_template.html: ## TODO FIX AND ENABLE <%include file="_filter_dropdown.html" />
- [x] templates/html/_underscore_templates.html: added django settings import
- [x] discussion_forum.py: # temporary, really... => Remove list of static resources