Renamed all JS files affected by former commit.
And also changed templates accordingly.
--- a/app/soc/content/js/blog-081117.js Tue Aug 25 15:58:30 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,79 +0,0 @@
-/* Copyright 2008 the Melange authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-function BlogPreview(container) {
- this.container_ = container;
-}
-
-BlogPreview.prototype.show = function (url, entries_num, title, title_link) {
- var feed = new google.feeds.Feed(url);
- var preview = this;
- feed.setNumEntries(entries_num);
- feed.load(function (result) {
- preview.render_(result, title, title_link);
- });
-};
-
-BlogPreview.prototype.render_ = function (result, title, title_link) {
- if (!result.feed || !result.feed.entries) {
- return;
- }
- while (this.container_.firstChild) {
- this.container_.removeChild(this.container_.firstChild);
- }
-
- var blog = this.createDiv_(this.container_, "blog");
- var header = this.createElement_("h2", blog, "");
- if (!title) {
- title = result.feed.title;
- }
- if (!title_link) {
- title_link = result.feed.link;
- }
- this.createLink_(header, title_link, title);
-
- for (var i = 0; i < result.feed.entries.length; i++) {
- var entry = result.feed.entries[i];
- var div = this.createDiv_(blog, "entry");
- var linkDiv = this.createDiv_(div, "title");
- this.createLink_(linkDiv, entry.link, entry.title);
- if (entry.author) {
- this.createDiv_(div, "author", "Posted by " + entry.author);
- }
- this.createDiv_(div, "snippet", entry.contentSnippet);
- }
-};
-
-BlogPreview.prototype.createDiv_ = function (parent, className, opt_text) {
- return this.createElement_("div", parent, className, opt_text);
-};
-
-BlogPreview.prototype.createLink_ = function (parent, href, text) {
- var link = this.createElement_("a", parent, "", text);
- link.href = href;
- return link;
-};
-
-BlogPreview.prototype.createElement_ = function (tagName, parent, className,
- opt_text) {
- var div = document.createElement(tagName);
- div.className = className;
- parent.appendChild(div);
- if (opt_text) {
- div.appendChild(document.createTextNode(opt_text));
- }
- return div;
-};
-
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/content/js/blog-090825.js Tue Aug 25 16:15:07 2009 +0100
@@ -0,0 +1,79 @@
+/* Copyright 2008 the Melange authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+function BlogPreview(container) {
+ this.container_ = container;
+}
+
+BlogPreview.prototype.show = function (url, entries_num, title, title_link) {
+ var feed = new google.feeds.Feed(url);
+ var preview = this;
+ feed.setNumEntries(entries_num);
+ feed.load(function (result) {
+ preview.render_(result, title, title_link);
+ });
+};
+
+BlogPreview.prototype.render_ = function (result, title, title_link) {
+ if (!result.feed || !result.feed.entries) {
+ return;
+ }
+ while (this.container_.firstChild) {
+ this.container_.removeChild(this.container_.firstChild);
+ }
+
+ var blog = this.createDiv_(this.container_, "blog");
+ var header = this.createElement_("h2", blog, "");
+ if (!title) {
+ title = result.feed.title;
+ }
+ if (!title_link) {
+ title_link = result.feed.link;
+ }
+ this.createLink_(header, title_link, title);
+
+ for (var i = 0; i < result.feed.entries.length; i++) {
+ var entry = result.feed.entries[i];
+ var div = this.createDiv_(blog, "entry");
+ var linkDiv = this.createDiv_(div, "title");
+ this.createLink_(linkDiv, entry.link, entry.title);
+ if (entry.author) {
+ this.createDiv_(div, "author", "Posted by " + entry.author);
+ }
+ this.createDiv_(div, "snippet", entry.contentSnippet);
+ }
+};
+
+BlogPreview.prototype.createDiv_ = function (parent, className, opt_text) {
+ return this.createElement_("div", parent, className, opt_text);
+};
+
+BlogPreview.prototype.createLink_ = function (parent, href, text) {
+ var link = this.createElement_("a", parent, "", text);
+ link.href = href;
+ return link;
+};
+
+BlogPreview.prototype.createElement_ = function (tagName, parent, className,
+ opt_text) {
+ var div = document.createElement(tagName);
+ div.className = className;
+ parent.appendChild(div);
+ if (opt_text) {
+ div.appendChild(document.createTextNode(opt_text));
+ }
+ return div;
+};
+
--- a/app/soc/content/js/bulk-review-090304.js Tue Aug 25 15:58:30 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,119 +0,0 @@
-jQuery(document).ready(function () {
- jQuery("#applications_progress_bar").progressBar({showText: false});
-});
-
-function bulkReview(data) {
- // some global constants
- var GLOBAL_LINK = data.link;
- var TOTAL_APPLICATIONS = data.nr_applications;
-
- // some global variables set needed for internal iteration
- var application_index = 0;
- // number of iteration is not taken from data.nr_applications
- // to ensure avoidance of array out of bounds errors
- var total_index = data.applications.length;
-
-
- // call immediately the function for review
- // real iteration is inside
- setTimeout(
- function () {
- var error_happened = false;
- var application = data.applications[application_index];
- var current_application = application_index + 1;
- // regular expression to find a valid scope path
- // inside matching parenthesis
- var re = /\((\w*)\)/;
- var scope_path = GLOBAL_LINK.match(re)[1];
- // the URL is obtained by using the scope path found
- // in the matching parenthesis
- var url_to_call = GLOBAL_LINK.replace(re, application[scope_path]);
- // now we can call the URL found
- jQuery.ajax({
- async: false,
- cache: false,
- url: url_to_call,
- timeout: 10000,
- success: function (data) {
- if (data) {
- // update progress bar percentage and description
- var percentage =
- Math.floor(100 * (current_application) / (TOTAL_APPLICATIONS));
- jQuery("#description_progressbar").html([
- " Processed application ", application.name,
- " (", current_application, "/", TOTAL_APPLICATIONS, ")"
- ].join(""));
- jQuery("#applications_progress_bar").progressBar(percentage);
- }
- },
- error: function (XMLHttpRequest, textStatus, errorThrown) {
- // if there is an error return the button and
- // leave a try again message
- error_happened = true;
- jQuery("[id^=button_bulk_]").fadeIn(
- "slow",
- function () {
- jQuery("#description_done").html([
- "<strong class='error'>",
- " Error encountered, try again",
- "</strong>"
- ].join(""));
- }
- );
- }
- });
- // if there were no errors, continue the iteration
- if (!error_happened) {
- // prepare for new iteration and then recall this function
- application_index++;
- if (application_index < total_index) {
- setTimeout(arguments.callee, 0);
- }
- else {
- // all ok, tell the user we are done
- jQuery("#applications_progress_bar").fadeOut(
- "slow",
- function () {
- jQuery("#applications_progress_bar").progressBar(0);
- jQuery("[id^=button_bulk_]").fadeIn("slow");
- }
- );
- jQuery("#description_progressbar").html("");
- jQuery("#description_done").html("<strong>Done!</strong>");
- }
- }
- },
- 0
- );
-}
-
-function bulkReviewInit(bulk_review_link, button) {
- // get the JSON object with details of every application for bulk acceptance
- jQuery.getJSON(
- bulk_review_link + "?_=" + (new Date().getTime()),
- function (data) {
- // If there are applications to review...
- if (data.nr_applications !== 0) {
- //...then fade out the button, show the progress bar and call the function for review
- jQuery("[id^=button_bulk_]").fadeOut(
- "slow",
- function () {
- jQuery("#applications_progress_bar").progressBar(0);
- jQuery("#description_done").html("");
- jQuery("#applications_progress_bar").fadeIn("slow", bulkReview(data));
- }
- );
- }
- else {
- var no_organization_text = "No organizations to ";
- if (jQuery(button).attr("id").indexOf("reject") !== -1) {
- no_organization_text += "reject";
- }
- else {
- no_organization_text += "accept";
- }
- jQuery("#description_done").html("<strong>" + no_organization_text + "</strong>");
- }
- }
- );
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/content/js/bulk-review-090825.js Tue Aug 25 16:15:07 2009 +0100
@@ -0,0 +1,119 @@
+jQuery(document).ready(function () {
+ jQuery("#applications_progress_bar").progressBar({showText: false});
+});
+
+function bulkReview(data) {
+ // some global constants
+ var GLOBAL_LINK = data.link;
+ var TOTAL_APPLICATIONS = data.nr_applications;
+
+ // some global variables set needed for internal iteration
+ var application_index = 0;
+ // number of iteration is not taken from data.nr_applications
+ // to ensure avoidance of array out of bounds errors
+ var total_index = data.applications.length;
+
+
+ // call immediately the function for review
+ // real iteration is inside
+ setTimeout(
+ function () {
+ var error_happened = false;
+ var application = data.applications[application_index];
+ var current_application = application_index + 1;
+ // regular expression to find a valid scope path
+ // inside matching parenthesis
+ var re = /\((\w*)\)/;
+ var scope_path = GLOBAL_LINK.match(re)[1];
+ // the URL is obtained by using the scope path found
+ // in the matching parenthesis
+ var url_to_call = GLOBAL_LINK.replace(re, application[scope_path]);
+ // now we can call the URL found
+ jQuery.ajax({
+ async: false,
+ cache: false,
+ url: url_to_call,
+ timeout: 10000,
+ success: function (data) {
+ if (data) {
+ // update progress bar percentage and description
+ var percentage =
+ Math.floor(100 * (current_application) / (TOTAL_APPLICATIONS));
+ jQuery("#description_progressbar").html([
+ " Processed application ", application.name,
+ " (", current_application, "/", TOTAL_APPLICATIONS, ")"
+ ].join(""));
+ jQuery("#applications_progress_bar").progressBar(percentage);
+ }
+ },
+ error: function (XMLHttpRequest, textStatus, errorThrown) {
+ // if there is an error return the button and
+ // leave a try again message
+ error_happened = true;
+ jQuery("[id^=button_bulk_]").fadeIn(
+ "slow",
+ function () {
+ jQuery("#description_done").html([
+ "<strong class='error'>",
+ " Error encountered, try again",
+ "</strong>"
+ ].join(""));
+ }
+ );
+ }
+ });
+ // if there were no errors, continue the iteration
+ if (!error_happened) {
+ // prepare for new iteration and then recall this function
+ application_index++;
+ if (application_index < total_index) {
+ setTimeout(arguments.callee, 0);
+ }
+ else {
+ // all ok, tell the user we are done
+ jQuery("#applications_progress_bar").fadeOut(
+ "slow",
+ function () {
+ jQuery("#applications_progress_bar").progressBar(0);
+ jQuery("[id^=button_bulk_]").fadeIn("slow");
+ }
+ );
+ jQuery("#description_progressbar").html("");
+ jQuery("#description_done").html("<strong>Done!</strong>");
+ }
+ }
+ },
+ 0
+ );
+}
+
+function bulkReviewInit(bulk_review_link, button) {
+ // get the JSON object with details of every application for bulk acceptance
+ jQuery.getJSON(
+ bulk_review_link + "?_=" + (new Date().getTime()),
+ function (data) {
+ // If there are applications to review...
+ if (data.nr_applications !== 0) {
+ //...then fade out the button, show the progress bar and call the function for review
+ jQuery("[id^=button_bulk_]").fadeOut(
+ "slow",
+ function () {
+ jQuery("#applications_progress_bar").progressBar(0);
+ jQuery("#description_done").html("");
+ jQuery("#applications_progress_bar").fadeIn("slow", bulkReview(data));
+ }
+ );
+ }
+ else {
+ var no_organization_text = "No organizations to ";
+ if (jQuery(button).attr("id").indexOf("reject") !== -1) {
+ no_organization_text += "reject";
+ }
+ else {
+ no_organization_text += "accept";
+ }
+ jQuery("#description_done").html("<strong>" + no_organization_text + "</strong>");
+ }
+ }
+ );
+}
--- a/app/soc/content/js/datetime-loader-090304.js Tue Aug 25 15:58:30 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,6 +0,0 @@
-jQuery(
- function () {
- jQuery('.datetime-pick').datetimepicker();
- }
-);
-
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/content/js/datetime-loader-090825.js Tue Aug 25 16:15:07 2009 +0100
@@ -0,0 +1,6 @@
+jQuery(
+ function () {
+ jQuery('.datetime-pick').datetimepicker();
+ }
+);
+
--- a/app/soc/content/js/datetimepicker-090304.js Tue Aug 25 15:58:30 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,12 +0,0 @@
-jQuery(
- function () {
- jQuery('.datetime-pick').datetimepicker();
- jQuery('.date-pick').datetimepicker({
- 'pickDateOnly': true,
- 'defaultDate': new Date('01/01/1974'),
- 'timeFormat': '',
- 'yearRange': '1900:2008'
- });
- }
-);
-
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/content/js/datetimepicker-090825.js Tue Aug 25 16:15:07 2009 +0100
@@ -0,0 +1,12 @@
+jQuery(
+ function () {
+ jQuery('.datetime-pick').datetimepicker();
+ jQuery('.date-pick').datetimepicker({
+ 'pickDateOnly': true,
+ 'defaultDate': new Date('01/01/1974'),
+ 'timeFormat': '',
+ 'yearRange': '1900:2008'
+ });
+ }
+);
+
--- a/app/soc/content/js/duplicate-slots-090505.js Tue Aug 25 15:58:30 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,262 +0,0 @@
-(function () {
- var duplicateSlots = window.duplicateSlots = function () {
- };
- // this variable will contain all the org details, and filled
- // incrementally
- var orgs_details = {};
- // this variable will contain all student/proposal data details,
- // filled incrementally
- var assigned_proposals = [];
-
- // public function to output actual HTML out of the data (cached or not)
- duplicateSlots.showDuplicatesHtml =
- function (orgs_details, student, student_key, proposals) {
- /*jslint undef:false */
- if (html_string === '') {
- jQuery("#div_duplicate_slots").html('');
- html_string = '<ul>';
- }
- html_string += [
- '<li>',
- ' Student: ',
- ' <strong>',
- ' <a href="/student/show/', student_key, '">', student.name,
- '</a>',
- ' </strong> ',
- '(<a href="mailto:', student.contact, '">', student.contact, '</a>)'
- ].join("");
- html_string += '<ul>';
- jQuery(proposals).each(
- function (intIndex, proposal) {
- html_string += [
- '<li>',
- ' Organization: ',
- ' <a href="/org/show/', proposal.org_key, '">',
- orgs_details[proposal.org_key].name,
- '</a>, admin: ', orgs_details[proposal.org_key].admin_name,
- ' (<a href="mailto:',
- orgs_details[proposal.org_key].admin_email,
- '">',
- orgs_details[proposal.org_key].admin_email, '</a>)</li>'
- ].join("");
- html_string += [
- '<ul>',
- ' <li>',
- 'Proposal: ',
- '<a href="/student_proposal/show/', proposal.proposal_key, '">',
- proposal.proposal_title, '</a>',
- ' </li>',
- '</ul>'
- ].join("");
- }
- );
- html_string += '</ul></li>';
- html_string += '</ul>';
- jQuery("#div_duplicate_slots").html(html_string);
- /*jslint undef:true */
- };
-
- // private function to generate the JSON to send for caching and calling
- // the actual function that will print the data
- function printDuplicatesAndSendJSON() {
- // JSON skeleton that need to be sent to the server
- var to_json = {
- "data": {
- "orgs" : orgs_details,
- "students": {}
- }
- };
- // for every student...
- jQuery.each(assigned_proposals, function (student_key, student) {
- var accepted_proposals = student.proposals.length;
- // if accepted proposal are less than 2, then ignore and
- // continue the iteration
- if (accepted_proposals < 2) {
- return true;
- }
- // push this student to the caching JSON
- to_json.data.students[student_key] = student;
- var proposals = student.proposals;
- // call the function that prints the output html
- duplicateSlots.showDuplicatesHtml(
- orgs_details, student, student_key, proposals
- );
- });
- /*jslint undef:false */
- if (html_string === "") {
- /*jslint undef:true */
- jQuery("#div_duplicate_slots")
- .html("<strong>No duplicate slots found</strong>");
- }
- // at the end, send the JSON for caching purposes
- jQuery.ajax({
- url: location.href,
- type: 'POST',
- processData: true,
- data: {result: JSON.stringify(to_json)},
- contentType: 'application/json',
- dataType: 'json'
- });
- }
-
- // private function to load a JSON and pushing the data to the
- // private global variables
- function loadSingleJSONData(data) {
- if (data) {
- // pushing org details
- jQuery.each(data.data.orgs, function (org_key, organization) {
- orgs_details[org_key] = organization;
- });
- // pushing proposals
- jQuery(data.data.proposals).each(
- function (intIndex, proposal) {
- // if this student_key is not yet present
- if (assigned_proposals[proposal.student_key] === undefined) {
- // create the object and insert general info
- assigned_proposals[proposal.student_key] = {};
- assigned_proposals[proposal.student_key].name =
- proposal.student_name;
- assigned_proposals[proposal.student_key].contact =
- proposal.student_contact;
- assigned_proposals[proposal.student_key].proposals = [];
- }
- // anyway, push the accepted proposals
- assigned_proposals[proposal.student_key].proposals.push(
- {
- "org_key" : proposal.org_key,
- "proposal_key" : proposal.key_name,
- "proposal_title": proposal.proposal_title
- }
- );
- }
- );
- }
- }
-
- function showDuplicates(url_to_query, OFFSET_LENGTH, NUMBER_OF_ORGS) {
- var current_offset = 0;
- orgs_details = {};
- assigned_proposals = [];
-
- // Here Ajax call is handled
- setTimeout(
- function () {
- jQuery.ajax({
- cache: false,
- mode: "sync",
- type: "GET",
- timeout: 1000000,
- dataType: "json",
- url: [
- "/program/assigned_proposals/", url_to_query,
- "?limit=", OFFSET_LENGTH,
- "&offset=", current_offset
- ].join(""),
- success: function (data, textStatus) {
- if (data) {
- // Load JSON data
- loadSingleJSONData(data);
- }
- },
- error: function (XMLHttpRequest, textStatus, errorThrown) {
- // if there is an error return the button and
- // leave a try again message
- if (XMLHttpRequest !== undefined) {
- jQuery("#id_button_duplicate_slots").fadeIn("slow",
- function () {
- jQuery("#description_done").html([
- "<strong class='error'> ",
- "Error encountered, try again",
- "</strong>"
- ].join(""));
- }
- );
- }
- }
- });
- current_offset += OFFSET_LENGTH;
- if (current_offset < NUMBER_OF_ORGS) {
- setTimeout(arguments.callee, 1);
- }
- },
- 1
- );
- // This prevent page reloading after each ajax call
- return false;
- }
-
- // public function to begin iterating load of JSONs and then call printing
- // of duplicates
-
- duplicateSlots.showDuplicatesInit = function () {
- /*jslint undef:false */
- html_string = '';
- // Remember this object for Javascript scoping
- var this_object = this;
- var NUMBER_OF_ORGS = number_of_orgs;
- var OFFSET_LENGTH = offset_length;
- /*jslint undef:true */
- // Variables to handle progress bar updating
- var ITERATIONS = (number_of_orgs % offset_length) === 0 ?
- Math.floor(number_of_orgs / offset_length) :
- Math.floor(number_of_orgs / offset_length) + 1;
-
- if (ITERATIONS === 0) {
- jQuery("#div_duplicate_slots")
- .html("<strong>No org slots to process</strong>");
- return;
- }
-
- var successful_calls = 0;
-
- jQuery("#id_button_duplicate_slots").fadeOut("slow",
- function () {
- jQuery("#duplicates_progress_bar").progressBar(0);
- jQuery("#description_done").html("");
- // For every ajax success, bind this function to update user feedback
- jQuery(this).bind("ajaxSuccess", function () {
- successful_calls++;
- var percentage = Math.floor(100 * (successful_calls) / (ITERATIONS));
- jQuery("#duplicates_progress_bar").progressBar(percentage);
- jQuery("#description_progressbar").html([
- " Processed orgs chunk ", successful_calls, "/", ITERATIONS
- ].join(""));
- // If this is the last call, feedback the user and
- // print the duplicates data
- if (successful_calls === ITERATIONS) {
- jQuery("#applications_progress_bar").fadeOut("slow",
- function () {
- jQuery("#duplicates_progress_bar").progressBar(0);
- jQuery("#id_button_duplicate_slots").fadeIn("slow");
- }
- );
- jQuery("#description_progressbar").html("");
- jQuery("#description_done").html("<strong> Done!</strong>");
- jQuery("#duplicates_progress_bar").fadeOut("slow",
- function () {
- jQuery("#id_button_duplicate_slots").val("Recalculate").fadeIn(
- "slow",
- function () {
- // Call printing to HTML function with correct scope
- printDuplicatesAndSendJSON.call(this_object);
- }
- );
- }
- );
- }
- });
- // Call the showDuplicates function for the first time
- // with correct scope
- jQuery("#duplicates_progress_bar").fadeIn(
- "slow",
- showDuplicates.apply(
- this_object,
- /*jslint undef:false */
- [url_to_query, OFFSET_LENGTH, NUMBER_OF_ORGS]
- /*jslint undef:true */
- )
- );
- }
- );
- };
-}());
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/content/js/duplicate-slots-090825.js Tue Aug 25 16:15:07 2009 +0100
@@ -0,0 +1,262 @@
+(function () {
+ var duplicateSlots = window.duplicateSlots = function () {
+ };
+ // this variable will contain all the org details, and filled
+ // incrementally
+ var orgs_details = {};
+ // this variable will contain all student/proposal data details,
+ // filled incrementally
+ var assigned_proposals = [];
+
+ // public function to output actual HTML out of the data (cached or not)
+ duplicateSlots.showDuplicatesHtml =
+ function (orgs_details, student, student_key, proposals) {
+ /*jslint undef:false */
+ if (html_string === '') {
+ jQuery("#div_duplicate_slots").html('');
+ html_string = '<ul>';
+ }
+ html_string += [
+ '<li>',
+ ' Student: ',
+ ' <strong>',
+ ' <a href="/student/show/', student_key, '">', student.name,
+ '</a>',
+ ' </strong> ',
+ '(<a href="mailto:', student.contact, '">', student.contact, '</a>)'
+ ].join("");
+ html_string += '<ul>';
+ jQuery(proposals).each(
+ function (intIndex, proposal) {
+ html_string += [
+ '<li>',
+ ' Organization: ',
+ ' <a href="/org/show/', proposal.org_key, '">',
+ orgs_details[proposal.org_key].name,
+ '</a>, admin: ', orgs_details[proposal.org_key].admin_name,
+ ' (<a href="mailto:',
+ orgs_details[proposal.org_key].admin_email,
+ '">',
+ orgs_details[proposal.org_key].admin_email, '</a>)</li>'
+ ].join("");
+ html_string += [
+ '<ul>',
+ ' <li>',
+ 'Proposal: ',
+ '<a href="/student_proposal/show/', proposal.proposal_key, '">',
+ proposal.proposal_title, '</a>',
+ ' </li>',
+ '</ul>'
+ ].join("");
+ }
+ );
+ html_string += '</ul></li>';
+ html_string += '</ul>';
+ jQuery("#div_duplicate_slots").html(html_string);
+ /*jslint undef:true */
+ };
+
+ // private function to generate the JSON to send for caching and calling
+ // the actual function that will print the data
+ function printDuplicatesAndSendJSON() {
+ // JSON skeleton that need to be sent to the server
+ var to_json = {
+ "data": {
+ "orgs" : orgs_details,
+ "students": {}
+ }
+ };
+ // for every student...
+ jQuery.each(assigned_proposals, function (student_key, student) {
+ var accepted_proposals = student.proposals.length;
+ // if accepted proposal are less than 2, then ignore and
+ // continue the iteration
+ if (accepted_proposals < 2) {
+ return true;
+ }
+ // push this student to the caching JSON
+ to_json.data.students[student_key] = student;
+ var proposals = student.proposals;
+ // call the function that prints the output html
+ duplicateSlots.showDuplicatesHtml(
+ orgs_details, student, student_key, proposals
+ );
+ });
+ /*jslint undef:false */
+ if (html_string === "") {
+ /*jslint undef:true */
+ jQuery("#div_duplicate_slots")
+ .html("<strong>No duplicate slots found</strong>");
+ }
+ // at the end, send the JSON for caching purposes
+ jQuery.ajax({
+ url: location.href,
+ type: 'POST',
+ processData: true,
+ data: {result: JSON.stringify(to_json)},
+ contentType: 'application/json',
+ dataType: 'json'
+ });
+ }
+
+ // private function to load a JSON and pushing the data to the
+ // private global variables
+ function loadSingleJSONData(data) {
+ if (data) {
+ // pushing org details
+ jQuery.each(data.data.orgs, function (org_key, organization) {
+ orgs_details[org_key] = organization;
+ });
+ // pushing proposals
+ jQuery(data.data.proposals).each(
+ function (intIndex, proposal) {
+ // if this student_key is not yet present
+ if (assigned_proposals[proposal.student_key] === undefined) {
+ // create the object and insert general info
+ assigned_proposals[proposal.student_key] = {};
+ assigned_proposals[proposal.student_key].name =
+ proposal.student_name;
+ assigned_proposals[proposal.student_key].contact =
+ proposal.student_contact;
+ assigned_proposals[proposal.student_key].proposals = [];
+ }
+ // anyway, push the accepted proposals
+ assigned_proposals[proposal.student_key].proposals.push(
+ {
+ "org_key" : proposal.org_key,
+ "proposal_key" : proposal.key_name,
+ "proposal_title": proposal.proposal_title
+ }
+ );
+ }
+ );
+ }
+ }
+
+ function showDuplicates(url_to_query, OFFSET_LENGTH, NUMBER_OF_ORGS) {
+ var current_offset = 0;
+ orgs_details = {};
+ assigned_proposals = [];
+
+ // Here Ajax call is handled
+ setTimeout(
+ function () {
+ jQuery.ajax({
+ cache: false,
+ mode: "sync",
+ type: "GET",
+ timeout: 1000000,
+ dataType: "json",
+ url: [
+ "/program/assigned_proposals/", url_to_query,
+ "?limit=", OFFSET_LENGTH,
+ "&offset=", current_offset
+ ].join(""),
+ success: function (data, textStatus) {
+ if (data) {
+ // Load JSON data
+ loadSingleJSONData(data);
+ }
+ },
+ error: function (XMLHttpRequest, textStatus, errorThrown) {
+ // if there is an error return the button and
+ // leave a try again message
+ if (XMLHttpRequest !== undefined) {
+ jQuery("#id_button_duplicate_slots").fadeIn("slow",
+ function () {
+ jQuery("#description_done").html([
+ "<strong class='error'> ",
+ "Error encountered, try again",
+ "</strong>"
+ ].join(""));
+ }
+ );
+ }
+ }
+ });
+ current_offset += OFFSET_LENGTH;
+ if (current_offset < NUMBER_OF_ORGS) {
+ setTimeout(arguments.callee, 1);
+ }
+ },
+ 1
+ );
+ // This prevent page reloading after each ajax call
+ return false;
+ }
+
+ // public function to begin iterating load of JSONs and then call printing
+ // of duplicates
+
+ duplicateSlots.showDuplicatesInit = function () {
+ /*jslint undef:false */
+ html_string = '';
+ // Remember this object for Javascript scoping
+ var this_object = this;
+ var NUMBER_OF_ORGS = number_of_orgs;
+ var OFFSET_LENGTH = offset_length;
+ /*jslint undef:true */
+ // Variables to handle progress bar updating
+ var ITERATIONS = (number_of_orgs % offset_length) === 0 ?
+ Math.floor(number_of_orgs / offset_length) :
+ Math.floor(number_of_orgs / offset_length) + 1;
+
+ if (ITERATIONS === 0) {
+ jQuery("#div_duplicate_slots")
+ .html("<strong>No org slots to process</strong>");
+ return;
+ }
+
+ var successful_calls = 0;
+
+ jQuery("#id_button_duplicate_slots").fadeOut("slow",
+ function () {
+ jQuery("#duplicates_progress_bar").progressBar(0);
+ jQuery("#description_done").html("");
+ // For every ajax success, bind this function to update user feedback
+ jQuery(this).bind("ajaxSuccess", function () {
+ successful_calls++;
+ var percentage = Math.floor(100 * (successful_calls) / (ITERATIONS));
+ jQuery("#duplicates_progress_bar").progressBar(percentage);
+ jQuery("#description_progressbar").html([
+ " Processed orgs chunk ", successful_calls, "/", ITERATIONS
+ ].join(""));
+ // If this is the last call, feedback the user and
+ // print the duplicates data
+ if (successful_calls === ITERATIONS) {
+ jQuery("#applications_progress_bar").fadeOut("slow",
+ function () {
+ jQuery("#duplicates_progress_bar").progressBar(0);
+ jQuery("#id_button_duplicate_slots").fadeIn("slow");
+ }
+ );
+ jQuery("#description_progressbar").html("");
+ jQuery("#description_done").html("<strong> Done!</strong>");
+ jQuery("#duplicates_progress_bar").fadeOut("slow",
+ function () {
+ jQuery("#id_button_duplicate_slots").val("Recalculate").fadeIn(
+ "slow",
+ function () {
+ // Call printing to HTML function with correct scope
+ printDuplicatesAndSendJSON.call(this_object);
+ }
+ );
+ }
+ );
+ }
+ });
+ // Call the showDuplicates function for the first time
+ // with correct scope
+ jQuery("#duplicates_progress_bar").fadeIn(
+ "slow",
+ showDuplicates.apply(
+ this_object,
+ /*jslint undef:false */
+ [url_to_query, OFFSET_LENGTH, NUMBER_OF_ORGS]
+ /*jslint undef:true */
+ )
+ );
+ }
+ );
+ };
+}());
\ No newline at end of file
--- a/app/soc/content/js/map-090730.js Tue Aug 25 15:58:30 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,347 +0,0 @@
-(function () {
- var role_profile_gmap = window.role_profile_gmap = function () {
- };
-
- // Create global variables
- var map;
- var marker;
- var geocoder;
-
- // The following strings can be customized to reflect ids in the page.
- // You can also add or remove fields used for GMap Geocoding in
- // the JSON address object
-
- var current_lat = 0;
- var current_lng = 0;
-
- // Two different levels for zoom: Starting one and an inner that
- // is used when showing the map if lat and lon page fields are set
- var world_zoom = 0;
- var country_zoom = 4;
- var state_zoom = 6;
- var city_zoom = 10;
- var address_zoom = 13;
-
- // Do not add a starting # as this JQuery selector seems
- // incompatible with GMap API
- var map_div = "role_profile_map";
-
- var field_lat = "#id_latitude";
- var field_lng = "#id_longitude";
- // Need to save old values to avoid unwanted updating
- // of lat and lot if marker dragged and blur another time an address field
- var address = {
- street: {
- id: "#id_res_street",
- old_value: ""
- },
- city: {
- id: "#id_res_city",
- old_value: ""
- },
- state: {
- id: "#id_res_state",
- old_value: ""
- },
- country: {
- id: "#id_res_country",
- old_value: ""
- },
- postalcode: {
- id: "#id_res_postalcode",
- old_value: ""
- }
- };
-
- // Save current address fields in the JSON Object
- function saveOldAddress() {
- jQuery.each(address, function (level, level_details) {
- level_details.old_value = jQuery(level_details.id).val();
- });
- }
-
- // Return true if the user has edited address fields
- function isNewAddress() {
- var is_new = false;
- jQuery.each(address, function (level, level_details) {
- if (jQuery(level_details.id).val() !== level_details.old_value) {
- is_new = true;
- return false;
- }
- });
- return is_new;
- }
-
- // Write saved lat and lng values to page fields
- function setLatLngFields() {
- jQuery(field_lat).val(current_lat);
- jQuery(field_lng).val(current_lng);
- }
-
- // Read lat and lng fields and store them
- function readLatLngFields() {
- current_lat = jQuery(field_lat).val();
- current_lng = jQuery(field_lng).val();
- }
-
- // This function reads address fields, merge them and uses
- // GMap API geocoding to find the first hit
- // Using geocoding
- // http://code.google.com/intl/it-IT/apis/maps/documentation/
- // services.html#Geocoding
- function calculateAddress() {
- // If the user has really edited address fields...
- if (isNewAddress()) {
- // Merge address fields
- var address_string = "";
- jQuery.each(address, function (level, level_details) {
- address_string += jQuery(level_details.id).val() + ",";
- });
-
- // Ask GMap API for geocoding
- geocoder.getLatLng(
- address_string,
- function (point) {
- // If a point is found
- if (point) {
- // Save the current address in the JSON object
- saveOldAddress();
- // Set the new zoom, map center and marker coords
- var zoom_set = world_zoom;
- if (jQuery(address.street.id).val() !== "") {
- zoom_set = address_zoom;
- }
- else if (jQuery(address.city.id).val() !== "") {
- zoom_set = city_zoom;
- }
- else if (jQuery(address.state.id).val() !== "") {
- zoom_set = state_zoom;
- }
- else if (jQuery(address.country.id).val() !== "") {
- zoom_set = country_zoom;
- }
- map.setCenter(point, zoom_set);
- marker.setPoint(point);
- map.clearOverlays();
- map.addOverlay(marker);
- // Save point coords in local variables and then update
- // the page lat/lng fields
- current_lat = point.lat();
- current_lng = point.lng();
- setLatLngFields();
- }
- }
- );
- }
- }
-
- // Public function to load the map
- role_profile_gmap.map_load = function () {
- // All can happen only if there is gmap compatible browser.
- // TODO: Fallback in case the browser is not compatible
- if (window.GBrowserIsCompatible()) {
- // Save the address fields. This is useful if the page is being edited
- // to not update blindly the lat/lng fields with GMap geocoding if
- // blurring an address field
- saveOldAddress();
- var starting_point;
- var zoom_selected = world_zoom;
- var show_marker = true;
-
- // Create the map and add small controls
- map = new window.GMap2(document.getElementById(map_div));
- map.addControl(new window.GSmallMapControl());
- map.addControl(new window.GMapTypeControl());
-
- // Instantiate a global geocoder for future use
- geocoder = new window.GClientGeocoder();
-
- // If lat and lng fields are not void (the page is being edited) then
- // update the starting coords, modify the zoom level and tells following
- // code to show the marker
- if (jQuery(field_lat).val() !== "" && jQuery(field_lng).val() !== "") {
- readLatLngFields();
- zoom_selected = address_zoom;
- show_marker = true;
- }
-
- // Set map center, marker coords and show it if this is an editing
- starting_point = new window.GLatLng(current_lat, current_lng);
- map.setCenter(starting_point, zoom_selected);
- marker = new window.GMarker(starting_point, {draggable: true});
- if (show_marker) {
- map.addOverlay(marker);
- }
-
- // Adds a new event listener to geocode the address when an address
- // field is blurred
- jQuery.each(address, function (level, level_details) {
- jQuery(level_details.id).blur(calculateAddress);
- });
-
- // Adds a new event listener: if the marker has been dragged around...
- window.GEvent.addListener(marker, "dragend", function () {
- // Update internal variables with current marker coords...
- current_lat = marker.getPoint().lat();
- current_lng = marker.getPoint().lng();
- // ...and set page fields accordingly
- setLatLngFields();
- });
- }
- };
-}());
-
-(function () {
- var org_home_gmap = window.org_home_gmap = function () {
- };
- // Global variables
- var map;
-
- // HTML div tag where map needs to be inserted
- var map_div = "org_home_map";
-
- // Setup required icons
- var base_icon = new window.GIcon();
- base_icon.shadow = "http://www.google.com/mapfiles/shadow50.png";
- base_icon.iconSize = new window.GSize(20, 34);
- base_icon.shadowSize = new window.GSize(37, 34);
- base_icon.iconAnchor = new window.GPoint(9, 34);
- base_icon.infoWindowAnchor = new window.GPoint(9, 2);
- base_icon.infoShadowAnchor = new window.GPoint(18, 25);
- var student_icon = new window.GIcon(base_icon);
- student_icon.image = "http://www.google.com/mapfiles/marker.png";
- var mentor_icon = new window.GIcon(base_icon);
- mentor_icon.image = "/soc/content/images/mentor-marker.png";
-
- // Map load function
- org_home_gmap.map_load = function (map_data) {
-
- if (window.GBrowserIsCompatible()) {
- // Create the map and add small controls
- map = new window.GMap2(document.getElementById(map_div));
- map.addControl(new window.GLargeMapControl());
- map.addControl(new window.GMapTypeControl());
-
- // Set map center and initial zoom level
- map.setCenter(new window.GLatLng(0, 0), 1);
-
- var mentors = {};
- var students = {};
- var projects = {};
- var polylines = [];
-
- jQuery.each(map_data.people, function (key, person) {
- if (person.type === "student") {
- students[key] = {
- "name": person.name,
- "lat": person.lat,
- "long": person.long,
- "projects": person.projects
- };
- }
- if (person.type === "mentor") {
- mentors[key] = {
- "name": person.name,
- "lat": person.lat,
- "long": person.long,
- "projects": person.projects
- };
- }
- });
-
- // Iterate over projects to draw polylines
- jQuery.each(map_data.projects, function (key, project) {
- var current_student = students[project.student_key];
- var current_mentor = mentors[project.mentor_key];
- if (current_student !== undefined &&
- current_mentor !== undefined &&
- current_student.lat !== null &&
- current_student.long !== null &&
- current_mentor.lat !== null &&
- current_mentor.long !== null) {
- /*jslint white: false */
- polylines.push([
- [current_student.lat, current_student.long],
- [current_mentor.lat, current_mentor.long]
- ]);
- /*jslint white: true */
- }
- });
-
- // Iterate over students
- jQuery.each(students, function (key, person) {
- var html = "";
- var marker = null;
-
- if (person.lat !== null && person.long !== null) {
- var point = new window.GLatLng(person.lat, person.long);
-
- marker = new window.GMarker(point, student_icon);
- html = [
- "<strong>", person.name, "</strong><br />",
- "<span style='font-style:italic;'>Student</span><br />",
- "<div style='height:100px;width:300px;",
- "overflow:auto;font-size:70%'>"
- ].join("");
- // iterate through projects
- jQuery.each(person.projects, function () {
- var current_project = map_data.projects[this];
- html += [
- "<a href='", current_project.redirect, "'>",
- current_project.title, "</a><br />",
- "Mentor: ", current_project.mentor_name, "<br />"
- ].join("");
- });
- html += "</div>";
- window.GEvent.addListener(marker, "click", function () {
- marker.openInfoWindowHtml(html);
- });
-
- map.addOverlay(marker);
- }
- });
-
- // Iterate over mentors
- jQuery.each(mentors, function (key, person) {
- var html = "";
- var marker = null;
-
- if (person.lat !== null && person.long !== null) {
- var point = new window.GLatLng(person.lat, person.long);
-
- marker = new window.GMarker(point, mentor_icon);
- html = [
- "<strong>", person.name, "</strong><br />",
- "<span style='font-style:italic;'>Mentor</span><br />",
- "<div style='height:100px;width:300px;",
- "overflow:auto;font-size:70%'>"
- ].join("");
- // iterate through projects
- jQuery.each(person.projects, function () {
- var current_project = map_data.projects[this];
- html += [
- "<a href='", current_project.redirect, "'>",
- current_project.title, "</a><br />",
- "Student: ", current_project.student_name, "<br />"
- ].join("");
- });
- html += "</div>";
-
- window.GEvent.addListener(marker, "click", function () {
- marker.openInfoWindowHtml(html);
- });
-
- map.addOverlay(marker);
- }
- });
-
- // Draw all polylines
- jQuery.each(polylines, function () {
- var from = new window.GLatLng(this[0][0], this[0][1]);
- var to = new window.GLatLng(this[1][0], this[1][1]);
- var polyline = new window.GPolyline([from, to], "#ff0000", 3);
- map.addOverlay(polyline);
- });
- }
- };
-}());
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/content/js/map-090825.js Tue Aug 25 16:15:07 2009 +0100
@@ -0,0 +1,347 @@
+(function () {
+ var role_profile_gmap = window.role_profile_gmap = function () {
+ };
+
+ // Create global variables
+ var map;
+ var marker;
+ var geocoder;
+
+ // The following strings can be customized to reflect ids in the page.
+ // You can also add or remove fields used for GMap Geocoding in
+ // the JSON address object
+
+ var current_lat = 0;
+ var current_lng = 0;
+
+ // Two different levels for zoom: Starting one and an inner that
+ // is used when showing the map if lat and lon page fields are set
+ var world_zoom = 0;
+ var country_zoom = 4;
+ var state_zoom = 6;
+ var city_zoom = 10;
+ var address_zoom = 13;
+
+ // Do not add a starting # as this JQuery selector seems
+ // incompatible with GMap API
+ var map_div = "role_profile_map";
+
+ var field_lat = "#id_latitude";
+ var field_lng = "#id_longitude";
+ // Need to save old values to avoid unwanted updating
+ // of lat and lot if marker dragged and blur another time an address field
+ var address = {
+ street: {
+ id: "#id_res_street",
+ old_value: ""
+ },
+ city: {
+ id: "#id_res_city",
+ old_value: ""
+ },
+ state: {
+ id: "#id_res_state",
+ old_value: ""
+ },
+ country: {
+ id: "#id_res_country",
+ old_value: ""
+ },
+ postalcode: {
+ id: "#id_res_postalcode",
+ old_value: ""
+ }
+ };
+
+ // Save current address fields in the JSON Object
+ function saveOldAddress() {
+ jQuery.each(address, function (level, level_details) {
+ level_details.old_value = jQuery(level_details.id).val();
+ });
+ }
+
+ // Return true if the user has edited address fields
+ function isNewAddress() {
+ var is_new = false;
+ jQuery.each(address, function (level, level_details) {
+ if (jQuery(level_details.id).val() !== level_details.old_value) {
+ is_new = true;
+ return false;
+ }
+ });
+ return is_new;
+ }
+
+ // Write saved lat and lng values to page fields
+ function setLatLngFields() {
+ jQuery(field_lat).val(current_lat);
+ jQuery(field_lng).val(current_lng);
+ }
+
+ // Read lat and lng fields and store them
+ function readLatLngFields() {
+ current_lat = jQuery(field_lat).val();
+ current_lng = jQuery(field_lng).val();
+ }
+
+ // This function reads address fields, merge them and uses
+ // GMap API geocoding to find the first hit
+ // Using geocoding
+ // http://code.google.com/intl/it-IT/apis/maps/documentation/
+ // services.html#Geocoding
+ function calculateAddress() {
+ // If the user has really edited address fields...
+ if (isNewAddress()) {
+ // Merge address fields
+ var address_string = "";
+ jQuery.each(address, function (level, level_details) {
+ address_string += jQuery(level_details.id).val() + ",";
+ });
+
+ // Ask GMap API for geocoding
+ geocoder.getLatLng(
+ address_string,
+ function (point) {
+ // If a point is found
+ if (point) {
+ // Save the current address in the JSON object
+ saveOldAddress();
+ // Set the new zoom, map center and marker coords
+ var zoom_set = world_zoom;
+ if (jQuery(address.street.id).val() !== "") {
+ zoom_set = address_zoom;
+ }
+ else if (jQuery(address.city.id).val() !== "") {
+ zoom_set = city_zoom;
+ }
+ else if (jQuery(address.state.id).val() !== "") {
+ zoom_set = state_zoom;
+ }
+ else if (jQuery(address.country.id).val() !== "") {
+ zoom_set = country_zoom;
+ }
+ map.setCenter(point, zoom_set);
+ marker.setPoint(point);
+ map.clearOverlays();
+ map.addOverlay(marker);
+ // Save point coords in local variables and then update
+ // the page lat/lng fields
+ current_lat = point.lat();
+ current_lng = point.lng();
+ setLatLngFields();
+ }
+ }
+ );
+ }
+ }
+
+ // Public function to load the map
+ role_profile_gmap.map_load = function () {
+ // All can happen only if there is gmap compatible browser.
+ // TODO: Fallback in case the browser is not compatible
+ if (window.GBrowserIsCompatible()) {
+ // Save the address fields. This is useful if the page is being edited
+ // to not update blindly the lat/lng fields with GMap geocoding if
+ // blurring an address field
+ saveOldAddress();
+ var starting_point;
+ var zoom_selected = world_zoom;
+ var show_marker = true;
+
+ // Create the map and add small controls
+ map = new window.GMap2(document.getElementById(map_div));
+ map.addControl(new window.GSmallMapControl());
+ map.addControl(new window.GMapTypeControl());
+
+ // Instantiate a global geocoder for future use
+ geocoder = new window.GClientGeocoder();
+
+ // If lat and lng fields are not void (the page is being edited) then
+ // update the starting coords, modify the zoom level and tells following
+ // code to show the marker
+ if (jQuery(field_lat).val() !== "" && jQuery(field_lng).val() !== "") {
+ readLatLngFields();
+ zoom_selected = address_zoom;
+ show_marker = true;
+ }
+
+ // Set map center, marker coords and show it if this is an editing
+ starting_point = new window.GLatLng(current_lat, current_lng);
+ map.setCenter(starting_point, zoom_selected);
+ marker = new window.GMarker(starting_point, {draggable: true});
+ if (show_marker) {
+ map.addOverlay(marker);
+ }
+
+ // Adds a new event listener to geocode the address when an address
+ // field is blurred
+ jQuery.each(address, function (level, level_details) {
+ jQuery(level_details.id).blur(calculateAddress);
+ });
+
+ // Adds a new event listener: if the marker has been dragged around...
+ window.GEvent.addListener(marker, "dragend", function () {
+ // Update internal variables with current marker coords...
+ current_lat = marker.getPoint().lat();
+ current_lng = marker.getPoint().lng();
+ // ...and set page fields accordingly
+ setLatLngFields();
+ });
+ }
+ };
+}());
+
+(function () {
+ var org_home_gmap = window.org_home_gmap = function () {
+ };
+ // Global variables
+ var map;
+
+ // HTML div tag where map needs to be inserted
+ var map_div = "org_home_map";
+
+ // Setup required icons
+ var base_icon = new window.GIcon();
+ base_icon.shadow = "http://www.google.com/mapfiles/shadow50.png";
+ base_icon.iconSize = new window.GSize(20, 34);
+ base_icon.shadowSize = new window.GSize(37, 34);
+ base_icon.iconAnchor = new window.GPoint(9, 34);
+ base_icon.infoWindowAnchor = new window.GPoint(9, 2);
+ base_icon.infoShadowAnchor = new window.GPoint(18, 25);
+ var student_icon = new window.GIcon(base_icon);
+ student_icon.image = "http://www.google.com/mapfiles/marker.png";
+ var mentor_icon = new window.GIcon(base_icon);
+ mentor_icon.image = "/soc/content/images/mentor-marker.png";
+
+ // Map load function
+ org_home_gmap.map_load = function (map_data) {
+
+ if (window.GBrowserIsCompatible()) {
+ // Create the map and add small controls
+ map = new window.GMap2(document.getElementById(map_div));
+ map.addControl(new window.GLargeMapControl());
+ map.addControl(new window.GMapTypeControl());
+
+ // Set map center and initial zoom level
+ map.setCenter(new window.GLatLng(0, 0), 1);
+
+ var mentors = {};
+ var students = {};
+ var projects = {};
+ var polylines = [];
+
+ jQuery.each(map_data.people, function (key, person) {
+ if (person.type === "student") {
+ students[key] = {
+ "name": person.name,
+ "lat": person.lat,
+ "long": person.long,
+ "projects": person.projects
+ };
+ }
+ if (person.type === "mentor") {
+ mentors[key] = {
+ "name": person.name,
+ "lat": person.lat,
+ "long": person.long,
+ "projects": person.projects
+ };
+ }
+ });
+
+ // Iterate over projects to draw polylines
+ jQuery.each(map_data.projects, function (key, project) {
+ var current_student = students[project.student_key];
+ var current_mentor = mentors[project.mentor_key];
+ if (current_student !== undefined &&
+ current_mentor !== undefined &&
+ current_student.lat !== null &&
+ current_student.long !== null &&
+ current_mentor.lat !== null &&
+ current_mentor.long !== null) {
+ /*jslint white: false */
+ polylines.push([
+ [current_student.lat, current_student.long],
+ [current_mentor.lat, current_mentor.long]
+ ]);
+ /*jslint white: true */
+ }
+ });
+
+ // Iterate over students
+ jQuery.each(students, function (key, person) {
+ var html = "";
+ var marker = null;
+
+ if (person.lat !== null && person.long !== null) {
+ var point = new window.GLatLng(person.lat, person.long);
+
+ marker = new window.GMarker(point, student_icon);
+ html = [
+ "<strong>", person.name, "</strong><br />",
+ "<span style='font-style:italic;'>Student</span><br />",
+ "<div style='height:100px;width:300px;",
+ "overflow:auto;font-size:70%'>"
+ ].join("");
+ // iterate through projects
+ jQuery.each(person.projects, function () {
+ var current_project = map_data.projects[this];
+ html += [
+ "<a href='", current_project.redirect, "'>",
+ current_project.title, "</a><br />",
+ "Mentor: ", current_project.mentor_name, "<br />"
+ ].join("");
+ });
+ html += "</div>";
+ window.GEvent.addListener(marker, "click", function () {
+ marker.openInfoWindowHtml(html);
+ });
+
+ map.addOverlay(marker);
+ }
+ });
+
+ // Iterate over mentors
+ jQuery.each(mentors, function (key, person) {
+ var html = "";
+ var marker = null;
+
+ if (person.lat !== null && person.long !== null) {
+ var point = new window.GLatLng(person.lat, person.long);
+
+ marker = new window.GMarker(point, mentor_icon);
+ html = [
+ "<strong>", person.name, "</strong><br />",
+ "<span style='font-style:italic;'>Mentor</span><br />",
+ "<div style='height:100px;width:300px;",
+ "overflow:auto;font-size:70%'>"
+ ].join("");
+ // iterate through projects
+ jQuery.each(person.projects, function () {
+ var current_project = map_data.projects[this];
+ html += [
+ "<a href='", current_project.redirect, "'>",
+ current_project.title, "</a><br />",
+ "Student: ", current_project.student_name, "<br />"
+ ].join("");
+ });
+ html += "</div>";
+
+ window.GEvent.addListener(marker, "click", function () {
+ marker.openInfoWindowHtml(html);
+ });
+
+ map.addOverlay(marker);
+ }
+ });
+
+ // Draw all polylines
+ jQuery.each(polylines, function () {
+ var from = new window.GLatLng(this[0][0], this[0][1]);
+ var to = new window.GLatLng(this[1][0], this[1][1]);
+ var polyline = new window.GPolyline([from, to], "#ff0000", 3);
+ map.addOverlay(polyline);
+ });
+ }
+ };
+}());
--- a/app/soc/content/js/menu-081108.js Tue Aug 25 15:58:30 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,24 +0,0 @@
-jQuery(function () {
- var new_item_text = "(new)";
- jQuery('#menu li.expandable').find('a').each(function () {
- if (jQuery(this).text().indexOf(new_item_text) > -1) {
- jQuery(this).css('color', 'red');
- }
- });
-
- jQuery('#side #menu li.expandable > a').dblclick(function () {
- window.location = jQuery(this).attr('href');
- });
-
- jQuery('#side #menu li.expandable > span').toggle(function () {
- jQuery(this).find("img").attr('src', '/soc/content/images/plus.gif')
- .end().parent().children("ul").toggle();
- }, function () {
- jQuery(this).find("img").attr('src', '/soc/content/images/minus.gif')
- .end().parent().children("ul").toggle();
- return false;
- });
-
- jQuery('#side #menu li.expandable > span').contents()
- .before('<img src="/soc/content/images/minus.gif" />');
-});
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/content/js/menu-090825.js Tue Aug 25 16:15:07 2009 +0100
@@ -0,0 +1,24 @@
+jQuery(function () {
+ var new_item_text = "(new)";
+ jQuery('#menu li.expandable').find('a').each(function () {
+ if (jQuery(this).text().indexOf(new_item_text) > -1) {
+ jQuery(this).css('color', 'red');
+ }
+ });
+
+ jQuery('#side #menu li.expandable > a').dblclick(function () {
+ window.location = jQuery(this).attr('href');
+ });
+
+ jQuery('#side #menu li.expandable > span').toggle(function () {
+ jQuery(this).find("img").attr('src', '/soc/content/images/plus.gif')
+ .end().parent().children("ul").toggle();
+ }, function () {
+ jQuery(this).find("img").attr('src', '/soc/content/images/minus.gif')
+ .end().parent().children("ul").toggle();
+ return false;
+ });
+
+ jQuery('#side #menu li.expandable > span').contents()
+ .before('<img src="/soc/content/images/minus.gif" />');
+});
--- a/app/soc/content/js/slot-allocator-090320.js Tue Aug 25 15:58:30 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,110 +0,0 @@
-var current_allocated_slots = 0;
-var current_slots = {};
-var tooltip = [
- "<div class='tooltip'>",
- "<div class='tooltip-body'>",
- "<img src='/soc/content/images/purrInfo.png' alt='' />",
- "<h3>Slots</h3>",
- "<p id='p_assigned_slots'></p>",
- "<p id='p_remaining_slots'></p>",
- "<p id='p_total_slots'></p></div>",
- "<div class='tooltip-bottom'></div>",
- "</div>"
-].join('');
-
-jQuery.postJSON = function (post_url, to_json, callback) {
- jQuery.ajax({
- url: post_url,
- type: 'POST',
- processData: true,
- data: {result: JSON.stringify(to_json)},
- contentType: 'application/json',
- dataType: 'json',
- success: callback
- });
-};
-
-function updateCurrentSlots() {
- current_allocated_slots = 0;
- jQuery.each(current_slots, function (org_id, org_details) {
- current_allocated_slots =
- current_allocated_slots + Number(org_details.slots);
- });
-}
-
-function updateOverlay() {
- updateCurrentSlots();
- var remaining_slots = window.MAX_AVAILABLE_SLOTS - current_allocated_slots;
- jQuery("#p_assigned_slots")
- .html("<strong>Assigned slots:</strong> " + current_allocated_slots);
- jQuery("#p_remaining_slots")
- .html("<strong>Remaining slots:</strong> " + remaining_slots);
-}
-
-function updateFromJSON(data) {
- if (data) {
- jQuery(data.data).each(
- function (intIndex, item) {
- jQuery("#id_spin_slot_count_" + item.link_id).val(item.slots);
- current_slots[item.link_id] = {
- slots: item.slots,
- locked: item.locked,
- adjustment: item.adjustment
- };
- jQuery("#id_locked_slot_" + item.link_id)
- .attr("checked", item.locked);
- jQuery("#id_spin_adjustment_count_" + item.link_id)
- .val(item.adjustment);
- }
- );
- updateOverlay();
- }
-}
-
-function retrieveJSON() {
- jQuery.getJSON(
- window.RETURN_URL + "?_=" + (new Date().getTime()),
- function (data) {
- if (data) {
- updateFromJSON(data);
- }
- }
- );
-}
-
-function reCalculate() {
- var url = window.RETURN_URL + "?_=" + (new Date().getTime());
- Â jQuery.postJSON(url, current_slots, updateFromJSON);
-}
-
-function submit() {
- var url = window.RETURN_URL + "?submit=1&_=" + (new Date().getTime());
- Â jQuery.postJSON(url, current_slots, updateFromJSON);
-}
-
-function load() {
- var url = window.RETURN_URL + "?load=1&_=" + (new Date().getTime());
- Â jQuery.postJSON(url, current_slots, updateFromJSON);
-}
-
-function lockSlots(checkbox) {
- var locked = jQuery(checkbox).attr("checked");
- var re = /^id_locked_slot_(\w*)/;
- var org_link_id = checkbox.id.match(re)[1];
- current_slots[org_link_id].locked = locked;
-}
-
-function assignSlots(counter) {
- var re = /^id_spin_slot_count_(\w*)/;
- var org_link_id = counter.id.match(re)[1];
- current_slots[org_link_id].slots = jQuery(counter).val();
- updateCurrentSlots();
- updateOverlay();
-}
-
-function assignAdjustment(counter) {
- var re = /^id_spin_adjustment_count_(\w*)/;
- var org_link_id = counter.id.match(re)[1];
- current_slots[org_link_id].adjustment = jQuery(counter).val();
-}
-
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/content/js/slot-allocator-090825.js Tue Aug 25 16:15:07 2009 +0100
@@ -0,0 +1,110 @@
+var current_allocated_slots = 0;
+var current_slots = {};
+var tooltip = [
+ "<div class='tooltip'>",
+ "<div class='tooltip-body'>",
+ "<img src='/soc/content/images/purrInfo.png' alt='' />",
+ "<h3>Slots</h3>",
+ "<p id='p_assigned_slots'></p>",
+ "<p id='p_remaining_slots'></p>",
+ "<p id='p_total_slots'></p></div>",
+ "<div class='tooltip-bottom'></div>",
+ "</div>"
+].join('');
+
+jQuery.postJSON = function (post_url, to_json, callback) {
+ jQuery.ajax({
+ url: post_url,
+ type: 'POST',
+ processData: true,
+ data: {result: JSON.stringify(to_json)},
+ contentType: 'application/json',
+ dataType: 'json',
+ success: callback
+ });
+};
+
+function updateCurrentSlots() {
+ current_allocated_slots = 0;
+ jQuery.each(current_slots, function (org_id, org_details) {
+ current_allocated_slots =
+ current_allocated_slots + Number(org_details.slots);
+ });
+}
+
+function updateOverlay() {
+ updateCurrentSlots();
+ var remaining_slots = window.MAX_AVAILABLE_SLOTS - current_allocated_slots;
+ jQuery("#p_assigned_slots")
+ .html("<strong>Assigned slots:</strong> " + current_allocated_slots);
+ jQuery("#p_remaining_slots")
+ .html("<strong>Remaining slots:</strong> " + remaining_slots);
+}
+
+function updateFromJSON(data) {
+ if (data) {
+ jQuery(data.data).each(
+ function (intIndex, item) {
+ jQuery("#id_spin_slot_count_" + item.link_id).val(item.slots);
+ current_slots[item.link_id] = {
+ slots: item.slots,
+ locked: item.locked,
+ adjustment: item.adjustment
+ };
+ jQuery("#id_locked_slot_" + item.link_id)
+ .attr("checked", item.locked);
+ jQuery("#id_spin_adjustment_count_" + item.link_id)
+ .val(item.adjustment);
+ }
+ );
+ updateOverlay();
+ }
+}
+
+function retrieveJSON() {
+ jQuery.getJSON(
+ window.RETURN_URL + "?_=" + (new Date().getTime()),
+ function (data) {
+ if (data) {
+ updateFromJSON(data);
+ }
+ }
+ );
+}
+
+function reCalculate() {
+ var url = window.RETURN_URL + "?_=" + (new Date().getTime());
+ Â jQuery.postJSON(url, current_slots, updateFromJSON);
+}
+
+function submit() {
+ var url = window.RETURN_URL + "?submit=1&_=" + (new Date().getTime());
+ Â jQuery.postJSON(url, current_slots, updateFromJSON);
+}
+
+function load() {
+ var url = window.RETURN_URL + "?load=1&_=" + (new Date().getTime());
+ Â jQuery.postJSON(url, current_slots, updateFromJSON);
+}
+
+function lockSlots(checkbox) {
+ var locked = jQuery(checkbox).attr("checked");
+ var re = /^id_locked_slot_(\w*)/;
+ var org_link_id = checkbox.id.match(re)[1];
+ current_slots[org_link_id].locked = locked;
+}
+
+function assignSlots(counter) {
+ var re = /^id_spin_slot_count_(\w*)/;
+ var org_link_id = counter.id.match(re)[1];
+ current_slots[org_link_id].slots = jQuery(counter).val();
+ updateCurrentSlots();
+ updateOverlay();
+}
+
+function assignAdjustment(counter) {
+ var re = /^id_spin_adjustment_count_(\w*)/;
+ var org_link_id = counter.id.match(re)[1];
+ current_slots[org_link_id].adjustment = jQuery(counter).val();
+}
+
--- a/app/soc/content/js/survey-edit-090708.js Tue Aug 25 15:58:30 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,776 +0,0 @@
- /* Copyright 2009 the Melange authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
-*
-* @author <a href="mailto:ajaksu@gmail.com">Daniel Diniz</a>
-* @author <a href="mailto:jamesalexanderlevy@gmail.com">James Levy</a>
-*/
-
-(function ($) {
-
- var DEFAULT_LONG_ANSWER_TEXT = 'Write a Custom Prompt For This Question...';
- var DEFAULT_SHORT_ANSWER_TEXT = 'Write a Custom Prompt...';
-
- $(function () {
- /*
- * == Set Selectors ==
- *
- */
- var widget = $('div#survey_widget');
-
- widget.parents('td.formfieldvalue:first').css({
- 'float': 'left',
- 'width': 200
- });
-
- /*
- * == Setup for existing surveys ==
- *
- */
-
- if ($('input#id_title').val() === '' && $('.formfielderror').length < 1) {
- widget.find('tr').remove();
- }
-
- widget.find('table:first').show();
-
- /*
- * Restore survey content html from editPost
- * if POST fails
- */
-
- var SURVEY_PREFIX = 'survey__';
- var del_el = ["<a class='delete'><img ",
- "src='/soc/content/images/minus.gif'/></a>"].join("");
- var del_li = ["<a class='delete_item' id='del_",
- "' ><img src='/soc/content/images/minus.gif'/></a> "];
-
- var survey_html = $('form').find("#id_survey_html").attr('value');
-
- function renderHTML() {
- // render existing survey forms
- widget.find('td.twolineformfieldlabel > label').prepend(del_el).end();
-
- $('ol').find('li').each(
- function () {
- $(this).prepend(del_li.join($(this).attr('id'))).end();
- }
- );
- widget.find('.short_answer').each(
- function () {
- $(this).attr('name', SURVEY_PREFIX + $(this).getPosition() +
- 'short_answer__' + $(this).attr('name'));
- }
- );
-
- // add index information to choice fields
- widget.find('[name=create-option-button]').each(
- function () {
- $(
- '#index_for_' + $(this).attr('value')
- )
- .val(
- $(this).getPosition()
- );
- }
- );
-
- widget.find('.long_answer').each(
- function () {
- $(this).attr('name', SURVEY_PREFIX + $(this).getPosition() +
- 'long_answer__' + $(this).attr('name'))
- .attr('overflow', 'auto');
- // TODO: replace scrollbar with jquery autogrow
- }
- );
- }
-
- if (survey_html && survey_html.length > 1) {
- widget.html(survey_html); // we don't need to re-render HTML
-
- widget.find('.long_answer,input').each(
- function () {
- $(this).val($(this).attr('val'));
- }
- );
- }
- else {
- renderHTML();
- }
-
- var survey = widget.find('tbody:first');
- var options = widget.find('#survey_options');
-
- /*
- * == Handle Enter key on dialogs ==
- */
- $('form input, form button, form select').keypress(
- function (e) {
- if ((e.which && e.which === 13) || (e.keyCode && e.keyCode === 13)) {
- $(this).parents('.ui-dialog:first').find(":button:first").click();
- return false;
- }
- }
- );
-
- /*
- * == Display survey answers inline ==
- */
- $('a.fetch_answers').click(
- function () {
- var user = this.id.replace('results_for_', '');
- var path = window.location.pathname;
- path = path.replace('/edit/', '/show/').replace('/results/', '/show/');
-
- // TODO(ajaksu) add Date().getTime() to query arg if needed
- var query = '?read_only=true&user_results=' + user;
- var scrollable = ['<div style="overflow-y: auto; ',
- 'margin-bottom: 100px;"></div>'].join("");
- $(scrollable).load(path + query + ' #survey_widget').dialog({
- title: user,
- height: 500,
- width: 700
- });
- }
- );
-
- /*
- * == Initiation ==
- *
- * Runs on PageLoad and Each Time Field is Added to Survey
- *
- */
-
- survey.bind('init',
- function () {
- // TODO(jamslevy) unnecessarily redundant
- // TODO(jamslevy) This should be refactored as a jQuery function that
- // acts on only a single field and it should be merged with renderHTML
- // since they have comparable functionality.
-
- widget.find('input').each(
- function () {
- if (($(this).val().length < 1 ||
- $(this).val() === DEFAULT_SHORT_ANSWER_TEXT) &&
- ($(this).attr('type') !== 'hidden')) {
- $(this).preserveDefaultText(DEFAULT_SHORT_ANSWER_TEXT);
- }
- }
- );
-
- widget.find('.long_answer, .tooltip_entry').each(
- function () {
- if ($(this).val().length < 1 ||
- $(this).val() === DEFAULT_LONG_ANSWER_TEXT) {
- $(this).preserveDefaultText(DEFAULT_LONG_ANSWER_TEXT);
- }
- $(this).growfield();
- }
- );
-
- widget.find('a.delete img').click(
- function () {
- // delete a field
- var this_field = $(this).parents('tr:first');
- var deleted_id = $(this_field).find('label').attr('for');
- var delete_this = confirm(["Deleting this field will remove all ",
- "answers submitted for this field. ",
- "Continue?"].join(""));
- if (delete_this) {
- var edit_form = $('#EditForm');
- var deleted_field = $('#__deleted__');
- if (deleted_field.val()) {
- deleted_field.val(deleted_field.val() + ',' +
- deleted_id.replace('id_', '')).end();
- }
- else {
- var deleted_input = $("<input type='hidden' value='" +
- deleted_id.replace('id_', '') + "' />");
- deleted_input.attr({'id': '__deleted__'}).attr({
- 'name': '__deleted__'
- });
- edit_form.append(deleted_input);
- }
- this_field.next('tr').remove().end()
- .remove();
- }
- }
- );
-
- // Add list/choice-field item to survey
- $('[name=create-option-button]').each(
- function () {
- $(this).click(
- function () {
- var new_option_val = $('#new_item_field_ul_id');
- var new_option_dialog = $("#new_item_dialog");
-
- new_option_val.val($(this).parents('fieldset').children('ol')
- .attr('id'));
-
- new_option_dialog.dialog('open').find('input:first').focus();
- }
- )
- .hover(
- function () {
- $(this).addClass("ui-state-hover");
- },
- function () {
- $(this).removeClass("ui-state-hover");
- }
- )
- .mousedown(
- function () {
- $(this).addClass("ui-state-active");
- }
- )
- .mouseup(
- function () {
- $(this).removeClass("ui-state-active");
- }
- );
- }
- );
-
- options.find('.AddQuestion').click(
- function (e) {
- // Choose a field type
- $("#new_question_button_id").val($(this).attr('id'));
- var question_options_div = $('#question_options_div');
- if ($(this).attr('id') === 'choice') {
- question_options_div.show();
- }
- else {
- question_options_div.hide();
- }
-
- $("#new_question_dialog").dialog('open').find('input:first')
- .focus();
- }
- );
- }).trigger('init')
- .bind('option_init',
- function () {
-
- // Delete list/choice-field item from survey
- widget.find('a.delete_item').click(
- function () {
- var to_delete = this.id.replace('del_', '');
- $('#delete_item_field').val(to_delete);
- $('#delete_item_dialog').dialog('open');
- }
- ).end();
-
- }
- ).trigger('option_init');
-
-
- /* GSOC ROLE-SPECIFIC FIELD PLUGIN
- * Choice between student/mentor renders required GSOC specific fields
- */
-
- var taking_access_field = $('select#id_taking_access');
-
- var addRoleFields = function (role_type) {
- // these should ideally be generated with django forms
- // TODO: apply info tooltips
- var CHOOSE_A_PROJECT_FIELD = [
- '<tr class="role-specific"><th><label>Choose Project:</label></th>',
- '<td> <select disabled=TRUE id="id_survey__NA__selection__project"',
- ' name="survey__1__selection__see"><option>Survey Taker\'s Projects',
- 'For This Program</option></select> </td></tr>'
- ].join("");
-
- var CHOOSE_A_GRADE_FIELD = [
- '<tr class="role-specific"><th><label>Assign Grade:</label></th><td>',
- '<select disabled=TRUE id="id_survey__NA__selection__grade"',
- 'name="survey__1__selection__see"><option>Pass/Fail</option></select>',
- '</td></tr>'
- ].join("");
-
- // flush existing role-specific fields
- var role_specific_fields = survey.find('tr.role-specific');
- role_specific_fields.remove();
-
- switch (role_type) {
- case "mentor evaluation":
- survey.prepend(CHOOSE_A_PROJECT_FIELD);
- survey.append(CHOOSE_A_GRADE_FIELD);
- break;
-
- case "student evaluation":
- survey.prepend(CHOOSE_A_PROJECT_FIELD);
- break;
- }
- };
-
- taking_access_field.change(
- function () {
- var role_type = $(this).val();
- addRoleFields(role_type);
- }
- );
-
- addRoleFields(taking_access_field.val());
-
- /*
- * == Survey Submission Handler ==
- */
- // Bind submit
- $('form').bind('submit',
- function () {
-
- /*
- * get rid of role-specific fields
- */
- survey.find('tr.role-specific').remove();
-
- /*
- * Save survey content html from editPost
- * if POST fails
- */
-
- // save field vals
- widget.find('.long_answer,input').each(
- function () {
- $(this).attr('val', $(this).val());
- }
- );
-
- $(this).find("#id_survey_html").attr('value', widget.html());
-
- // don't save default value
- widget.find('input').each(
- function () {
- if ($(this).val() === DEFAULT_SHORT_ANSWER_TEXT) {
- $(this).val('');
- }
- }
- );
-
- // don't save default value
- widget.find('.long_answer, .tooltip_entry').each(
- function () {
- if ($(this).val() === DEFAULT_LONG_ANSWER_TEXT) {
- $(this).val('');
- }
- }
- );
-
- // get rid of the options
- $('input#id_s_html')
- .val(
- widget
- .find(
- 'div#survey_options'
- )
- .remove()
- .end()
- .html()
- );
- // only needed for HTML
-
- // Get option order per field
- survey.find('.sortable').each(
- function () {
- $('#order_for_' + this.id)
- .val(
- $(this).sortable(
- 'serialize'
- )
- );
- }
- );
- }
- );
- });
-}(jQuery));
-
-
-(function ($) {
- /*
- * == Utils ==
- *
- */
- jQuery.fn.extend({
-
- // get position of survey field
- getPosition: function () {
- var this_fieldset = $(this).parents('fieldset:first');
- var this_table = this_fieldset.parents('table:first');
- var position = this_table.find('fieldset').index(this_fieldset) + '__';
- return position;
- }
- });
-}(jQuery));
-
-
-(function ($) {
- /*
- * == Sortable options ==
- */
- $(function () {
- $(".sortable").each(
- function (i, domEle) {
- $(domEle).sortable().disableSelection().end();
- }
- );
- });
-}(jQuery));
-
-
-(function ($) {
- /*
- * == Editable options ==
- */
- $(function () {
- function onSubmitEditable(content) {
- var id_ = $(this).parent().attr('id').replace('-li-', '_');
- id_ = id_ + '__field';
- $('#' + id_).val(content.current);
- }
- $('.editable_option').editable({
- editBy: 'dblclick',
- submit: 'change',
- cancel: 'cancel',
- onSubmit: onSubmitEditable
- });
- });
-}(jQuery));
-
-
-(function ($) {
- $(function () {
- var del_li = [
- "<a class='delete_item' id='del_",
- "' ><img src='/soc/content/images/minus.gif'/></a> "
- ];
-
- // Confirmation dialog for deleting list/choice-field item from survey
- $("#delete_item_dialog").dialog({
- autoOpen: false,
- bgiframe: true,
- resizable: false,
- height: 300,
- modal: true,
- overlay: {
- backgroundColor: '#000',
- opacity: 0.5
- },
- buttons: {
- 'Delete this item': function () {
- $('#' + $('#delete_item_field').val()).remove();
- $('#delete_item_field').val('');
- $(this).dialog('close');
- },
- Cancel: function () {
- $('#delete_item_field').val('');
- $(this).dialog('close');
- }
- }
- });
-
-
- // Dialog for adding list/choice-field item to survey
- $("#new_item_dialog").dialog({
- bgiframe: true,
- autoOpen: false,
- height: 300,
- width: 300,
- modal: true,
- buttons: {
- 'Add option': function () {
- var ol_id = $('#new_item_field_ul_id').val();
- var ol = $('#' + ol_id);
- var name = $('#new_item_name').val();
- var i = ol.find('li').length;
- var id_ = 'id_' + ol_id + '_' + i;
- var option_html = $([
- '<li id="id-li-', ol_id, '_', i,
- '" class="ui-state-defaolt sortable_li">',
- '<span class="ui-icon ui-icon-arrowthick-2-n-s"></span>',
- '<span id="', id_, '" class="editable_option" name="', id_,
- '__field">', name, '</span>', '<input type="hidden" id="', id_,
- '__field" name="', id_, '__field" value="',
- name.replace(/\"/g, '"'), '" >', '</li>'
- ].join(""));
-
- ol.append(
- option_html
- .prepend(
- del_li.join(
- option_html.attr('id')
- )
- )
- );
- ol.sortable().disableSelection();
- $('#new_item_name').val('');
- $('#new_item_field_ol_id').val('');
- $(this).dialog('close');
- },
- Cancel: function () {
- $('#new_item_name').val('');
- $('#new_item_field_ul_id').val('');
- $(this).dialog('close');
- }
- }
- });
- });
-}(jQuery));
-
-
-(function ($) {
- $(function () {
- // Dialog for adding new question to survey
- var SURVEY_PREFIX = 'survey__';
- var del_el = ["<a class='delete'><img ",
- "src='/soc/content/images/minus.gif'/></a>"].join("");
- var del_li = ["<a class='delete_item' id='del_",
- "' ><img src='/soc/content/images/minus.gif'/></a> "];
-
-
- var widget = $('div#survey_widget');
- var survey = widget.find('tbody:first');
-
- $("#new_question_dialog").dialog({
- bgiframe: true,
- autoOpen: false,
- height: 400,
- width: 300,
- modal: true,
- buttons: {
- 'Add question': function () {
- var button_id = $("#new_question_button_id").val();
- var survey_table = $('div#survey_widget').find('tbody:first');
- $("#new_question_button_id").val('');
-
- var field_template = $(["<tr><th><label>", del_el,
- "</label></th><td> </td></tr>"].join(""));
-
- var field_name = $("#new_question_name").val();
- var question_content = $("#new_question_content").val();
- var question_options = $("#new_question_options").val();
-
- if (field_name !== '') {
- $("#new_question_name").val('');
- $("#new_question_content").val('');
- $("#new_question_options").val('');
-
- var new_field = false;
- var type = button_id + "__";
- var field_count = survey_table.find('fieldset').length;
- var new_field_count = field_count + 1 + '__';
-
- var MIN_ROWS = 10;
- var MAX_ROWS = MIN_ROWS * 2;
- var DEFAULT_OPTION_TEXT = 'Add A New Option...';
- var default_option = ["<option>", DEFAULT_OPTION_TEXT,
- "</option>"].join("");
-
- // create the HTML for the field
- switch (button_id) {
- case "short_answer":
- new_field = ["<fieldset>\n",
- '<label for="required_for_',
- field_name, '">Required</label>',
- '<select id="required_for_', field_name,
- '" name="required_for_', field_name,
- '"><option value="True" selected="selected">True',
- '</option>', '<option value="False">False</option>',
- '</select>', '<label for="comment_for_',
- field_name, '">Allow Comments</label>',
- '<select id="comment_for_', field_name,
- '" name="comment_for_', field_name, '">',
- '<option value="True" selected="selected">',
- 'True</option>', '<option value="False">',
- 'False</option>', '</select>',
- "<input type='text' ",
- "class='short_answer'>", "</fieldset>"
- ].join("");
- break;
- case "long_answer":
- field_count = survey_table.find('fieldset').length;
- new_field_count = field_count + 1 + '__';
- new_field = ['<fieldset>\n', '<label for="required_for_',
- field_name, '">Required</label>',
- '<select id="required_for_', field_name,
- '" name="required_for_', field_name,
- '"><option value="True" selected="selected">True',
- '</option>', '<option value="False">False</option>',
- '</select>', '<label for="comment_for_',
- field_name, '">Allow Comments</label>',
- '<select id="comment_for_', field_name,
- '" name="comment_for_', field_name, '">',
- '<option value="True" selected="selected">',
- 'True</option>', '<option value="False">',
- 'False</option>', '</select>',
- "<textarea wrap='hard' cols='40' rows='", MIN_ROWS,
- "' class='long_answer'/>", '</fieldset>'
- ].join("");
- break;
- case "selection":
- new_field = ["<select><option></option>", default_option,
- "</select>"].join("");
- break;
- case "pick_multi":
- new_field = ["<fieldset class='fieldset'><input type='button'",
- "value='", DEFAULT_OPTION_TEXT, "' /></fieldset>"]
- .join("");
- break;
- case "choice":
- new_field = ["<fieldset class='fieldset'><input type='button'",
- "value='", DEFAULT_OPTION_TEXT, "' /></fieldset>"]
- .join("");
- break;
- }
-
- if (new_field) {
- var question_for = [
- '\n <input type="hidden" name="NEW_', field_name,
- '" id="NEW_', field_name, '" value="', question_content,
- '"/>'
- ].join("");
-
- field_count = survey_table.find('fieldset').length;
- new_field_count = field_count + 1 + '__';
- var formatted_name = (SURVEY_PREFIX + new_field_count + type +
- field_name);
- if (button_id === 'choice') {
- var name = (field_name);
- new_field = $([
- '<fieldset>\n', '<label for="required_for_', name,
- '">Required</label>',
- '<select id="required_for_', name, '" name="required_for_',
- name, '"><option value="True" selected="selected">True',
- '</option>', '<option value="False">False</option>',
- '</select>', '<label for="comment_for_', name,
- '">Allow Comments</label>', '<select id="comment_for_', name,
- '" name="comment_for_', name, '">',
- '<option value="True" selected="selected">True</option>',
- '<option value="False">False</option>',
- '</select>',
- '<label for="render_for_', name,
- '">Render as</label>', '\n <select id="render_for_', name,
- '" name="render_for_', name, '">', '\n <option',
- 'selected="selected" value="select">select</option>',
- '\n <option value="checkboxes">checkboxes</option>',
- '\n <option value="radio_buttons">radio_buttons</option>',
- '\n </select>', '\n <input type="hidden" id="order_for_',
- name, '\n " name="order_for_', name, '" value=""/>',
- '\n <input type="hidden" id="index_for_', name,
- '\n " name="index_for_', name, '" value="',
- (field_count + 1), '"/>\n <ol id="', name,
- '" class="sortable"></ol>',
- question_for, '\n <button name="create-option-button"',
- 'id="create-option-button__', name,
- '" class="ui-button ui-state-default ui-corner-all" value="',
- name, '" onClick="return false;">Create new option',
- '</button>\n</fieldset>'
- ].join(""));
-
- $(new_field).attr({
- 'id': 'id_' + formatted_name,
- 'name': formatted_name
- });
- field_template
- .find(
- 'label'
- )
- .attr(
- 'for',
- 'NEW_' + name
- )
- .append(question_content).end()
- .find(
- 'td'
- )
- .append(new_field);
- survey_table.append(field_template).end();
-
- if (question_options) {
-
- var options_array = question_options.split('\n');
- var ol = $('#' + name);
- var length = options_array.length;
- var oname = '';
- var id_ = '';
- var option_html = '';
-
- for (var i = 0; i < length; i = i + 1) {
- id_ = 'id_' + name + '_' + i;
- oname = options_array[i];
- option_html = $([
- '<li id="id-li-', name, '_', i,
- '" class="ui-state-defaolt sortable_li">',
- '<span class="ui-icon ui-icon-arrowthick-2-n-s"></span>',
- '<span id="' + id_ + '" class="editable_option" name="',
- id_, '__field">', oname, '</span>', '<input ',
- 'type="hidden" id="', id_, '__field" name="', id_,
- '__field" value="', oname.replace(/\"/g, '"'), '" >', '</li>'
- ].join(""));
- ol.append(option_html.prepend(
- del_li.join(option_html.attr('id'))));
- ol.sortable().disableSelection();
- }
-
- survey.trigger('option_init');
- }
- }
-
- else {
- new_field = $(new_field);
- // maybe the name should be serialized in a more common format
- $(new_field).find('.long_answer, .short_answer').attr({
- 'id': 'id_' + formatted_name,
- 'name': formatted_name
- });
- field_template.find(
- 'label'
- )
- .attr(
- 'for',
- 'id_' + formatted_name
- )
- .append(question_content).end()
- .find(
- 'td'
- )
- .append(new_field).append($(question_for));
-
- survey_table.append(field_template);
- }
-
- survey.trigger('init');
-
- }
- }
- $("#new_question_name").val('');
- $("#new_question_content").val('');
- $("#new_question_options").val('');
- $(this).dialog('close');
- },
-
- Cancel: function () {
- $('#new_question_name').val('');
- $("#new_question_button_id").val('');
- $("#new_question_content").val('');
- $("#new_question_options").val('');
- $(this).dialog('close');
- }
- }
- });
- });
-}(jQuery));
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/content/js/survey-edit-090825.js Tue Aug 25 16:15:07 2009 +0100
@@ -0,0 +1,776 @@
+ /* Copyright 2009 the Melange authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+*
+* @author <a href="mailto:ajaksu@gmail.com">Daniel Diniz</a>
+* @author <a href="mailto:jamesalexanderlevy@gmail.com">James Levy</a>
+*/
+
+(function ($) {
+
+ var DEFAULT_LONG_ANSWER_TEXT = 'Write a Custom Prompt For This Question...';
+ var DEFAULT_SHORT_ANSWER_TEXT = 'Write a Custom Prompt...';
+
+ $(function () {
+ /*
+ * == Set Selectors ==
+ *
+ */
+ var widget = $('div#survey_widget');
+
+ widget.parents('td.formfieldvalue:first').css({
+ 'float': 'left',
+ 'width': 200
+ });
+
+ /*
+ * == Setup for existing surveys ==
+ *
+ */
+
+ if ($('input#id_title').val() === '' && $('.formfielderror').length < 1) {
+ widget.find('tr').remove();
+ }
+
+ widget.find('table:first').show();
+
+ /*
+ * Restore survey content html from editPost
+ * if POST fails
+ */
+
+ var SURVEY_PREFIX = 'survey__';
+ var del_el = ["<a class='delete'><img ",
+ "src='/soc/content/images/minus.gif'/></a>"].join("");
+ var del_li = ["<a class='delete_item' id='del_",
+ "' ><img src='/soc/content/images/minus.gif'/></a> "];
+
+ var survey_html = $('form').find("#id_survey_html").attr('value');
+
+ function renderHTML() {
+ // render existing survey forms
+ widget.find('td.twolineformfieldlabel > label').prepend(del_el).end();
+
+ $('ol').find('li').each(
+ function () {
+ $(this).prepend(del_li.join($(this).attr('id'))).end();
+ }
+ );
+ widget.find('.short_answer').each(
+ function () {
+ $(this).attr('name', SURVEY_PREFIX + $(this).getPosition() +
+ 'short_answer__' + $(this).attr('name'));
+ }
+ );
+
+ // add index information to choice fields
+ widget.find('[name=create-option-button]').each(
+ function () {
+ $(
+ '#index_for_' + $(this).attr('value')
+ )
+ .val(
+ $(this).getPosition()
+ );
+ }
+ );
+
+ widget.find('.long_answer').each(
+ function () {
+ $(this).attr('name', SURVEY_PREFIX + $(this).getPosition() +
+ 'long_answer__' + $(this).attr('name'))
+ .attr('overflow', 'auto');
+ // TODO: replace scrollbar with jquery autogrow
+ }
+ );
+ }
+
+ if (survey_html && survey_html.length > 1) {
+ widget.html(survey_html); // we don't need to re-render HTML
+
+ widget.find('.long_answer,input').each(
+ function () {
+ $(this).val($(this).attr('val'));
+ }
+ );
+ }
+ else {
+ renderHTML();
+ }
+
+ var survey = widget.find('tbody:first');
+ var options = widget.find('#survey_options');
+
+ /*
+ * == Handle Enter key on dialogs ==
+ */
+ $('form input, form button, form select').keypress(
+ function (e) {
+ if ((e.which && e.which === 13) || (e.keyCode && e.keyCode === 13)) {
+ $(this).parents('.ui-dialog:first').find(":button:first").click();
+ return false;
+ }
+ }
+ );
+
+ /*
+ * == Display survey answers inline ==
+ */
+ $('a.fetch_answers').click(
+ function () {
+ var user = this.id.replace('results_for_', '');
+ var path = window.location.pathname;
+ path = path.replace('/edit/', '/show/').replace('/results/', '/show/');
+
+ // TODO(ajaksu) add Date().getTime() to query arg if needed
+ var query = '?read_only=true&user_results=' + user;
+ var scrollable = ['<div style="overflow-y: auto; ',
+ 'margin-bottom: 100px;"></div>'].join("");
+ $(scrollable).load(path + query + ' #survey_widget').dialog({
+ title: user,
+ height: 500,
+ width: 700
+ });
+ }
+ );
+
+ /*
+ * == Initiation ==
+ *
+ * Runs on PageLoad and Each Time Field is Added to Survey
+ *
+ */
+
+ survey.bind('init',
+ function () {
+ // TODO(jamslevy) unnecessarily redundant
+ // TODO(jamslevy) This should be refactored as a jQuery function that
+ // acts on only a single field and it should be merged with renderHTML
+ // since they have comparable functionality.
+
+ widget.find('input').each(
+ function () {
+ if (($(this).val().length < 1 ||
+ $(this).val() === DEFAULT_SHORT_ANSWER_TEXT) &&
+ ($(this).attr('type') !== 'hidden')) {
+ $(this).preserveDefaultText(DEFAULT_SHORT_ANSWER_TEXT);
+ }
+ }
+ );
+
+ widget.find('.long_answer, .tooltip_entry').each(
+ function () {
+ if ($(this).val().length < 1 ||
+ $(this).val() === DEFAULT_LONG_ANSWER_TEXT) {
+ $(this).preserveDefaultText(DEFAULT_LONG_ANSWER_TEXT);
+ }
+ $(this).growfield();
+ }
+ );
+
+ widget.find('a.delete img').click(
+ function () {
+ // delete a field
+ var this_field = $(this).parents('tr:first');
+ var deleted_id = $(this_field).find('label').attr('for');
+ var delete_this = confirm(["Deleting this field will remove all ",
+ "answers submitted for this field. ",
+ "Continue?"].join(""));
+ if (delete_this) {
+ var edit_form = $('#EditForm');
+ var deleted_field = $('#__deleted__');
+ if (deleted_field.val()) {
+ deleted_field.val(deleted_field.val() + ',' +
+ deleted_id.replace('id_', '')).end();
+ }
+ else {
+ var deleted_input = $("<input type='hidden' value='" +
+ deleted_id.replace('id_', '') + "' />");
+ deleted_input.attr({'id': '__deleted__'}).attr({
+ 'name': '__deleted__'
+ });
+ edit_form.append(deleted_input);
+ }
+ this_field.next('tr').remove().end()
+ .remove();
+ }
+ }
+ );
+
+ // Add list/choice-field item to survey
+ $('[name=create-option-button]').each(
+ function () {
+ $(this).click(
+ function () {
+ var new_option_val = $('#new_item_field_ul_id');
+ var new_option_dialog = $("#new_item_dialog");
+
+ new_option_val.val($(this).parents('fieldset').children('ol')
+ .attr('id'));
+
+ new_option_dialog.dialog('open').find('input:first').focus();
+ }
+ )
+ .hover(
+ function () {
+ $(this).addClass("ui-state-hover");
+ },
+ function () {
+ $(this).removeClass("ui-state-hover");
+ }
+ )
+ .mousedown(
+ function () {
+ $(this).addClass("ui-state-active");
+ }
+ )
+ .mouseup(
+ function () {
+ $(this).removeClass("ui-state-active");
+ }
+ );
+ }
+ );
+
+ options.find('.AddQuestion').click(
+ function (e) {
+ // Choose a field type
+ $("#new_question_button_id").val($(this).attr('id'));
+ var question_options_div = $('#question_options_div');
+ if ($(this).attr('id') === 'choice') {
+ question_options_div.show();
+ }
+ else {
+ question_options_div.hide();
+ }
+
+ $("#new_question_dialog").dialog('open').find('input:first')
+ .focus();
+ }
+ );
+ }).trigger('init')
+ .bind('option_init',
+ function () {
+
+ // Delete list/choice-field item from survey
+ widget.find('a.delete_item').click(
+ function () {
+ var to_delete = this.id.replace('del_', '');
+ $('#delete_item_field').val(to_delete);
+ $('#delete_item_dialog').dialog('open');
+ }
+ ).end();
+
+ }
+ ).trigger('option_init');
+
+
+ /* GSOC ROLE-SPECIFIC FIELD PLUGIN
+ * Choice between student/mentor renders required GSOC specific fields
+ */
+
+ var taking_access_field = $('select#id_taking_access');
+
+ var addRoleFields = function (role_type) {
+ // these should ideally be generated with django forms
+ // TODO: apply info tooltips
+ var CHOOSE_A_PROJECT_FIELD = [
+ '<tr class="role-specific"><th><label>Choose Project:</label></th>',
+ '<td> <select disabled=TRUE id="id_survey__NA__selection__project"',
+ ' name="survey__1__selection__see"><option>Survey Taker\'s Projects',
+ 'For This Program</option></select> </td></tr>'
+ ].join("");
+
+ var CHOOSE_A_GRADE_FIELD = [
+ '<tr class="role-specific"><th><label>Assign Grade:</label></th><td>',
+ '<select disabled=TRUE id="id_survey__NA__selection__grade"',
+ 'name="survey__1__selection__see"><option>Pass/Fail</option></select>',
+ '</td></tr>'
+ ].join("");
+
+ // flush existing role-specific fields
+ var role_specific_fields = survey.find('tr.role-specific');
+ role_specific_fields.remove();
+
+ switch (role_type) {
+ case "mentor evaluation":
+ survey.prepend(CHOOSE_A_PROJECT_FIELD);
+ survey.append(CHOOSE_A_GRADE_FIELD);
+ break;
+
+ case "student evaluation":
+ survey.prepend(CHOOSE_A_PROJECT_FIELD);
+ break;
+ }
+ };
+
+ taking_access_field.change(
+ function () {
+ var role_type = $(this).val();
+ addRoleFields(role_type);
+ }
+ );
+
+ addRoleFields(taking_access_field.val());
+
+ /*
+ * == Survey Submission Handler ==
+ */
+ // Bind submit
+ $('form').bind('submit',
+ function () {
+
+ /*
+ * get rid of role-specific fields
+ */
+ survey.find('tr.role-specific').remove();
+
+ /*
+ * Save survey content html from editPost
+ * if POST fails
+ */
+
+ // save field vals
+ widget.find('.long_answer,input').each(
+ function () {
+ $(this).attr('val', $(this).val());
+ }
+ );
+
+ $(this).find("#id_survey_html").attr('value', widget.html());
+
+ // don't save default value
+ widget.find('input').each(
+ function () {
+ if ($(this).val() === DEFAULT_SHORT_ANSWER_TEXT) {
+ $(this).val('');
+ }
+ }
+ );
+
+ // don't save default value
+ widget.find('.long_answer, .tooltip_entry').each(
+ function () {
+ if ($(this).val() === DEFAULT_LONG_ANSWER_TEXT) {
+ $(this).val('');
+ }
+ }
+ );
+
+ // get rid of the options
+ $('input#id_s_html')
+ .val(
+ widget
+ .find(
+ 'div#survey_options'
+ )
+ .remove()
+ .end()
+ .html()
+ );
+ // only needed for HTML
+
+ // Get option order per field
+ survey.find('.sortable').each(
+ function () {
+ $('#order_for_' + this.id)
+ .val(
+ $(this).sortable(
+ 'serialize'
+ )
+ );
+ }
+ );
+ }
+ );
+ });
+}(jQuery));
+
+
+(function ($) {
+ /*
+ * == Utils ==
+ *
+ */
+ jQuery.fn.extend({
+
+ // get position of survey field
+ getPosition: function () {
+ var this_fieldset = $(this).parents('fieldset:first');
+ var this_table = this_fieldset.parents('table:first');
+ var position = this_table.find('fieldset').index(this_fieldset) + '__';
+ return position;
+ }
+ });
+}(jQuery));
+
+
+(function ($) {
+ /*
+ * == Sortable options ==
+ */
+ $(function () {
+ $(".sortable").each(
+ function (i, domEle) {
+ $(domEle).sortable().disableSelection().end();
+ }
+ );
+ });
+}(jQuery));
+
+
+(function ($) {
+ /*
+ * == Editable options ==
+ */
+ $(function () {
+ function onSubmitEditable(content) {
+ var id_ = $(this).parent().attr('id').replace('-li-', '_');
+ id_ = id_ + '__field';
+ $('#' + id_).val(content.current);
+ }
+ $('.editable_option').editable({
+ editBy: 'dblclick',
+ submit: 'change',
+ cancel: 'cancel',
+ onSubmit: onSubmitEditable
+ });
+ });
+}(jQuery));
+
+
+(function ($) {
+ $(function () {
+ var del_li = [
+ "<a class='delete_item' id='del_",
+ "' ><img src='/soc/content/images/minus.gif'/></a> "
+ ];
+
+ // Confirmation dialog for deleting list/choice-field item from survey
+ $("#delete_item_dialog").dialog({
+ autoOpen: false,
+ bgiframe: true,
+ resizable: false,
+ height: 300,
+ modal: true,
+ overlay: {
+ backgroundColor: '#000',
+ opacity: 0.5
+ },
+ buttons: {
+ 'Delete this item': function () {
+ $('#' + $('#delete_item_field').val()).remove();
+ $('#delete_item_field').val('');
+ $(this).dialog('close');
+ },
+ Cancel: function () {
+ $('#delete_item_field').val('');
+ $(this).dialog('close');
+ }
+ }
+ });
+
+
+ // Dialog for adding list/choice-field item to survey
+ $("#new_item_dialog").dialog({
+ bgiframe: true,
+ autoOpen: false,
+ height: 300,
+ width: 300,
+ modal: true,
+ buttons: {
+ 'Add option': function () {
+ var ol_id = $('#new_item_field_ul_id').val();
+ var ol = $('#' + ol_id);
+ var name = $('#new_item_name').val();
+ var i = ol.find('li').length;
+ var id_ = 'id_' + ol_id + '_' + i;
+ var option_html = $([
+ '<li id="id-li-', ol_id, '_', i,
+ '" class="ui-state-defaolt sortable_li">',
+ '<span class="ui-icon ui-icon-arrowthick-2-n-s"></span>',
+ '<span id="', id_, '" class="editable_option" name="', id_,
+ '__field">', name, '</span>', '<input type="hidden" id="', id_,
+ '__field" name="', id_, '__field" value="',
+ name.replace(/\"/g, '"'), '" >', '</li>'
+ ].join(""));
+
+ ol.append(
+ option_html
+ .prepend(
+ del_li.join(
+ option_html.attr('id')
+ )
+ )
+ );
+ ol.sortable().disableSelection();
+ $('#new_item_name').val('');
+ $('#new_item_field_ol_id').val('');
+ $(this).dialog('close');
+ },
+ Cancel: function () {
+ $('#new_item_name').val('');
+ $('#new_item_field_ul_id').val('');
+ $(this).dialog('close');
+ }
+ }
+ });
+ });
+}(jQuery));
+
+
+(function ($) {
+ $(function () {
+ // Dialog for adding new question to survey
+ var SURVEY_PREFIX = 'survey__';
+ var del_el = ["<a class='delete'><img ",
+ "src='/soc/content/images/minus.gif'/></a>"].join("");
+ var del_li = ["<a class='delete_item' id='del_",
+ "' ><img src='/soc/content/images/minus.gif'/></a> "];
+
+
+ var widget = $('div#survey_widget');
+ var survey = widget.find('tbody:first');
+
+ $("#new_question_dialog").dialog({
+ bgiframe: true,
+ autoOpen: false,
+ height: 400,
+ width: 300,
+ modal: true,
+ buttons: {
+ 'Add question': function () {
+ var button_id = $("#new_question_button_id").val();
+ var survey_table = $('div#survey_widget').find('tbody:first');
+ $("#new_question_button_id").val('');
+
+ var field_template = $(["<tr><th><label>", del_el,
+ "</label></th><td> </td></tr>"].join(""));
+
+ var field_name = $("#new_question_name").val();
+ var question_content = $("#new_question_content").val();
+ var question_options = $("#new_question_options").val();
+
+ if (field_name !== '') {
+ $("#new_question_name").val('');
+ $("#new_question_content").val('');
+ $("#new_question_options").val('');
+
+ var new_field = false;
+ var type = button_id + "__";
+ var field_count = survey_table.find('fieldset').length;
+ var new_field_count = field_count + 1 + '__';
+
+ var MIN_ROWS = 10;
+ var MAX_ROWS = MIN_ROWS * 2;
+ var DEFAULT_OPTION_TEXT = 'Add A New Option...';
+ var default_option = ["<option>", DEFAULT_OPTION_TEXT,
+ "</option>"].join("");
+
+ // create the HTML for the field
+ switch (button_id) {
+ case "short_answer":
+ new_field = ["<fieldset>\n",
+ '<label for="required_for_',
+ field_name, '">Required</label>',
+ '<select id="required_for_', field_name,
+ '" name="required_for_', field_name,
+ '"><option value="True" selected="selected">True',
+ '</option>', '<option value="False">False</option>',
+ '</select>', '<label for="comment_for_',
+ field_name, '">Allow Comments</label>',
+ '<select id="comment_for_', field_name,
+ '" name="comment_for_', field_name, '">',
+ '<option value="True" selected="selected">',
+ 'True</option>', '<option value="False">',
+ 'False</option>', '</select>',
+ "<input type='text' ",
+ "class='short_answer'>", "</fieldset>"
+ ].join("");
+ break;
+ case "long_answer":
+ field_count = survey_table.find('fieldset').length;
+ new_field_count = field_count + 1 + '__';
+ new_field = ['<fieldset>\n', '<label for="required_for_',
+ field_name, '">Required</label>',
+ '<select id="required_for_', field_name,
+ '" name="required_for_', field_name,
+ '"><option value="True" selected="selected">True',
+ '</option>', '<option value="False">False</option>',
+ '</select>', '<label for="comment_for_',
+ field_name, '">Allow Comments</label>',
+ '<select id="comment_for_', field_name,
+ '" name="comment_for_', field_name, '">',
+ '<option value="True" selected="selected">',
+ 'True</option>', '<option value="False">',
+ 'False</option>', '</select>',
+ "<textarea wrap='hard' cols='40' rows='", MIN_ROWS,
+ "' class='long_answer'/>", '</fieldset>'
+ ].join("");
+ break;
+ case "selection":
+ new_field = ["<select><option></option>", default_option,
+ "</select>"].join("");
+ break;
+ case "pick_multi":
+ new_field = ["<fieldset class='fieldset'><input type='button'",
+ "value='", DEFAULT_OPTION_TEXT, "' /></fieldset>"]
+ .join("");
+ break;
+ case "choice":
+ new_field = ["<fieldset class='fieldset'><input type='button'",
+ "value='", DEFAULT_OPTION_TEXT, "' /></fieldset>"]
+ .join("");
+ break;
+ }
+
+ if (new_field) {
+ var question_for = [
+ '\n <input type="hidden" name="NEW_', field_name,
+ '" id="NEW_', field_name, '" value="', question_content,
+ '"/>'
+ ].join("");
+
+ field_count = survey_table.find('fieldset').length;
+ new_field_count = field_count + 1 + '__';
+ var formatted_name = (SURVEY_PREFIX + new_field_count + type +
+ field_name);
+ if (button_id === 'choice') {
+ var name = (field_name);
+ new_field = $([
+ '<fieldset>\n', '<label for="required_for_', name,
+ '">Required</label>',
+ '<select id="required_for_', name, '" name="required_for_',
+ name, '"><option value="True" selected="selected">True',
+ '</option>', '<option value="False">False</option>',
+ '</select>', '<label for="comment_for_', name,
+ '">Allow Comments</label>', '<select id="comment_for_', name,
+ '" name="comment_for_', name, '">',
+ '<option value="True" selected="selected">True</option>',
+ '<option value="False">False</option>',
+ '</select>',
+ '<label for="render_for_', name,
+ '">Render as</label>', '\n <select id="render_for_', name,
+ '" name="render_for_', name, '">', '\n <option',
+ 'selected="selected" value="select">select</option>',
+ '\n <option value="checkboxes">checkboxes</option>',
+ '\n <option value="radio_buttons">radio_buttons</option>',
+ '\n </select>', '\n <input type="hidden" id="order_for_',
+ name, '\n " name="order_for_', name, '" value=""/>',
+ '\n <input type="hidden" id="index_for_', name,
+ '\n " name="index_for_', name, '" value="',
+ (field_count + 1), '"/>\n <ol id="', name,
+ '" class="sortable"></ol>',
+ question_for, '\n <button name="create-option-button"',
+ 'id="create-option-button__', name,
+ '" class="ui-button ui-state-default ui-corner-all" value="',
+ name, '" onClick="return false;">Create new option',
+ '</button>\n</fieldset>'
+ ].join(""));
+
+ $(new_field).attr({
+ 'id': 'id_' + formatted_name,
+ 'name': formatted_name
+ });
+ field_template
+ .find(
+ 'label'
+ )
+ .attr(
+ 'for',
+ 'NEW_' + name
+ )
+ .append(question_content).end()
+ .find(
+ 'td'
+ )
+ .append(new_field);
+ survey_table.append(field_template).end();
+
+ if (question_options) {
+
+ var options_array = question_options.split('\n');
+ var ol = $('#' + name);
+ var length = options_array.length;
+ var oname = '';
+ var id_ = '';
+ var option_html = '';
+
+ for (var i = 0; i < length; i = i + 1) {
+ id_ = 'id_' + name + '_' + i;
+ oname = options_array[i];
+ option_html = $([
+ '<li id="id-li-', name, '_', i,
+ '" class="ui-state-defaolt sortable_li">',
+ '<span class="ui-icon ui-icon-arrowthick-2-n-s"></span>',
+ '<span id="' + id_ + '" class="editable_option" name="',
+ id_, '__field">', oname, '</span>', '<input ',
+ 'type="hidden" id="', id_, '__field" name="', id_,
+ '__field" value="', oname.replace(/\"/g, '"'), '" >', '</li>'
+ ].join(""));
+ ol.append(option_html.prepend(
+ del_li.join(option_html.attr('id'))));
+ ol.sortable().disableSelection();
+ }
+
+ survey.trigger('option_init');
+ }
+ }
+
+ else {
+ new_field = $(new_field);
+ // maybe the name should be serialized in a more common format
+ $(new_field).find('.long_answer, .short_answer').attr({
+ 'id': 'id_' + formatted_name,
+ 'name': formatted_name
+ });
+ field_template.find(
+ 'label'
+ )
+ .attr(
+ 'for',
+ 'id_' + formatted_name
+ )
+ .append(question_content).end()
+ .find(
+ 'td'
+ )
+ .append(new_field).append($(question_for));
+
+ survey_table.append(field_template);
+ }
+
+ survey.trigger('init');
+
+ }
+ }
+ $("#new_question_name").val('');
+ $("#new_question_content").val('');
+ $("#new_question_options").val('');
+ $(this).dialog('close');
+ },
+
+ Cancel: function () {
+ $('#new_question_name').val('');
+ $("#new_question_button_id").val('');
+ $("#new_question_content").val('');
+ $("#new_question_options").val('');
+ $(this).dialog('close');
+ }
+ }
+ });
+ });
+}(jQuery));
--- a/app/soc/content/js/survey-take-090708.js Tue Aug 25 15:58:30 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,155 +0,0 @@
-/* Copyright 2009 the Melange authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
-*
-* @author <a href="mailto:ajaksu@gmail.com">Daniel Diniz</a>
-* @author <a href="mailto:jamesalexanderlevy@gmail.com">James Levy</a>
-*/
-
-(function ($) {
- $(function () {
-
- /*
- * == Setup Survey on Page Load ==
- *
- */
-
- var widget = $('div#survey_widget');
-
- // TODO(ajaksu) survey below is unused, remove if no known use is predicted
- var survey = widget.find('tbody:first');
-
- if (widget.hasClass('create')) {
-
- /*
- * == Set Custom Field Rules ==
- *
- */
- widget.find('textarea').each(
- function () {
- $(this).attr('overflow', 'auto').growfield();
- }
- );
- }
-
- else { // survey has saved results
- widget.find('textarea').each(
- function () {
- $(this).attr('overflow', 'auto').growfield();
- }
- ).end()
- .find('.pick_multi').each(
- function () {
- $(this).find('input').each(
- /*jslint white: false */
- function () {
- // if $(this).attr('checked', 'true');});
- }
- /*jslint white: true */
- );
- }
- );
- }
-
- /*
- * == Configure Project ==
- *
- */
-
- // remember if form has been touched
- $('input,textarea,select').change(
- function () {
- if ($(this).attr('id') === 'id_project') {
- return;
- }
- $('form:first').data('touched', true);
- }
- );
-
- // remember initially chosen project choice
- $('select#id_project').blur(
- function () {
- $(this).data('selected', $(this).find('option:first'));
- }
- ).change(
- function () {
- if ($('form:first').data('touched') === true) {
- // if form has been touched, send confirmation dialog
- var save_check = confirm(["Switching projects will lose unsaved ",
- "edits made to this survey."].join(""));
- if (!save_check) {
- $(this).data('selected').attr('selected', 'selected');
- return false;
- }
- }
-
- if ($(this).val() !== 'None') {
- // redirect with new project GET param
- window.location = [window.location.href.split('?')[0], "?project=",
- $(this).val()].join("");
- }
- }
- );
-
- // insert project link after project select field
- $('div#project_link').insertAfter($('select#id_project')).show();
-
- /*
- * == Survey Submission Handler ==
- *
- */
-
- // validate form
- $('input[type=submit]').bind(
- 'click',
- function (e) {
- e.preventDefault();
-
- // validate project and grade choice fields
- if ($('select#id_project') &&
- $('select#id_project').val() === 'None') {
- return alert('Please Choose a Project');
- }
-
- if ($('select#id_grade') && $('select#id_grade').val() === 'None') {
- return alert('Please Choose a Grade');
- }
- $('form').trigger('submit');
-
- }
- );
-
- $('form').bind('submit',
- function () {
- $('input#id_s_html').val(
- widget.find('div#survey_options').remove().end().html()
- );
- }
- );
-
- /*
- * == Customize Comment Appearance ==
- */
-
- var comments = widget.find('td > .comment');
- comments.each(function () {
- $(this).parents('tr:first')
- .prev().css({'margin-top': '-10px'})
- .find('label').css({'font-size': '11px'});
- });
-
- });
-}(jQuery));
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/content/js/survey-take-090825.js Tue Aug 25 16:15:07 2009 +0100
@@ -0,0 +1,155 @@
+/* Copyright 2009 the Melange authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+*
+* @author <a href="mailto:ajaksu@gmail.com">Daniel Diniz</a>
+* @author <a href="mailto:jamesalexanderlevy@gmail.com">James Levy</a>
+*/
+
+(function ($) {
+ $(function () {
+
+ /*
+ * == Setup Survey on Page Load ==
+ *
+ */
+
+ var widget = $('div#survey_widget');
+
+ // TODO(ajaksu) survey below is unused, remove if no known use is predicted
+ var survey = widget.find('tbody:first');
+
+ if (widget.hasClass('create')) {
+
+ /*
+ * == Set Custom Field Rules ==
+ *
+ */
+ widget.find('textarea').each(
+ function () {
+ $(this).attr('overflow', 'auto').growfield();
+ }
+ );
+ }
+
+ else { // survey has saved results
+ widget.find('textarea').each(
+ function () {
+ $(this).attr('overflow', 'auto').growfield();
+ }
+ ).end()
+ .find('.pick_multi').each(
+ function () {
+ $(this).find('input').each(
+ /*jslint white: false */
+ function () {
+ // if $(this).attr('checked', 'true');});
+ }
+ /*jslint white: true */
+ );
+ }
+ );
+ }
+
+ /*
+ * == Configure Project ==
+ *
+ */
+
+ // remember if form has been touched
+ $('input,textarea,select').change(
+ function () {
+ if ($(this).attr('id') === 'id_project') {
+ return;
+ }
+ $('form:first').data('touched', true);
+ }
+ );
+
+ // remember initially chosen project choice
+ $('select#id_project').blur(
+ function () {
+ $(this).data('selected', $(this).find('option:first'));
+ }
+ ).change(
+ function () {
+ if ($('form:first').data('touched') === true) {
+ // if form has been touched, send confirmation dialog
+ var save_check = confirm(["Switching projects will lose unsaved ",
+ "edits made to this survey."].join(""));
+ if (!save_check) {
+ $(this).data('selected').attr('selected', 'selected');
+ return false;
+ }
+ }
+
+ if ($(this).val() !== 'None') {
+ // redirect with new project GET param
+ window.location = [window.location.href.split('?')[0], "?project=",
+ $(this).val()].join("");
+ }
+ }
+ );
+
+ // insert project link after project select field
+ $('div#project_link').insertAfter($('select#id_project')).show();
+
+ /*
+ * == Survey Submission Handler ==
+ *
+ */
+
+ // validate form
+ $('input[type=submit]').bind(
+ 'click',
+ function (e) {
+ e.preventDefault();
+
+ // validate project and grade choice fields
+ if ($('select#id_project') &&
+ $('select#id_project').val() === 'None') {
+ return alert('Please Choose a Project');
+ }
+
+ if ($('select#id_grade') && $('select#id_grade').val() === 'None') {
+ return alert('Please Choose a Grade');
+ }
+ $('form').trigger('submit');
+
+ }
+ );
+
+ $('form').bind('submit',
+ function () {
+ $('input#id_s_html').val(
+ widget.find('div#survey_options').remove().end().html()
+ );
+ }
+ );
+
+ /*
+ * == Customize Comment Appearance ==
+ */
+
+ var comments = widget.find('td > .comment');
+ comments.each(function () {
+ $(this).parents('tr:first')
+ .prev().css({'margin-top': '-10px'})
+ .find('label').css({'font-size': '11px'});
+ });
+
+ });
+}(jQuery));
--- a/app/soc/templates/soc/base.html Tue Aug 25 15:58:30 2009 +0100
+++ b/app/soc/templates/soc/base.html Tue Aug 25 16:15:07 2009 +0100
@@ -56,7 +56,7 @@
<script type='text/javascript' src="/json/json2.js"></script>
{% endif %}
{% if uses_menu %}
- <script type='text/javascript' src="/soc/content/js/menu-081108.js"></script>
+ <script type='text/javascript' src="/soc/content/js/menu-090825.js"></script>
{% endif %}
{% if uses_jq_purr %}
<script type='text/javascript' src="/jquery/jquery-purr.js"></script>
@@ -83,21 +83,21 @@
<script type="text/javascript" src="/jquery/jquery-progressbar.js"></script>
{% endif %}
{% if uses_bulk_review %}
- <script type="text/javascript" src="/soc/content/js/bulk-review-090304.js"></script>
+ <script type="text/javascript" src="/soc/content/js/bulk-review-090825.js"></script>
{% endif %}
{% if uses_jq_ui_core %}
<script type="text/javascript" src="/jquery/jquery-ui.core.js"></script>
{% endif %}
{% if uses_jq_datetimepicker %}
<script type="text/javascript" src="/jquery/jquery-ui.datetimepicker.js"></script>
- <script type="text/javascript" src="/soc/content/js/datetime-loader-090304.js"></script>
- <script type="text/javascript" src="/soc/content/js/datetimepicker-090304.js"></script>
+ <script type="text/javascript" src="/soc/content/js/datetime-loader-090825.js"></script>
+ <script type="text/javascript" src="/soc/content/js/datetimepicker-090825.js"></script>
{% endif %}
{% if uses_slot_allocator %}
- <script type="text/javascript" src="/soc/content/js/slot-allocator-090320.js"></script>
+ <script type="text/javascript" src="/soc/content/js/slot-allocator-090825.js"></script>
{% endif %}
{% if uses_duplicates %}
- <script type="text/javascript" src="/soc/content/js/duplicate-slots-090505.js"></script>
+ <script type="text/javascript" src="/soc/content/js/duplicate-slots-090825.js"></script>
{% endif %}
{% endblock %}
</head>
--- a/app/soc/templates/soc/organization/home.html Tue Aug 25 15:58:30 2009 +0100
+++ b/app/soc/templates/soc/organization/home.html Tue Aug 25 16:15:07 2009 +0100
@@ -17,7 +17,7 @@
{{ block.super }}
{% if gmaps_api_key %}
<script src="http://maps.google.com/maps?file=api&v=2&key={{ gmaps_api_key }}" type="text/javascript"></script>
- <script type="text/javascript" src="/soc/content/js/map-090730.js"></script>
+ <script type="text/javascript" src="/soc/content/js/map-090825.js"></script>
{% endif %}
{% endblock %}
--- a/app/soc/templates/soc/presence/home.html Tue Aug 25 15:58:30 2009 +0100
+++ b/app/soc/templates/soc/presence/home.html Tue Aug 25 16:15:07 2009 +0100
@@ -17,7 +17,7 @@
{{ block.super }}
{% if entity.feed_url %}
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
- <script type="text/javascript" src="/soc/content/js/blog-081117.js"></script>
+ <script type="text/javascript" src="/soc/content/js/blog-090825.js"></script>
<script type="text/javascript" >
google.load("feeds", "1");
--- a/app/soc/templates/soc/role/edit.html Tue Aug 25 15:58:30 2009 +0100
+++ b/app/soc/templates/soc/role/edit.html Tue Aug 25 16:15:07 2009 +0100
@@ -18,7 +18,7 @@
{{ block.super }}
{% if gmaps_api_key %}
<script src="http://maps.google.com/maps?file=api&v=2&key={{ gmaps_api_key }}" type="text/javascript"></script>
- <script type="text/javascript" src="/soc/content/js/map-090730.js"></script>
+ <script type="text/javascript" src="/soc/content/js/map-090825.js"></script>
{% endif %}
{% endblock %}
--- a/app/soc/templates/soc/student_project/public.html Tue Aug 25 15:58:30 2009 +0100
+++ b/app/soc/templates/soc/student_project/public.html Tue Aug 25 16:15:07 2009 +0100
@@ -18,7 +18,7 @@
{{ block.super }}
{% if entity.feed_url %}
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
- <script type="text/javascript" src="/soc/content/js/blog-081117.js"></script>
+ <script type="text/javascript" src="/soc/content/js/blog-090825.js"></script>
<script type="text/javascript" >
google.load("feeds", "1");
--- a/app/soc/templates/soc/survey/edit.html Tue Aug 25 15:58:30 2009 +0100
+++ b/app/soc/templates/soc/survey/edit.html Tue Aug 25 16:15:07 2009 +0100
@@ -23,7 +23,7 @@
<script type="text/javascript" src="/jquery/jquery-ui.dialog.js"></script>
<script type="text/javascript" src="/jquery/jquery-growfield.js"></script>
<script type="text/javascript" src="/jquery/jquery-editable-1.3.3.js"></script>
-<script type="text/javascript" src="/soc/content/js/survey-edit-090708.js"></script>
+<script type="text/javascript" src="/soc/content/js/survey-edit-090825.js"></script>
{% endblock %}
--- a/app/soc/templates/soc/survey/public.html Tue Aug 25 15:58:30 2009 +0100
+++ b/app/soc/templates/soc/survey/public.html Tue Aug 25 16:15:07 2009 +0100
@@ -17,7 +17,7 @@
{% block scripts %}
{{ block.super }}
<script type="text/javascript" src="/soc/content/js/survey-default-text-090627.js"></script>
-<script type="text/javascript" src="/soc/content/js/survey-take-090708.js"></script>
+<script type="text/javascript" src="/soc/content/js/survey-take-090825.js"></script>
<script type="text/javascript" src="/jquery/jquery-growfield.js"></script>
{% endblock %}
--- a/app/soc/templates/soc/survey/results_page.html Tue Aug 25 15:58:30 2009 +0100
+++ b/app/soc/templates/soc/survey/results_page.html Tue Aug 25 16:15:07 2009 +0100
@@ -23,7 +23,7 @@
<script type="text/javascript" src="/jquery/jquery-ui.dialog.js"></script>
<script type="text/javascript" src="/jquery/jquery-growfield.js"></script>
<script type="text/javascript" src="/jquery/jquery-editable-1.3.3.js"></script>
-<script type="text/javascript" src="/soc/content/js/survey-edit-090708.js"></script>
+<script type="text/javascript" src="/soc/content/js/survey-edit-090825.js"></script>
{% endblock %}
--- a/app/soc/templates/soc/survey/take.html Tue Aug 25 15:58:30 2009 +0100
+++ b/app/soc/templates/soc/survey/take.html Tue Aug 25 16:15:07 2009 +0100
@@ -17,7 +17,7 @@
{% block scripts %}
{{ block.super }}
<script type="text/javascript" src="/soc/content/js/survey-default-text-090627.js"></script>
-<script type="text/javascript" src="/soc/content/js/survey-take-090708.js"></script>
+<script type="text/javascript" src="/soc/content/js/survey-take-090825.js"></script>
<script type="text/javascript" src="/jquery/jquery-growfield.js"></script>
{% endblock %}