summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJayaram R Pai2014-08-04 16:16:18 +0530
committerJayaram R Pai2014-08-04 16:16:18 +0530
commit416556f05904077f08103254ec9da28d6d7fcb83 (patch)
tree2cff311038f2c9af55bf00494a3dc85d76fb3838
parent1c3489080c2f46a082480b2aa1e85b566d00afbf (diff)
downloadtextbook_companion_fixer-416556f05904077f08103254ec9da28d6d7fcb83.tar.gz
textbook_companion_fixer-416556f05904077f08103254ec9da28d6d7fcb83.tar.bz2
textbook_companion_fixer-416556f05904077f08103254ec9da28d6d7fcb83.zip
added page to edit example code
-rw-r--r--css/scilab_fixer.css18
-rw-r--r--js/scilab_fixer.js62
-rw-r--r--js/selection.js4
-rwxr-xr-xscilab_fixer.module97
4 files changed, 154 insertions, 27 deletions
diff --git a/css/scilab_fixer.css b/css/scilab_fixer.css
index 2468fb4..964317f 100644
--- a/css/scilab_fixer.css
+++ b/css/scilab_fixer.css
@@ -1,16 +1,16 @@
-#fix-caption-form #edit-caption {
+#fix-tbc-form #edit-caption {
width: 99% !important;
}
-#fix-caption-form .well {
+#fix-tbc-form .well {
margin-top: 25px;
width: 620px;
overflow-x: auto;
}
-#fix-caption-form #edit-example {
+#fix-tbc-form #edit-example {
height: 250px;
}
-#fix-caption-page #updating,
-#fix-caption-page #done {
+#fix-tbc-page #updating,
+#fix-tbc-page #done {
display: none;
position: fixed;
z-index: 2000;
@@ -26,9 +26,13 @@
-obox-shadow: 0px 0px 10px #cccccc;
box-shadow: 0px 0px 10px #cccccc;
}
-#fix-caption-page #updating {
+#fix-tbc-page #updating {
background: #FF851B;
}
-#fix-caption-page #done {
+#fix-tbc-page #done {
background: #2ECC40;
}
+textarea#edit-code {
+ height: 300px;
+ width: 650px;
+}
diff --git a/js/scilab_fixer.js b/js/scilab_fixer.js
index 8236099..9148603 100644
--- a/js/scilab_fixer.js
+++ b/js/scilab_fixer.js
@@ -2,15 +2,16 @@ $(document).ready(function() {
var basePath = Drupal.settings.basePath;
var modPath = basePath + "fix/";
- $category = $("#fix-caption-form #edit-category");
- $book = $("#fix-caption-form #edit-book");
- $chapter = $("#fix-caption-form #edit-chapter");
- $example = $("#fix-caption-form #edit-example");
- $caption = $("#fix-caption-form #edit-caption");
- $code = $("#fix-caption-form #fix-caption-code");
- $form = $("#scilab-fixer-caption-form");
- $updating = $("#fix-caption-page #updating");
- $done = $("#fix-caption-page #done");
+ $category = $("#fix-tbc-form #edit-category");
+ $book = $("#fix-tbc-form #edit-book");
+ $chapter = $("#fix-tbc-form #edit-chapter");
+ $example = $("#fix-tbc-form #edit-example");
+ $caption = $("#fix-tbc-form #edit-caption");
+ $code = $("#fix-tbc-form #edit-code");
+ $caption_form = $("#scilab-fixer-caption-form");
+ $code_form = $("#scilab-fixer-code-form");
+ $updating = $("#fix-tbc-page #updating");
+ $done = $("#fix-tbc-page #done");
$example.attr("multiple", "enabled");
function reset() {
@@ -81,21 +82,30 @@ $(document).ready(function() {
$example.change(function() {
var example_id = $(this).val();
reset("caption");
-
+ console.log("########" + example_id);
$.ajax({
url: modPath + "ajax/example/" + example_id,
type: "POST",
dataType: "html",
success: function(data) {
var code = $(data).filter("#code").html();
- $code.html(code);
+ /* checking whether it is for .well or textarea */
+ if($code.hasClass("fix-caption-code")) {
+ $code.html(code);
+ } else {
+ $code.val(code);
+ }
var caption = $(data).filter("#caption").html();
- $caption.val(caption);
+ try {
+ $caption.val(caption);
+ } catch(e) {
+ return;
+ }
}
});
});
- $form.submit(function(e) {
+ $caption_form.submit(function(e) {
var example_id = $example.val();
if(example_id != "0") {
var caption = $caption.val();
@@ -105,7 +115,31 @@ $(document).ready(function() {
type: "POST",
data: {
example_id: example_id,
- caption: caption
+ caption: caption
+ },
+ dataType: "html",
+ success: function(data) {
+ $chapter.trigger("change");
+ $updating.hide();
+ $done.show();
+ $done.fadeOut("slow");
+ }
+ });
+ } else {
+ alert("No example selected.")
+ }
+ e.preventDefault();
+ });
+
+ $code_form.submit(function(e) {
+ var example_id = $example.val();
+ if(example_id != "0") {
+ var code = $code.val();
+ $.ajax({
+ url: modPath + "ajax/code/" + example_id,
+ type: "POST",
+ data: {
+ code: code
},
dataType: "html",
success: function(data) {
diff --git a/js/selection.js b/js/selection.js
index fcb738b..6834aca 100644
--- a/js/selection.js
+++ b/js/selection.js
@@ -16,10 +16,10 @@ function getSelectionText(divID) {
return selectedText;
}
$(document).ready(function() {
- $("#fix-caption-code").mousedown(function() {
+ $(".fix-caption-code").mousedown(function() {
$("#edit-caption").val("");
});
- $("#fix-caption-code").mouseup(function() {
+ $(".fix-caption-code").mouseup(function() {
quotedText = getSelectionText("#fix-caption-code");
$("#edit-caption").val(quotedText);
});
diff --git a/scilab_fixer.module b/scilab_fixer.module
index 8955255..27bb6d5 100755
--- a/scilab_fixer.module
+++ b/scilab_fixer.module
@@ -29,6 +29,13 @@
"weight" => 2,
"type" => MENU_LOCAL_TASK
);
+ $items["fix/code"] = array(
+ "title" => "Edit TBC code",
+ "page callback" => "scilab_fixer_code_all",
+ "access arguments" => array("fix scilab"),
+ "access arguments" => array("fix scilab"),
+ "type" => MENU_CALLBACK
+ );
$items["fix/ajax"] = array(
"page callback" => "scilab_fixer_ajax",
"access callback" => TRUE,
@@ -48,7 +55,7 @@
$form["wrapper"] = array(
"#type" => "fieldset",
"#title"=> "Caption change form",
- "#prefix" => "<div id='fix-caption-form'>",
+ "#prefix" => "<div id='fix-tbc-form'>",
"#suffix" => "</div>",
);
$form["wrapper"]["category"] = array(
@@ -100,10 +107,10 @@
"#type" => "submit",
"#value" => "Update"
);
- $form["wrapper"]["code"] = array(
+ $form["wrapper"]["code_wrapper"] = array(
"#type" => "fieldset",
"#description" => t("No code to display"),
- "#prefix" => "<div class='well'><pre id='fix-caption-code'>",
+ "#prefix" => "<div class='well'><pre id='edit-code' class='fix-caption-code'>",
"#suffix" => "</pre></div>",
);
return $form;
@@ -111,7 +118,7 @@
function scilab_fixer_caption_all() {
$page_content = "";
- $page_content .= "<div id='fix-caption-page'>";
+ $page_content .= "<div id='fix-tbc-page'>";
$page_content .= "<center><span id='updating'>Updating...</span></center>";
$page_content .= "<span id='done'>Done.</span>";
$page_content .= drupal_get_form("scilab_fixer_caption_form");
@@ -175,6 +182,18 @@
";
$result = db_query($query, $caption, $example_id);
$data .= "Updated";
+ } else if($item == "code" && $key) {
+ $code = $_POST["code"];
+ $query = "
+ SELECT * FROM textbook_companion_example_files
+ WHERE example_id = %d AND filetype = 'S'
+ ";
+ $result = db_query($query, $key);
+ $row = db_fetch_object($result);
+ $uploads_dir = $_SERVER['DOCUMENT_ROOT'] . base_path() . "uploads/";
+ $example_path = $uploads_dir . $row->filepath;
+ file_put_contents($example_path, $code);
+ $data .= "updated";
} else {
$data = "Nothing to display.";
}
@@ -337,6 +356,76 @@
return $page_content;
}
+ function scilab_fixer_code_form($form_state) {
+ $form = array();
+ $form["wrapper"] = array(
+ "#type" => "fieldset",
+ "#title"=> "Code edit form",
+ "#prefix" => "<div id='fix-tbc-form'>",
+ "#suffix" => "</div>",
+ );
+ $form["wrapper"]["category"] = array(
+ "#type" => "select",
+ "#title" => t("Please select the category"),
+ '#options' => array(
+ 0 => 'Please select a category',
+ 1 => 'Fluid Mechanics',
+ 2 => 'Control Theory & Control Systems',
+ 3 => 'Chemical Engineering',
+ 4 => 'Thermodynamics',
+ 5 => 'Mechanical Engineering',
+ 6 => 'Signal Processing',
+ 7 => 'Digital Communications',
+ 8 => 'Electrical Technology',
+ 9 => 'Mathematics & Pure Science',
+ 10 => 'Analog Electronics',
+ 11 => 'Digital Electronics',
+ 12 => 'Computer Programming',
+ 13 => 'Others'
+ ),
+ );
+ $form["wrapper"]["book"] = array(
+ "#type" => "select",
+ "#title" => t("Please select the book."),
+ "#options" => array(
+ 0 => "Please select a book"
+ )
+ );
+ $form["wrapper"]["chapter"] = array(
+ "#type" => "select",
+ "#title" => t("Please select the chapter"),
+ "#options" => array(
+ 0 => "Please select a chapter"
+ )
+ );
+ $form["wrapper"]["example"] = array(
+ "#type" => "select",
+ "#title" => t("Please select the example"),
+ "#options" => array(
+ 0 => "Please select a example"
+ )
+ );
+ $form["wrapper"]["code"] = array(
+ "#type" => "textarea",
+ "#title" => t("Code Editor"),
+ );
+ $form["wrapper"]["submit"] = array(
+ "#type" => "submit",
+ "#value" => "Update"
+ );
+ return $form;
+ }
+
+ function scilab_fixer_code_all() {
+ $page_content = "";
+ $page_content .= "<div id='fix-tbc-page'>";
+ $page_content .= "<center><span id='updating'>Updating...</span></center>";
+ $page_content .= "<span id='done'>Done.</span>";
+ $page_content .= drupal_get_form("scilab_fixer_code_form");
+ $page_content .= "</div>";
+ return $page_content;
+ }
+
function scilab_fixer_init() {
drupal_add_css(drupal_get_path("module", "scilab_fixer") . "/css/scilab_fixer.css");
drupal_add_js(drupal_get_path("module", "scilab_fixer") . "/js/scilab_fixer.js");