Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit 217475d21b8ba06ada2d004f281b46cec04a6e94 @zhm committed Jul 8, 2012
@@ -0,0 +1,3 @@
+# Choice Maker for Fulcrum
+
+This is a little app to convert CSV format to Fulcrum choice lists.

Large diffs are not rendered by default.

Oops, something went wrong.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,29 @@
+
+.brand {
+ margin-left: 0px !important;
+}
+
+.left {
+ position: absolute;
+ top: 50px;
+ left: 10px;
+ right: 50%;
+ bottom: 0;
+}
+
+.right {
+ position: absolute;
+ top: 50px;
+ right: 10px;
+ left: 51%;
+ bottom: 0;
+}
+
+.right-text, .left-text {
+ width: 99%;
+ height: 98%;
+}
+
+.right-text {
+ font-family: monospace;
+}
@@ -0,0 +1,30 @@
+<!DOCTYPE html>
+<html lang="en">
+ <head>
+ <meta charset="utf-8">
+ <title>Fulcrum Choice Maker</title>
+ <script type="text/javascript" src="js/jquery.min.js"></script>
+ <script type="text/javascript" src="js/jquery-ui-1.8.21.min.js"></script>
+ <script type="text/javascript" src="js/underscore.min.js"></script>
+ <script type="text/javascript" src="js/choicemaker.js"></script>
+ <!--[if lt IE 9]>
+ <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
+ <![endif]-->
+ <link rel="stylesheet" href="css/bootstrap.css" type="text/css" media="screen" charset="utf-8" />
+ <link rel="stylesheet" href="css/style.css" type="text/css" media="screen" charset="utf-8" />
+ <link rel="stylesheet" href="css/jquery-ui-1.8.21.css" type="text/css" media="screen" charset="utf-8" />
+ </head>
+ <body>
+ <div class="navbar navbar-fixed-top">
+ <div class="navbar-inner">
+ <a class="brand" href="../">Choice Maker</a>
+ </div>
+ </div>
+ <div class="left">
+ <textarea class="left-text" placeholder="Enter choices here in CSV format"></textarea>
+ </div>
+ <div class="right">
+ <textarea class="right-text" placeholder="The choice list will automatically update here in Fulcrum format."></textarea>
+ </div>
+ </body>
+</html>
@@ -0,0 +1,148 @@
+$(function() {
+ ChoiceMaker = {};
+ ClassMaker = {};
+
+ ClassMaker.convert = function() {
+ source = $('.left-text').val();
+
+ if (!source) {
+ $('.right-text').html('');
+ return;
+ }
+
+ lines = source.split('\n');
+
+ var classes = [];
+ var classificationSet = currentNode = { name: 'Classification Set', description: 'Classification Set', items: [] };
+ var currentIndent = 1;
+
+ _.each(lines, function(line) {
+ line = $.trim(line);
+
+ var parts = line.split(',');
+ var indent = 0;
+ var indentedParts;
+
+ for (var i = 0; i < parts.length; ++i) {
+ if ($.trim(parts[i]).length === 0) {
+ indent++;
+ } else {
+ indentedParts = parts.slice(i);
+ break;
+ }
+ }
+
+ if (indentedParts.length === 0 || $.trim(indentedParts[0]).length === 0) {
+ return;
+ }
+
+ parts = indentedParts;
+
+ var label = $.trim(parts[0]);
+ var value = $.trim(parts.length > 1 && $.trim(parts[1]).length > 0 ? parts[1] : parts[0]);
+
+ if (indent > currentIndent) {
+ var children = currentNode.child_classifications || currentNode.items;
+ currentNode = {
+ parent: currentNode,
+ label: label,
+ value: value,
+ child_classifications: []
+ };
+ children.push(currentNode);
+ } else if (indent < currentIndent) {
+ var diff = (currentIndent - indent);
+ var theParent = null;
+
+ do {
+ theParent = currentNode.parent;
+ } while (diff--);
+
+ if (!theParent)
+ theParent = currentNode;
+ else
+ theParent = theParent.parent;
+
+ currentNode = {
+ parent: theParent,
+ label: label,
+ value: value,
+ child_classifications: []
+ };
+
+ if (theParent) {
+ var children = theParent.child_classifications || theParent.items;
+ children.push(currentNode);
+ }
+ } else {
+ var children = currentNode.parent.child_classifications || currentNode.parent.items;
+ currentNode = {
+ parent: currentNode.parent,
+ label: label,
+ value: value,
+ child_classifications: []
+ };
+
+ children.push(currentNode);
+ }
+
+ currentIndent = indent;
+ });
+
+ var withoutParents = {};
+ var recurse = function(items) {
+ var result = [];
+ _.each(items, function(item) {
+ result.push({
+ label: item.label,
+ value: item.value,
+ child_classifications: recurse(item.child_classifications)
+ });
+ });
+ return result;
+ };
+
+ withoutParents.items = recurse(classificationSet.items);
+
+ $('.right-text').html(JSON.stringify(withoutParents, null, ' '));
+ };
+
+ ChoiceMaker.convert = function() {
+ source = $('.left-text').val();
+
+ if (!source) {
+ $('.right-text').html('');
+ return;
+ }
+
+ lines = source.split('\n');
+
+ choices = [];
+
+ _.each(lines, function(line) {
+ var parts = line.split(',');
+
+ if (parts.length === 0 || $.trim(parts[0]).length === 0)
+ return;
+
+ choices.push({
+ label: $.trim(parts[0]),
+ value: $.trim(parts.length > 1 && $.trim(parts[1]).length > 0 ? parts[1] : parts[0])
+ });
+ });
+
+ choiceList = {
+ name: 'Choice List',
+ description: 'Choice List',
+ choices: choices
+ };
+
+ $('.right-text').html(JSON.stringify(choiceList, null, ' '));
+ };
+
+ $('.left-text').keyup(function() {
+ ClassMaker.convert();
+ // ChoiceMaker.convert();
+ });
+});
+

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

0 comments on commit 217475d

Please sign in to comment.