validate: function(attrs) { if (!attrs) return; if (attrs.type === "file") { // Number of files if (attrs.value && attrs.value.length) { return { msg: "Unfortunately only one file is allowed per upload" } } // File name var name = attrs.value.name; if (!name) { return { msg: "File name should be defined" } } // File extension var ext = name.substr(name.lastIndexOf('.') + 1); if (ext) { ext = ext.toLowerCase(); } if (!_.contains(UploadConfig.fileExtensions, ext)) { return { msg: "Unfortunately this file extension is not allowed" } } // File size if (this.user && ((this.user.get('remaining_byte_quota') * UploadConfig.fileTimesBigger) < attrs.value.size)) { return { msg: "Unfortunately the size of the file is bigger than your remaining quota", error_code: 8001 } } } if (attrs.type === "remote") { // Valid remote visualization id? if (!attrs.remote_visualization_id) { return { msg: "The remote visualization id was not specified" } } // Remote size? if (this.user && attrs.size && ((this.user.get('remaining_byte_quota') * UploadConfig.fileTimesBigger) < attrs.size)) { return { msg: "Unfortunately the size of the remote dataset is bigger than your remaining quota", error_code: 8001 } } } if (attrs.type === "url") { // Valid URL? if (!Utils.isURL(attrs.value)) { return { msg: "Unfortunately the URL provided is not valid" } } } if (attrs.type === "sql") { if (!attrs.value) { return { msg: "Query is not provided" } } } if (attrs.type === "duplication") { if (!attrs.value) { return { msg: "Dataset copy is not defined" } } } if (attrs.type === "service" && attrs.service_name === "twitter_search") { var service_item_id = attrs.service_item_id; // Empty? if (!service_item_id || _.isEmpty(service_item_id)) { return { msg: "Twitter data is empty" } } // Categories? if (_.isEmpty(service_item_id.categories)) { return { msg: "Twitter categories are not valid" } } // Dates? var dates = service_item_id.dates; if (!dates || _.isEmpty(dates)) { return { msg: "Twitter dates are empty" } } var isToDateValid = moment(dates.fromDate) <= moment(new Date()); if (!dates.fromDate || !dates.toDate || !isToDateValid) { return { msg: "Twitter dates are not valid" } } } },