Commit 761a3ec0a5a6cc9cb5425c79f0c7422c76465afa

Authored by Adabriand Furtado
1 parent e89d1e6b
Exists in master

Logic in JS moved to corretor.js for modularization.

corretor.py
... ... @@ -39,13 +39,46 @@ class Corretor:
39 39  
40 40 def __update_project_info(self, project):
41 41 template = self.env.get_template('template.html')
42   - project.info['task_presenter'] = template.render(server=self.config['HOST_ENDPOINT'])
  42 + project.info['task_presenter'] = template.render(server=self.config['HOST_ENDPOINT'], app_shortname=self.config['PYBOSSA_APP_SHORT_NAME'])
43 43 project.info['thumbnail'] = self.config['HOST_ENDPOINT'] + "/img/thumbnail.png"
44 44 project.info['sched'] = "incremental"
45 45 project.allow_anonymous_contributors = False
46 46 pbclient.update_project(project)
47 47  
  48 + def __find_task(self, project_id, task_id):
  49 + tasks = pbclient.find_tasks(project_id, id=task_id)
  50 + return tasks[0] if len(tasks) > 0 else None
  51 +
  52 + def __find_taskruns(self, project_id, task_id):
  53 + return pbclient.find_taskruns(project_id, id=task_id)
  54 +
  55 + def __number_of_taskruns(self, project_id, task_id):
  56 + taskruns = self.__find_taskruns(project_id, task_id)
  57 + return len(taskruns)
  58 +
  59 + def __close_task(self, project_id, task_id):
  60 + pyutil.log("Closing the task with ID=" + str(task_id) + ".")
  61 + task = self.__find_task(project_id, task_id)
  62 + number_of_taskruns = self.__number_of_taskruns(project_id, task_id)
  63 + task.n_answers = number_of_taskruns + 1
  64 + pbclient.update_task(task)
  65 + return "The task with ID=" + str(task_id) + " was closed."
  66 +
48 67 def finish_task(self):
  68 + task_id = request.form['task_id']
  69 + project_id = request.form['project_id']
  70 + number_of_approval = int(request.form['number_of_approval'])
  71 + agreement_number = self.config['AGREEMENT_NUMBER']
  72 + result_msg = ""
  73 + code = 200
  74 + if (number_of_approval >= agreement_number):
  75 + result_msg = self.__close_task(project_id, task_id)
  76 + else:
  77 + result_msg = "The task with ID=" + str(task_id) + " didn't reach the agreement number yet."
  78 + pyutil.log(result_msg)
  79 + return make_response(result_msg, code)
  80 +
  81 + def render_video(self):
49 82 upload_session_id = request.form['upload_session_id']
50 83 sign_name = request.form['sign_name']
51 84 upload_dir = os.path.join(self.config['UPLOAD_FOLDER'], upload_session_id)
... ... @@ -55,10 +88,10 @@ class Corretor:
55 88 code = 0
56 89 result_msg = ""
57 90 if(checkout_result == 0):
58   - result_msg = "Video gerado com sucesso."
59   - code = 200
  91 + result_msg = "Successfully rendered the video."
  92 + code = 200
60 93 else:
61   - result_msg = "Erro durante geração de vídeo."
  94 + result_msg = "Error while rendering the video."
62 95 code = 400
63 96 pyutil.log(result_msg)
64 97 return make_response(result_msg, code)
... ... @@ -116,7 +149,7 @@ class Corretor:
116 149 result_msg = "File " + filename + " was uploaded."
117 150 code = 200
118 151 else:
119   - result_msg = "File " + filename + " has not expected structure of blend file. " + str(checkout_result)
  152 + result_msg = "File " + filename + " has not expected structure of blend file. "
120 153 code = 400
121 154 pyutil.log(result_msg)
122 155 return make_response(result_msg, code)
... ...
main.py
... ... @@ -40,6 +40,14 @@ def upload_file():
40 40 pyutil.print_stack_trace()
41 41 raise
42 42  
  43 +@app.route("/render_video", methods=["POST"])
  44 +def render_video():
  45 + try:
  46 + return controller.render_video()
  47 + except:
  48 + pyutil.print_stack_trace()
  49 + raise
  50 +
43 51 @app.route("/finish_task", methods=["POST"])
44 52 def finish_task():
45 53 try:
... ...
settings_local.py.tmpl
... ... @@ -2,6 +2,7 @@
2 2 # Corretor Server Configuration
3 3 SERVER_HOST = "localhost"
4 4 SERVER_PORT = 8000
  5 +AGREEMENT_NUMBER = 2
5 6 UPLOAD_FOLDER = "<path-to-corretor>/view/uploads"
6 7  
7 8 # PyBossa Configuration
... ...
view/assets/css/main.css
... ... @@ -2,12 +2,7 @@
2 2 font-family: 'Titillium Web';
3 3 src: url('../fonts/TitilliumWeb-SemiBold.ttf') format('truetype');
4 4 }
5   -/*
6   -video {
7   - -webkit-transform: scaleX(1.05);
8   - -moz-transform: scaleX(1.05);
9   -}
10   -*/
  5 +
11 6 .video-body {
12 7 height: 50%;
13 8 width: 85%;
... ... @@ -48,10 +43,6 @@ video {
48 43 padding-bottom: 10px;
49 44 }
50 45  
51   -#approval-container {
52   - display: none;
53   -}
54   -
55 46 /* Tabela */
56 47 .table-responsive {
57 48 border: none;
... ... @@ -88,29 +79,6 @@ h6 {
88 79 font-size: 20px;
89 80 }
90 81  
91   -/*
92   -.btn-file {
93   - position: relative;
94   - overflow: hidden;
95   -}
96   -
97   -.btn-file input[type=file] {
98   - background: rgba(94, 199, 189, 1);
99   - position: absolute;
100   - top: 0;
101   - right: 0;
102   - min-width: 100%;
103   - min-height: 100%;
104   - font-size: 100px;
105   - text-align: right;
106   - filter: alpha(opacity=0);
107   - opacity: 0;
108   - outline: none;
109   - background: white;
110   - cursor: inherit;
111   - display: block;
112   -}
113   -*/
114 82 .btn-default, .progress-bar {
115 83 background-color: rgba(94, 199, 189, 1.0);
116 84 }
... ... @@ -181,12 +149,11 @@ h6 {
181 149 padding-right: 40px;
182 150 }
183 151  
184   -#approval-task-container {
185   - padding-top: 6px;
186   - padding-right: 40px;
  152 +#fix-button {
  153 + display: none;
187 154 }
188 155  
189   -#fix-button {
  156 +#approval-button {
190 157 display: none;
191 158 }
192 159  
... ... @@ -223,8 +190,6 @@ h6 {
223 190 z-index: 1040;
224 191 }
225 192  
226   -
227   -
228 193 #loading-container img {
229 194 position: absolute;
230 195 width: 80px;
... ...
view/assets/js/corretor.js 0 → 100644
... ... @@ -0,0 +1,284 @@
  1 +(function(corretor, $, undefined) {
  2 +
  3 + var base_url = "";
  4 + var videos_url = "/videos/";
  5 + var uploads_url = "/uploads/";
  6 + var upload_session_id = _getUploadSessionID();
  7 + var current_task_id = -1;
  8 +
  9 + function _getUploadSessionID() {
  10 + var corretor_session_id = Cookies.get("corretor_session_id");
  11 + var upload_session_id = "";
  12 + if (typeof corretor_session_id == "undefined") {
  13 + upload_session_id = _createUploadSessionID();
  14 + } else {
  15 + var pybossa_rembember_token = Cookies.get("remember_token");
  16 + var splitted_session_id = corretor_session_id.split(";");
  17 + var last_remember_token = splitted_session_id[0];
  18 + var upload_session_id = splitted_session_id[1];
  19 + if (pybossa_rembember_token != last_remember_token) {
  20 + upload_session_id = _createUploadSessionID();
  21 + }
  22 + }
  23 + return upload_session_id;
  24 + }
  25 +
  26 + function _createUploadSessionID() {
  27 + var upload_session_id = _generateSessionID();
  28 + var pybossa_rembember_token = Cookies.get("remember_token");
  29 + corretor_session_id = pybossa_rembember_token + ";" + upload_session_id;
  30 + Cookies.set("corretor_session_id", corretor_session_id, {
  31 + path : "/",
  32 + expires : 365
  33 + });
  34 + return upload_session_id;
  35 + }
  36 +
  37 + function _generateSessionID() {
  38 + return (Math.random() + " ").substring(2, 10)
  39 + + (Math.random() + " ").substring(2, 10);
  40 + }
  41 +
  42 + function _resetUploadProgress() {
  43 + $("#upload-progress .progress-bar").css("width", "0%");
  44 + }
  45 +
  46 + function _enableFinishButton(task, deferred) {
  47 + $("#finish-button").removeClass("disabled-button");
  48 + $("#finish-button").addClass("enabled-button");
  49 + $("#finish-button").off("click").on("click", function() {
  50 + _submitAnswer(task, deferred, "FIXED");
  51 + });
  52 + }
  53 +
  54 + function _enableLoading() {
  55 + $("#loading-container").show();
  56 + $("#main-container").addClass("mask");
  57 + }
  58 +
  59 + function _disableLoading() {
  60 + $("#loading-container").hide();
  61 + $("#main-container").removeClass("mask");
  62 + }
  63 +
  64 + function _disableFinishButton() {
  65 + $("#finish-button").off("click");
  66 + $("#finish-button").removeClass("enabled-button");
  67 + $("#finish-button").addClass("disabled-button");
  68 + }
  69 +
  70 + function _disableApprovalButton() {
  71 + $("#approval-button").off("click");
  72 + $("#approval-button").removeClass("enabled-button");
  73 + $("#approval-button").addClass("disabled-button");
  74 + }
  75 +
  76 + function _showApprovalGUI(task, deferred) {
  77 + $("#upload-container").hide();
  78 + $(".link-container").hide();
  79 + $("#finish-button").hide();
  80 + $("#approval-button").show();
  81 + $("#fix-button").show();
  82 + _enableFinishButton(task, deferred);
  83 + }
  84 +
  85 + function _showFixGUI() {
  86 + _disableFinishButton();
  87 + $("#upload-container").show();
  88 + $(".link-container").show();
  89 + $("#finish-button").show();
  90 + $("#approval-button").hide();
  91 + $("#fix-button").hide();
  92 + }
  93 +
  94 + function setupButtons(task, deferred) {
  95 + _disableFinishButton();
  96 + _resetUploadProgress();
  97 + $("#upload-file-name").text("Escolha um arquivo");
  98 + $("#file-upload").val("");
  99 + $("#file-upload").fileupload(
  100 + {
  101 + url : base_url + "/upload",
  102 + formData : {
  103 + "upload_session_id" : upload_session_id,
  104 + 'sign_name' : task.info.sign_name
  105 + },
  106 + add : function(e, data) {
  107 + _resetUploadProgress();
  108 + $("#upload-file-name").text(data.files[0].name)
  109 + data.submit();
  110 + },
  111 + done : function(e, data) {
  112 + _enableFinishButton(task, deferred);
  113 + },
  114 + progressall : function(e, data) {
  115 + var progress = parseInt(data.loaded / data.total * 100,
  116 + 10);
  117 + $("#upload-progress .progress-bar").css("width",
  118 + progress + "%");
  119 + },
  120 + error : function(error) {
  121 + alert(error.responseText);
  122 + _resetUploadProgress();
  123 + _disableFinishButton();
  124 + }
  125 + });
  126 +
  127 + $("#upload-button").off("click").on("click", function() {
  128 + $("#file-upload").click();
  129 + });
  130 + $("#skip-button").off("click").on("click", function() {
  131 + _submitAnswer(task, deferred, "SKIPPED");
  132 + });
  133 + $("#approval-button").off("click").on("click", function() {
  134 + _submitAnswer(task, deferred, "APPROVED");
  135 + });
  136 + $("#fix-button").off("click").on("click", function() {
  137 + _showFixGUI();
  138 + });
  139 + }
  140 +
  141 + function _createAnswer(task, status) {
  142 + var answer = {};
  143 + var last_answer = task.info.last_answer;
  144 + var hasLastAnswer = typeof last_answer != "undefined";
  145 + if (hasLastAnswer) {
  146 + answer = last_answer;
  147 + } else {
  148 + answer = {
  149 + "number_of_fixes" : 0,
  150 + "number_of_approval" : 0
  151 + };
  152 + }
  153 + answer["status"] = status;
  154 + if (status == "FIXED") {
  155 + answer["last_edit_date"] = moment(new Date()).format(
  156 + "YYYY-MM-DDTHH:mm:ss")
  157 + answer["upload_session_id"] = upload_session_id;
  158 + answer["number_of_fixes"] = answer.number_of_fixes + 1;
  159 + answer["number_of_approval"] = 0;
  160 + } else if (status == "APPROVED") {
  161 + answer["number_of_approval"] = answer.number_of_approval + 1;
  162 + }
  163 + return answer;
  164 + }
  165 +
  166 + function _renderVideo(task, deferred, answer) {
  167 + _enableLoading();
  168 + $.ajax({
  169 + type : "POST",
  170 + url : base_url + "/render_video",
  171 + data : {
  172 + "upload_session_id" : upload_session_id,
  173 + "sign_name" : task.info.sign_name
  174 + },
  175 + success : function(response) {
  176 + _disableLoading();
  177 + _saveAnswer(task, deferred, answer);
  178 + },
  179 + error : function(xhr, textStatus, error) {
  180 + _disableLoading();
  181 + _disableFinishButton();
  182 + alert(xhr.responseText);
  183 + }
  184 + });
  185 + }
  186 +
  187 + function _finishTask(task, deferred, answer) {
  188 + _enableLoading();
  189 + $.ajax({
  190 + type : "POST",
  191 + url : base_url + "/finish_task",
  192 + data : {
  193 + "task_id" : task.id,
  194 + "project_id" : task.project_id,
  195 + "number_of_approval" : answer.number_of_approval,
  196 + },
  197 + success : function(response) {
  198 + _disableLoading();
  199 + _saveAnswer(task, deferred, answer);
  200 + },
  201 + error : function(xhr, textStatus, error) {
  202 + _disableLoading();
  203 + _disableApprovalButton();
  204 + alert(xhr.responseText);
  205 + }
  206 + });
  207 + }
  208 +
  209 + function _saveAnswer(task, deferred, answer) {
  210 + pybossa.saveTask(task.id, answer).done(function() {
  211 + $("#success").fadeIn(500);
  212 + $("#main-container").hide();
  213 + setTimeout(function() {
  214 + deferred.resolve();
  215 + }, 2000);
  216 + });
  217 + }
  218 +
  219 + function _submitAnswer(task, deferred, status) {
  220 + var answer = _createAnswer(task, status);
  221 + if (status == "FIXED") {
  222 + _renderVideo(task, deferred, answer);
  223 + } else if (status == "APPROVED") {
  224 + _finishTask(task, deferred, answer);
  225 + } else if (status == "SKIPPED") {
  226 + _saveAnswer(task, deferred, answer);
  227 + }
  228 + }
  229 +
  230 + function _loadTaskInfo(task, deferred) {
  231 + current_task_id = task.id;
  232 + var sign_name = task.info.sign_name;
  233 + var blend_link = videos_url + sign_name + "_AVATAR.blend";
  234 + var avatar_vid_link = videos_url + sign_name + "_AVATAR.webm";
  235 + var ref_vid_link = videos_url + sign_name + "_REF.webm";
  236 + $(".sign-label").text(sign_name);
  237 + $("#submission-date").text(
  238 + moment(task.info.submission_date).format("DD/MM/YYYY"));
  239 + $("#ref-video").attr("src", ref_vid_link);
  240 + $("#ref-video-link").attr("href", ref_vid_link);
  241 +
  242 + var last_answer = task.info.last_answer;
  243 + var hasLastAnswer = typeof last_answer != "undefined";
  244 + if (hasLastAnswer
  245 + && typeof last_answer.upload_session_id != "undefined") {
  246 + blend_link = uploads_url + last_answer.upload_session_id + "/"
  247 + + sign_name + ".blend";
  248 + avatar_vid_link = uploads_url + last_answer.upload_session_id + "/"
  249 + + sign_name + ".webm";
  250 + $("#last-edit-date").text(
  251 + moment(last_answer.last_edit_date).format("DD/MM/YYYY"));
  252 + $("#number-of-fixes").text(last_answer.number_of_fixes);
  253 + _showApprovalGUI(task, deferred);
  254 + }
  255 + $("#blend-link").attr("href", blend_link);
  256 + $("#avatar-video").attr("src", avatar_vid_link);
  257 + }
  258 +
  259 + pybossa.presentTask(function(task, deferred) {
  260 + if (!$.isEmptyObject(task) && current_task_id != task.id) {
  261 + _loadTaskInfo(task, deferred);
  262 + setupButtons(task, deferred);
  263 + $("#success").hide();
  264 + $("#main-container").fadeIn(500);
  265 + } else {
  266 + $("#main-container").hide();
  267 + $("#finish").fadeIn(500);
  268 + }
  269 + });
  270 +
  271 + // Private methods
  272 + function _run(projectname) {
  273 + pybossa.run(projectname);
  274 + }
  275 +
  276 + // Public methods
  277 + corretor.run = function(serverhost, projectname) {
  278 + base_url = serverhost;
  279 + videos_url = base_url + videos_url;
  280 + uploads_url = base_url + uploads_url;
  281 + _run(projectname);
  282 + };
  283 +
  284 +}(window.corretor = window.corretor || {}, jQuery));
0 285 \ No newline at end of file
... ...
view/assets/js/js.cookie.js 0 → 100644
... ... @@ -0,0 +1,145 @@
  1 +/*!
  2 + * JavaScript Cookie v2.0.4
  3 + * https://github.com/js-cookie/js-cookie
  4 + *
  5 + * Copyright 2006, 2015 Klaus Hartl & Fagner Brack
  6 + * Released under the MIT license
  7 + */
  8 +(function (factory) {
  9 + if (typeof define === 'function' && define.amd) {
  10 + define(factory);
  11 + } else if (typeof exports === 'object') {
  12 + module.exports = factory();
  13 + } else {
  14 + var _OldCookies = window.Cookies;
  15 + var api = window.Cookies = factory();
  16 + api.noConflict = function () {
  17 + window.Cookies = _OldCookies;
  18 + return api;
  19 + };
  20 + }
  21 +}(function () {
  22 + function extend () {
  23 + var i = 0;
  24 + var result = {};
  25 + for (; i < arguments.length; i++) {
  26 + var attributes = arguments[ i ];
  27 + for (var key in attributes) {
  28 + result[key] = attributes[key];
  29 + }
  30 + }
  31 + return result;
  32 + }
  33 +
  34 + function init (converter) {
  35 + function api (key, value, attributes) {
  36 + var result;
  37 +
  38 + // Write
  39 +
  40 + if (arguments.length > 1) {
  41 + attributes = extend({
  42 + path: '/'
  43 + }, api.defaults, attributes);
  44 +
  45 + if (typeof attributes.expires === 'number') {
  46 + var expires = new Date();
  47 + expires.setMilliseconds(expires.getMilliseconds() + attributes.expires * 864e+5);
  48 + attributes.expires = expires;
  49 + }
  50 +
  51 + try {
  52 + result = JSON.stringify(value);
  53 + if (/^[\{\[]/.test(result)) {
  54 + value = result;
  55 + }
  56 + } catch (e) {}
  57 +
  58 + if (!converter.write) {
  59 + value = encodeURIComponent(String(value))
  60 + .replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent);
  61 + } else {
  62 + value = converter.write(value, key);
  63 + }
  64 +
  65 + key = encodeURIComponent(String(key));
  66 + key = key.replace(/%(23|24|26|2B|5E|60|7C)/g, decodeURIComponent);
  67 + key = key.replace(/[\(\)]/g, escape);
  68 +
  69 + return (document.cookie = [
  70 + key, '=', value,
  71 + attributes.expires && '; expires=' + attributes.expires.toUTCString(), // use expires attribute, max-age is not supported by IE
  72 + attributes.path && '; path=' + attributes.path,
  73 + attributes.domain && '; domain=' + attributes.domain,
  74 + attributes.secure ? '; secure' : ''
  75 + ].join(''));
  76 + }
  77 +
  78 + // Read
  79 +
  80 + if (!key) {
  81 + result = {};
  82 + }
  83 +
  84 + // To prevent the for loop in the first place assign an empty array
  85 + // in case there are no cookies at all. Also prevents odd result when
  86 + // calling "get()"
  87 + var cookies = document.cookie ? document.cookie.split('; ') : [];
  88 + var rdecode = /(%[0-9A-Z]{2})+/g;
  89 + var i = 0;
  90 +
  91 + for (; i < cookies.length; i++) {
  92 + var parts = cookies[i].split('=');
  93 + var name = parts[0].replace(rdecode, decodeURIComponent);
  94 + var cookie = parts.slice(1).join('=');
  95 +
  96 + if (cookie.charAt(0) === '"') {
  97 + cookie = cookie.slice(1, -1);
  98 + }
  99 +
  100 + try {
  101 + cookie = converter.read ?
  102 + converter.read(cookie, name) : converter(cookie, name) ||
  103 + cookie.replace(rdecode, decodeURIComponent);
  104 +
  105 + if (this.json) {
  106 + try {
  107 + cookie = JSON.parse(cookie);
  108 + } catch (e) {}
  109 + }
  110 +
  111 + if (key === name) {
  112 + result = cookie;
  113 + break;
  114 + }
  115 +
  116 + if (!key) {
  117 + result[name] = cookie;
  118 + }
  119 + } catch (e) {}
  120 + }
  121 +
  122 + return result;
  123 + }
  124 +
  125 + api.get = api.set = api;
  126 + api.getJSON = function () {
  127 + return api.apply({
  128 + json: true
  129 + }, [].slice.call(arguments));
  130 + };
  131 + api.defaults = {};
  132 +
  133 + api.remove = function (key, attributes) {
  134 + api(key, '', extend(attributes, {
  135 + expires: -1
  136 + }));
  137 + };
  138 +
  139 + api.withConverter = init;
  140 +
  141 + return api;
  142 + }
  143 +
  144 + return init(function () {});
  145 +}));
... ...
view/template.html
... ... @@ -4,6 +4,8 @@
4 4 <script src="{{ server }}/assets/js/jquery.iframe-transport.js"></script>
5 5 <script src="{{ server }}/assets/js/jquery.fileupload.js"></script>
6 6 <script src="{{ server }}/assets/js/moment.js"></script>
  7 +<script src="{{ server }}/assets/js/js.cookie.js"></script>
  8 +<script src="{{ server }}/assets/js/corretor.js"></script>
7 9  
8 10 <div id="loading-container">
9 11 <img src="{{ server }}/img/loading.gif">
... ... @@ -109,8 +111,12 @@
109 111 </a>
110 112 </div>
111 113 <div id="finish-task-container" class="row">
112   - <div id="finish-button" class="finish-task-button disabled-button ">
113   - <span id="finish-button-text">FINALIZAR</span><img class="icon"
  114 + <div id="approval-button" class="finish-task-button enabled-button">
  115 + <span>APROVAR</span><img class="icon"
  116 + src="{{ server }}/img/finish.svg"></img>
  117 + </div>
  118 + <div id="finish-button" class="finish-task-button disabled-button">
  119 + <span>FINALIZAR</span><img class="icon"
114 120 src="{{ server }}/img/finish.svg"></img>
115 121 </div>
116 122 <div id="fix-button" class="finish-task-button enabled-button">
... ... @@ -125,191 +131,5 @@
125 131 </div>
126 132  
127 133 <script type="text/javascript">
128   - var base_url = "{{ server }}/videos/";
129   - var upload_session_id = generateSessionID();
130   - var current_task_id = -1;
131   - var status_dict = {
132   - "APROVAR" : "APPROVED",
133   - "FINALIZAR" : "FINISHED"
134   - };
135   -
136   - function generateSessionID() {
137   - return (Math.random() + " ").substring(2, 10)
138   - + (Math.random() + " ").substring(2, 10);
139   - }
140   -
141   - function resetUploadProgress() {
142   - $("#upload-progress .progress-bar").css("width", "0%");
143   - }
144   -
145   - function enableFinishButton(task, deferred) {
146   - $("#finish-button").removeClass("disabled-button");
147   - $("#finish-button").addClass("enabled-button");
148   - $("#finish-button").off("click").on("click", function() {
149   - enableLoading();
150   - $.post("{{ server }}/finish_task",
151   - {
152   - "upload_session_id": upload_session_id,
153   - "sign_name": task.info.sign_name
154   - },
155   - function(response) {
156   - console.log(response);
157   - disableLoading();
158   - status = status_dict[$("#finish-button").text().trim()];
159   - saveAnswer(task, deferred, status);
160   - });
161   - });
162   - }
163   -
164   - function enableLoading() {
165   - $("#loading-container").show();
166   - $("#main-container").addClass("mask");
167   - }
168   -
169   - function disableLoading() {
170   - $("#loading-container").hide();
171   - $("#main-container").removeClass("mask");
172   - }
173   -
174   - function disableFinishButton() {
175   - $("#finish-button").off("click");
176   - $("#finish-button").removeClass("enabled-button");
177   - $("#finish-button").addClass("disabled-button");
178   - }
179   -
180   - function showApprovalGUI(task, deferred) {
181   - $("#upload-container").hide();
182   - $(".link-container").hide();
183   - $("#fix-button").show();
184   - $("#finish-button-text").text("APROVAR");
185   - enableFinishButton(task, deferred);
186   - }
187   -
188   - function showFixGUI() {
189   - disableFinishButton();
190   - $("#upload-container").show();
191   - $(".link-container").show();
192   - $("#finish-button-text").text("FINALIZAR");
193   - $("#fix-button").hide();
194   - }
195   -
196   - function setupButtons(task, deferred) {
197   - disableFinishButton();
198   - resetUploadProgress();
199   - $("#upload-file-name").text("Escolha um arquivo");
200   - $("#file-upload").val("");
201   - $("#file-upload").fileupload(
202   - {
203   - url : "{{ server }}/upload",
204   - formData : {
205   - "upload_session_id" : upload_session_id,
206   - 'sign_name' : task.info.sign_name
207   - },
208   - add : function(e, data) {
209   - resetUploadProgress();
210   - $("#upload-file-name").text(data.files[0].name)
211   - data.submit();
212   - },
213   - done : function(e, data) {
214   - enableFinishButton(task, deferred);
215   - },
216   - progressall : function(e, data) {
217   - //console.log(data);
218   - var progress = parseInt(data.loaded / data.total * 100,
219   - 10);
220   - $("#upload-progress .progress-bar").css("width",
221   - progress + "%");
222   - },
223   - error : function(error) {
224   - alert(error.responseText);
225   - resetUploadProgress();
226   - disableFinishButton();
227   - }
228   - });
229   -
230   - $("#upload-button").off("click").on("click", function() {
231   - $("#file-upload").click();
232   - });
233   - $("#skip-button").off("click").on("click", function() {
234   - saveAnswer(task, deferred, "SKIP");
235   - });
236   - $("#fix-button").off("click").on("click", function() {
237   - showFixGUI();
238   - });
239   - }
240   -
241   - function createAnswer(task, status) {
242   - var answer = {
243   - "status" : status,
244   - "number_of_fixes" : 0,
245   - "number_of_approval" : 0
246   - };
247   - var last_answer = task.info.last_answer;
248   - var hasLastAnswer = typeof last_answer != "undefined";
249   - if (hasLastAnswer) {
250   - answer = last_answer;
251   - }
252   - if (status == "FINISHED") {
253   - answer["last_edit_date"] = moment(new Date()).format(
254   - "YYYY-MM-DDTHH:mm:ss")
255   - answer["last_upload_session_id"] = upload_session_id;
256   - answer["number_of_fixes"] = answer.number_of_fixes + 1;
257   - } else if (status == "APPROVED") {
258   - answer["number_of_approval"] = answer.number_of_approval + 1;
259   - }
260   - return answer;
261   - }
262   -
263   - function saveAnswer(task, deferred, status) {
264   - var answer = createAnswer(task, status);
265   - pybossa.saveTask(task.id, answer).done(function() {
266   - $("#success").fadeIn(500);
267   - $("#main-container").hide();
268   - setTimeout(function() {
269   - deferred.resolve();
270   - }, 2000);
271   - });
272   - }
273   -
274   - function loadTaskInfo(task) {
275   - current_task_id = task.id;
276   - var sign_name = task.info.sign_name;
277   - var blend_link = base_url + sign_name + "_AVATAR.blend";
278   - var avatar_vid_link = base_url + sign_name + "_AVATAR.webm";
279   - var ref_vid_link = base_url + sign_name + "_REF.webm";
280   - $(".sign-label").text(sign_name);
281   - $("#submission-date").text(
282   - moment(task.info.submission_date).format("DD/MM/YYYY"));
283   - $("#avatar-video").attr("src", avatar_vid_link);
284   - $("#ref-video").attr("src", ref_vid_link);
285   - $("#ref-video-link").attr("href", ref_vid_link);
286   - $("#blend-link").attr("href", blend_link);
287   -
288   - var last_answer = task.info.last_answer;
289   - var hasLastAnswer = typeof last_answer != "undefined";
290   - if (hasLastAnswer && last_answer.status == "FINISHED") {
291   - console.log(last_answer);
292   - $("#last-edit-date").text(
293   - moment(last_answer.last_edit_date).format("DD/MM/YYYY"));
294   - $("#number-of-fixes").text(last_answer.number_of_fixes);
295   - }
296   - }
297   -
298   - pybossa.presentTask(function(task, deferred) {
299   - if (!$.isEmptyObject(task) && current_task_id != task.id) {
300   - loadTaskInfo(task);
301   - setupButtons(task, deferred);
302   - $("#success").hide();
303   - $("#main-container").fadeIn(500);
304   - var hasLastAnswer = typeof task.info.last_answer != "undefined";
305   - if (hasLastAnswer && task.info.last_answer.status == "FINISHED") {
306   - showApprovalGUI(task, deferred);
307   - }
308   - } else {
309   - $("#main-container").hide();
310   - $("#finish").fadeIn(500);
311   - }
312   - });
313   -
314   - pybossa.run('corretor_sinais');
  134 + corretor.run("{{ server }}", "{{ app_shortname }}");
315 135 </script>
... ...