Stricter parameter checking in JavaScript.
This commit is contained in:
@@ -36,8 +36,7 @@
|
|||||||
*/
|
*/
|
||||||
function task_open(task_id, project_url) {
|
function task_open(task_id, project_url) {
|
||||||
if (task_id === undefined || project_url === undefined) {
|
if (task_id === undefined || project_url === undefined) {
|
||||||
if (console) console.log("task_open(", task_id, project_url, ") called.");
|
throw new ReferenceError("task_open(" + task_id + ", " + project_url + ") called.");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$('#col_right .col_header span.header_text').text('Task details');
|
$('#col_right .col_header span.header_text').text('Task details');
|
||||||
@@ -63,8 +62,7 @@ function task_open(task_id, project_url) {
|
|||||||
*/
|
*/
|
||||||
function shot_open(shot_id, project_url) {
|
function shot_open(shot_id, project_url) {
|
||||||
if (shot_id === undefined || project_url === undefined) {
|
if (shot_id === undefined || project_url === undefined) {
|
||||||
if (console) console.log("shot_open(", shot_id, project_url, ") called.");
|
throw new ReferenceError("shot_open(" + shot_id + ", " + project_url + ") called.");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$('#col_right .col_header span.header_text').text('Shot details');
|
$('#col_right .col_header span.header_text').text('Shot details');
|
||||||
@@ -91,8 +89,7 @@ function shot_open(shot_id, project_url) {
|
|||||||
*/
|
*/
|
||||||
function task_create(shot_id, project_url, task_type) {
|
function task_create(shot_id, project_url, task_type) {
|
||||||
if (shot_id === undefined || project_url === undefined || task_type === undefined) {
|
if (shot_id === undefined || project_url === undefined || task_type === undefined) {
|
||||||
if (console) console.log("task_create(", shot_id, project_url, task_type, ") called.");
|
throw "task_create(" + shot_id + ", " + project_url+ ", " + task_type + ") called.";
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
var url = '/attract/' + project_url + '/tasks/create';
|
var url = '/attract/' + project_url + '/tasks/create';
|
||||||
|
|
||||||
@@ -116,6 +113,11 @@ function task_create(shot_id, project_url, task_type) {
|
|||||||
|
|
||||||
function attract_form_save(form_id, item_id, item_save_url, options={})
|
function attract_form_save(form_id, item_id, item_save_url, options={})
|
||||||
{
|
{
|
||||||
|
// Mandatory option.
|
||||||
|
if (typeof options.type === 'undefined') {
|
||||||
|
throw 'attract_form_save(): options.type is mandatory.';
|
||||||
|
}
|
||||||
|
|
||||||
var $form = $('#' + form_id);
|
var $form = $('#' + form_id);
|
||||||
var $button = $form.find("button[type='submit']");
|
var $button = $form.find("button[type='submit']");
|
||||||
|
|
||||||
@@ -139,7 +141,7 @@ function attract_form_save(form_id, item_id, item_save_url, options={})
|
|||||||
})
|
})
|
||||||
.fail(function(xhr_or_response_data) {
|
.fail(function(xhr_or_response_data) {
|
||||||
// jQuery sends the response data (if JSON), or an XHR object (if not JSON).
|
// jQuery sends the response data (if JSON), or an XHR object (if not JSON).
|
||||||
if (console) console.log('Failed saving', xhr_or_response_data);
|
if (console) console.log('Failed saving', options.type, xhr_or_response_data);
|
||||||
|
|
||||||
$button.removeClass('btn-default').addClass('btn-danger');
|
$button.removeClass('btn-default').addClass('btn-danger');
|
||||||
$('#status-bar').text('Failed saving. ' + xhr_or_response_data.status);
|
$('#status-bar').text('Failed saving. ' + xhr_or_response_data.status);
|
||||||
|
Reference in New Issue
Block a user