# HG changeset patch # User Mario Ferraro # Date 1251213307 -3600 # Node ID 0ee67cc9bd207115cc8a30316dc5867ac98bef8b # Parent cd9eed2b787e9146cd976377c522e639307719bb Renamed all JS files affected by former commit. And also changed templates accordingly. diff -r cd9eed2b787e -r 0ee67cc9bd20 app/soc/content/js/blog-081117.js --- 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; -}; - diff -r cd9eed2b787e -r 0ee67cc9bd20 app/soc/content/js/blog-090825.js --- /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; +}; + diff -r cd9eed2b787e -r 0ee67cc9bd20 app/soc/content/js/bulk-review-090304.js --- 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([ - "", - " Error encountered, try again", - "" - ].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("Done!"); - } - } - }, - 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("" + no_organization_text + ""); - } - } - ); -} diff -r cd9eed2b787e -r 0ee67cc9bd20 app/soc/content/js/bulk-review-090825.js --- /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([ + "", + " Error encountered, try again", + "" + ].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("Done!"); + } + } + }, + 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("" + no_organization_text + ""); + } + } + ); +} diff -r cd9eed2b787e -r 0ee67cc9bd20 app/soc/content/js/datetime-loader-090304.js --- 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(); - } -); - diff -r cd9eed2b787e -r 0ee67cc9bd20 app/soc/content/js/datetime-loader-090825.js --- /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(); + } +); + diff -r cd9eed2b787e -r 0ee67cc9bd20 app/soc/content/js/datetimepicker-090304.js --- 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' - }); - } -); - diff -r cd9eed2b787e -r 0ee67cc9bd20 app/soc/content/js/datetimepicker-090825.js --- /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' + }); + } +); + diff -r cd9eed2b787e -r 0ee67cc9bd20 app/soc/content/js/duplicate-slots-090505.js --- 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 = ''; - 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("No duplicate slots found"); - } - // 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([ - " ", - "Error encountered, try again", - "" - ].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("No org slots to process"); - 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(" Done!"); - 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 diff -r cd9eed2b787e -r 0ee67cc9bd20 app/soc/content/js/duplicate-slots-090825.js --- /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 = ''; + 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("No duplicate slots found"); + } + // 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([ + " ", + "Error encountered, try again", + "" + ].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("No org slots to process"); + 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(" Done!"); + 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 diff -r cd9eed2b787e -r 0ee67cc9bd20 app/soc/content/js/map-090730.js --- 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 = [ - "", person.name, "
", - "Student
", - "
" - ].join(""); - // iterate through projects - jQuery.each(person.projects, function () { - var current_project = map_data.projects[this]; - html += [ - "", - current_project.title, "
", - "Mentor: ", current_project.mentor_name, "
" - ].join(""); - }); - html += "
"; - 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 = [ - "", person.name, "
", - "Mentor
", - "
" - ].join(""); - // iterate through projects - jQuery.each(person.projects, function () { - var current_project = map_data.projects[this]; - html += [ - "", - current_project.title, "
", - "Student: ", current_project.student_name, "
" - ].join(""); - }); - html += "
"; - - 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); - }); - } - }; -}()); diff -r cd9eed2b787e -r 0ee67cc9bd20 app/soc/content/js/map-090825.js --- /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 = [ + "", person.name, "
", + "Student
", + "
" + ].join(""); + // iterate through projects + jQuery.each(person.projects, function () { + var current_project = map_data.projects[this]; + html += [ + "", + current_project.title, "
", + "Mentor: ", current_project.mentor_name, "
" + ].join(""); + }); + html += "
"; + 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 = [ + "", person.name, "
", + "Mentor
", + "
" + ].join(""); + // iterate through projects + jQuery.each(person.projects, function () { + var current_project = map_data.projects[this]; + html += [ + "", + current_project.title, "
", + "Student: ", current_project.student_name, "
" + ].join(""); + }); + html += "
"; + + 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); + }); + } + }; +}()); diff -r cd9eed2b787e -r 0ee67cc9bd20 app/soc/content/js/menu-081108.js --- 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(''); -}); diff -r cd9eed2b787e -r 0ee67cc9bd20 app/soc/content/js/menu-090825.js --- /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(''); +}); diff -r cd9eed2b787e -r 0ee67cc9bd20 app/soc/content/js/slot-allocator-090320.js --- 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 = [ - "
", - "
", - "", - "

Slots

", - "

", - "

", - "

", - "
", - "
" -].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("Assigned slots: " + current_allocated_slots); - jQuery("#p_remaining_slots") - .html("Remaining slots: " + 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(); -} - diff -r cd9eed2b787e -r 0ee67cc9bd20 app/soc/content/js/slot-allocator-090825.js --- /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 = [ + "
", + "
", + "", + "

Slots

", + "

", + "

", + "

", + "
", + "
" +].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("Assigned slots: " + current_allocated_slots); + jQuery("#p_remaining_slots") + .html("Remaining slots: " + 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(); +} + diff -r cd9eed2b787e -r 0ee67cc9bd20 app/soc/content/js/survey-edit-090708.js --- 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 Daniel Diniz -* @author James Levy -*/ - -(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 = [""].join(""); - var del_li = [" "]; - - 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 = ['
'].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 = $(""); - 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 = [ - '', - ' ' - ].join(""); - - var CHOOSE_A_GRADE_FIELD = [ - '', - '', - '' - ].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 = [ - " " - ]; - - // 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 = $([ - '
  • ', - '', - '', name, '', '', '
  • ' - ].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 = [""].join(""); - var del_li = [" "]; - - - 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 = $([" "].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 = [""].join(""); - - // create the HTML for the field - switch (button_id) { - case "short_answer": - new_field = ["
    \n", - '', - '', '', - '', - "", "
    " - ].join(""); - break; - case "long_answer": - field_count = survey_table.find('fieldset').length; - new_field_count = field_count + 1 + '__'; - new_field = ['
    \n', '', - '', '', - '', - "