diff --git a/addons/base/controllers/main.py b/addons/base/controllers/main.py index 923df69ca2d..f5384697d17 100644 --- a/addons/base/controllers/main.py +++ b/addons/base/controllers/main.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +import base64 import glob, os import pprint from xml.etree import ElementTree @@ -361,24 +362,6 @@ class DataSet(openerpweb.Controller): @openerpweb.jsonrequest def read(self, request, model, ids, fields=False): return self.do_search_read(request, model, ids, fields) - def search_read(self, request, model, ids, fields=False): - """ Performs a read() - - :param request: a JSON-RPC request object - :type request: openerpweb.JsonRequest - :param str model: the name of the model to search on - :param ids: the ids of the records - :type ids: [?] - :param fields: a list of the fields to return in the result records - :type fields: [str] - :returns: a list of result records - :rtype: list - """ - Model = request.session.model(model) - - reads = Model.read(ids, fields or False, request.context) - reads.sort(key=lambda obj: ids.index(obj['id'])) - return reads @openerpweb.jsonrequest def get(self, request, model, ids, fields=False): @@ -403,7 +386,7 @@ class DataSet(openerpweb.Controller): :rtype: list """ Model = request.session.model(model) - records = Model.read(ids, fields) + records = Model.read(ids, fields, request.context) record_map = dict((record['id'], record) for record in records) @@ -572,6 +555,48 @@ class FormView(View): fields_view = self.fields_view_get(req, model, view_id, 'form', toolbar=toolbar) return {'fields_view': fields_view} + @openerpweb.httprequest + def image(self, request, session_id, model, id, field, **kw): + cherrypy.response.headers['Content-Type'] = 'image/png' + Model = request.session.model(model) + try: + if not id: + res = Model.default_get([field], request.context).get(field, '') + else: + res = Model.read([id], [field], request.context)[0].get(field, '') + return base64.decodestring(res) + except: + return self.placeholder() + def placeholder(self): + return open(os.path.join(openerpweb.path_addons, 'base', 'static', 'src', 'img', 'placeholder.png'), 'rb').read() + + @openerpweb.httprequest + def upload(self, request, session_id, callback, ufile=None): + cherrypy.response.timeout = 500 + headers = {} + for key, val in cherrypy.request.headers.iteritems(): + headers[key.lower()] = val + size = int(headers.get('content-length', 0)) + # TODO: might be usefull to have a configuration flag for max-lenght file uploads + try: + out = """""" + data = ufile.file.read() + args = [size, ufile.filename, ufile.headers.getheader('Content-Type'), base64.encodestring(data)] + except Exception as e: + args = [False, e.message] + return out % (simplejson.dumps(callback), simplejson.dumps(args)) + class ListView(View): _cp_path = "/base/listview" diff --git a/addons/base/static/lib/json/json2.js b/addons/base/static/lib/json/json2.js new file mode 100755 index 00000000000..b4c02d3f08b --- /dev/null +++ b/addons/base/static/lib/json/json2.js @@ -0,0 +1,480 @@ +/* + http://www.JSON.org/json2.js + 2011-02-23 + + Public Domain. + + NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK. + + See http://www.JSON.org/js.html + + + This code should be minified before deployment. + See http://javascript.crockford.com/jsmin.html + + USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO + NOT CONTROL. + + + This file creates a global JSON object containing two methods: stringify + and parse. + + JSON.stringify(value, replacer, space) + value any JavaScript value, usually an object or array. + + replacer an optional parameter that determines how object + values are stringified for objects. It can be a + function or an array of strings. + + space an optional parameter that specifies the indentation + of nested structures. If it is omitted, the text will + be packed without extra whitespace. If it is a number, + it will specify the number of spaces to indent at each + level. If it is a string (such as '\t' or ' '), + it contains the characters used to indent at each level. + + This method produces a JSON text from a JavaScript value. + + When an object value is found, if the object contains a toJSON + method, its toJSON method will be called and the result will be + stringified. A toJSON method does not serialize: it returns the + value represented by the name/value pair that should be serialized, + or undefined if nothing should be serialized. The toJSON method + will be passed the key associated with the value, and this will be + bound to the value + + For example, this would serialize Dates as ISO strings. + + Date.prototype.toJSON = function (key) { + function f(n) { + // Format integers to have at least two digits. + return n < 10 ? '0' + n : n; + } + + return this.getUTCFullYear() + '-' + + f(this.getUTCMonth() + 1) + '-' + + f(this.getUTCDate()) + 'T' + + f(this.getUTCHours()) + ':' + + f(this.getUTCMinutes()) + ':' + + f(this.getUTCSeconds()) + 'Z'; + }; + + You can provide an optional replacer method. It will be passed the + key and value of each member, with this bound to the containing + object. The value that is returned from your method will be + serialized. If your method returns undefined, then the member will + be excluded from the serialization. + + If the replacer parameter is an array of strings, then it will be + used to select the members to be serialized. It filters the results + such that only members with keys listed in the replacer array are + stringified. + + Values that do not have JSON representations, such as undefined or + functions, will not be serialized. Such values in objects will be + dropped; in arrays they will be replaced with null. You can use + a replacer function to replace those with JSON values. + JSON.stringify(undefined) returns undefined. + + The optional space parameter produces a stringification of the + value that is filled with line breaks and indentation to make it + easier to read. + + If the space parameter is a non-empty string, then that string will + be used for indentation. If the space parameter is a number, then + the indentation will be that many spaces. + + Example: + + text = JSON.stringify(['e', {pluribus: 'unum'}]); + // text is '["e",{"pluribus":"unum"}]' + + + text = JSON.stringify(['e', {pluribus: 'unum'}], null, '\t'); + // text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]' + + text = JSON.stringify([new Date()], function (key, value) { + return this[key] instanceof Date ? + 'Date(' + this[key] + ')' : value; + }); + // text is '["Date(---current time---)"]' + + + JSON.parse(text, reviver) + This method parses a JSON text to produce an object or array. + It can throw a SyntaxError exception. + + The optional reviver parameter is a function that can filter and + transform the results. It receives each of the keys and values, + and its return value is used instead of the original value. + If it returns what it received, then the structure is not modified. + If it returns undefined then the member is deleted. + + Example: + + // Parse the text. Values that look like ISO date strings will + // be converted to Date objects. + + myData = JSON.parse(text, function (key, value) { + var a; + if (typeof value === 'string') { + a = +/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value); + if (a) { + return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4], + +a[5], +a[6])); + } + } + return value; + }); + + myData = JSON.parse('["Date(09/09/2001)"]', function (key, value) { + var d; + if (typeof value === 'string' && + value.slice(0, 5) === 'Date(' && + value.slice(-1) === ')') { + d = new Date(value.slice(5, -1)); + if (d) { + return d; + } + } + return value; + }); + + + This is a reference implementation. You are free to copy, modify, or + redistribute. +*/ + +/*jslint evil: true, strict: false, regexp: false */ + +/*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply, + call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours, + getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join, + lastIndex, length, parse, prototype, push, replace, slice, stringify, + test, toJSON, toString, valueOf +*/ + + +// Create a JSON object only if one does not already exist. We create the +// methods in a closure to avoid creating global variables. + +var JSON; +if (!JSON) { + JSON = {}; +} + +(function () { + "use strict"; + + function f(n) { + // Format integers to have at least two digits. + return n < 10 ? '0' + n : n; + } + + if (typeof Date.prototype.toJSON !== 'function') { + + Date.prototype.toJSON = function (key) { + + return isFinite(this.valueOf()) ? + this.getUTCFullYear() + '-' + + f(this.getUTCMonth() + 1) + '-' + + f(this.getUTCDate()) + 'T' + + f(this.getUTCHours()) + ':' + + f(this.getUTCMinutes()) + ':' + + f(this.getUTCSeconds()) + 'Z' : null; + }; + + String.prototype.toJSON = + Number.prototype.toJSON = + Boolean.prototype.toJSON = function (key) { + return this.valueOf(); + }; + } + + var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, + escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, + gap, + indent, + meta = { // table of character substitutions + '\b': '\\b', + '\t': '\\t', + '\n': '\\n', + '\f': '\\f', + '\r': '\\r', + '"' : '\\"', + '\\': '\\\\' + }, + rep; + + + function quote(string) { + +// If the string contains no control characters, no quote characters, and no +// backslash characters, then we can safely slap some quotes around it. +// Otherwise we must also replace the offending characters with safe escape +// sequences. + + escapable.lastIndex = 0; + return escapable.test(string) ? '"' + string.replace(escapable, function (a) { + var c = meta[a]; + return typeof c === 'string' ? c : + '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4); + }) + '"' : '"' + string + '"'; + } + + + function str(key, holder) { + +// Produce a string from holder[key]. + + var i, // The loop counter. + k, // The member key. + v, // The member value. + length, + mind = gap, + partial, + value = holder[key]; + +// If the value has a toJSON method, call it to obtain a replacement value. + + if (value && typeof value === 'object' && + typeof value.toJSON === 'function') { + value = value.toJSON(key); + } + +// If we were called with a replacer function, then call the replacer to +// obtain a replacement value. + + if (typeof rep === 'function') { + value = rep.call(holder, key, value); + } + +// What happens next depends on the value's type. + + switch (typeof value) { + case 'string': + return quote(value); + + case 'number': + +// JSON numbers must be finite. Encode non-finite numbers as null. + + return isFinite(value) ? String(value) : 'null'; + + case 'boolean': + case 'null': + +// If the value is a boolean or null, convert it to a string. Note: +// typeof null does not produce 'null'. The case is included here in +// the remote chance that this gets fixed someday. + + return String(value); + +// If the type is 'object', we might be dealing with an object or an array or +// null. + + case 'object': + +// Due to a specification blunder in ECMAScript, typeof null is 'object', +// so watch out for that case. + + if (!value) { + return 'null'; + } + +// Make an array to hold the partial results of stringifying this object value. + + gap += indent; + partial = []; + +// Is the value an array? + + if (Object.prototype.toString.apply(value) === '[object Array]') { + +// The value is an array. Stringify every element. Use null as a placeholder +// for non-JSON values. + + length = value.length; + for (i = 0; i < length; i += 1) { + partial[i] = str(i, value) || 'null'; + } + +// Join all of the elements together, separated with commas, and wrap them in +// brackets. + + v = partial.length === 0 ? '[]' : gap ? + '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']' : + '[' + partial.join(',') + ']'; + gap = mind; + return v; + } + +// If the replacer is an array, use it to select the members to be stringified. + + if (rep && typeof rep === 'object') { + length = rep.length; + for (i = 0; i < length; i += 1) { + if (typeof rep[i] === 'string') { + k = rep[i]; + v = str(k, value); + if (v) { + partial.push(quote(k) + (gap ? ': ' : ':') + v); + } + } + } + } else { + +// Otherwise, iterate through all of the keys in the object. + + for (k in value) { + if (Object.prototype.hasOwnProperty.call(value, k)) { + v = str(k, value); + if (v) { + partial.push(quote(k) + (gap ? ': ' : ':') + v); + } + } + } + } + +// Join all of the member texts together, separated with commas, +// and wrap them in braces. + + v = partial.length === 0 ? '{}' : gap ? + '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}' : + '{' + partial.join(',') + '}'; + gap = mind; + return v; + } + } + +// If the JSON object does not yet have a stringify method, give it one. + + if (typeof JSON.stringify !== 'function') { + JSON.stringify = function (value, replacer, space) { + +// The stringify method takes a value and an optional replacer, and an optional +// space parameter, and returns a JSON text. The replacer can be a function +// that can replace values, or an array of strings that will select the keys. +// A default replacer method can be provided. Use of the space parameter can +// produce text that is more easily readable. + + var i; + gap = ''; + indent = ''; + +// If the space parameter is a number, make an indent string containing that +// many spaces. + + if (typeof space === 'number') { + for (i = 0; i < space; i += 1) { + indent += ' '; + } + +// If the space parameter is a string, it will be used as the indent string. + + } else if (typeof space === 'string') { + indent = space; + } + +// If there is a replacer, it must be a function or an array. +// Otherwise, throw an error. + + rep = replacer; + if (replacer && typeof replacer !== 'function' && + (typeof replacer !== 'object' || + typeof replacer.length !== 'number')) { + throw new Error('JSON.stringify'); + } + +// Make a fake root object containing our value under the key of ''. +// Return the result of stringifying the value. + + return str('', {'': value}); + }; + } + + +// If the JSON object does not yet have a parse method, give it one. + + if (typeof JSON.parse !== 'function') { + JSON.parse = function (text, reviver) { + +// The parse method takes a text and an optional reviver function, and returns +// a JavaScript value if the text is a valid JSON text. + + var j; + + function walk(holder, key) { + +// The walk method is used to recursively walk the resulting structure so +// that modifications can be made. + + var k, v, value = holder[key]; + if (value && typeof value === 'object') { + for (k in value) { + if (Object.prototype.hasOwnProperty.call(value, k)) { + v = walk(value, k); + if (v !== undefined) { + value[k] = v; + } else { + delete value[k]; + } + } + } + } + return reviver.call(holder, key, value); + } + + +// Parsing happens in four stages. In the first stage, we replace certain +// Unicode characters with escape sequences. JavaScript handles many characters +// incorrectly, either silently deleting them, or treating them as line endings. + + text = String(text); + cx.lastIndex = 0; + if (cx.test(text)) { + text = text.replace(cx, function (a) { + return '\\u' + + ('0000' + a.charCodeAt(0).toString(16)).slice(-4); + }); + } + +// In the second stage, we run the text against regular expressions that look +// for non-JSON patterns. We are especially concerned with '()' and 'new' +// because they can cause invocation, and '=' because it can cause mutation. +// But just to be safe, we want to reject all unexpected forms. + +// We split the second stage into 4 regexp operations in order to work around +// crippling inefficiencies in IE's and Safari's regexp engines. First we +// replace the JSON backslash pairs with '@' (a non-JSON character). Second, we +// replace all simple value tokens with ']' characters. Third, we delete all +// open brackets that follow a colon or comma or that begin the text. Finally, +// we look to see that the remaining characters are only whitespace or ']' or +// ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval. + + if (/^[\],:{}\s]*$/ + .test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@') + .replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']') + .replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) { + +// In the third stage we use the eval function to compile the text into a +// JavaScript structure. The '{' operator is subject to a syntactic ambiguity +// in JavaScript: it can begin a block or an object literal. We wrap the text +// in parens to eliminate the ambiguity. + + j = eval('(' + text + ')'); + +// In the optional fourth stage, we recursively walk the new structure, passing +// each name/value pair to a reviver function for possible transformation. + + return typeof reviver === 'function' ? + walk({'': j}, '') : j; + } + +// If the text is not JSON parseable, then a SyntaxError is thrown. + + throw new SyntaxError('JSON.parse'); + }; + } +}()); diff --git a/addons/base/static/lib/qweb/qweb2.js b/addons/base/static/lib/qweb/qweb2.js index b37a38e9c38..e113ddc7c80 100644 --- a/addons/base/static/lib/qweb/qweb2.js +++ b/addons/base/static/lib/qweb/qweb2.js @@ -1,4 +1,5 @@ // TODO: trim support +// TODO: line number -> https://bugzilla.mozilla.org/show_bug.cgi?id=618650 var QWeb2 = { expressions_cache: {}, reserved_words: 'true,false,NaN,null,undefined,debugger,in,instanceof,new,function,return,this,typeof,eval,Math,RegExp,Array,Object'.split(','), @@ -295,8 +296,7 @@ QWeb2.Engine = (function() { compile : function(node) { var e = new QWeb2.Element(this, node); var template = node.getAttribute(this.prefix + '-name'); - return "(function(dict) {\n" + - " /* 'this' refers to Qweb2.Engine instance */\n" + + return " /* 'this' refers to Qweb2.Engine instance */\n" + " var context = { engine : this, template : " + (this.tools.js_escape(template)) + " };\n" + " dict = dict || {};\n" + " dict['__template__'] = '" + template + "';\n" + @@ -306,8 +306,7 @@ QWeb2.Engine = (function() { " /* END OF TEMPLATE */ } catch(error) {\n" + " context.engine.tools.exception('Runtime Error: ' + error, context);\n" + " }\n" + - " return r.join('');\n" + - "});"; + " return r.join('');"; }, render : function(template, dict) { if (this.debug && window['console'] !== undefined) { @@ -332,12 +331,16 @@ QWeb2.Engine = (function() { } var code = this.compile(this.templates[template]), tcompiled; try { - // tcompiled = new Function(code); TODO: Check if could use this in order to avoid eval - tcompiled = eval(code); + tcompiled = new Function(['dict'], code); } catch (error) { - console.log(code); + if (this.debug && window.console) { + console.log(code); + } this.tools.exception("Error evaluating template: " + error, { template: name }); } + if (!tcompiled) { + this.tools.exception("Error evaluating template: (IE?)" + error, { template: name }); + } this.compiled_templates[template] = tcompiled; return this.render(template, dict); } else { diff --git a/addons/base/static/src/base.html b/addons/base/static/src/base.html index 39909413397..314422d826b 100644 --- a/addons/base/static/src/base.html +++ b/addons/base/static/src/base.html @@ -20,6 +20,7 @@ + @@ -35,6 +36,9 @@ + - - - - - - - - -
Choose dashboard layout
-| ').append(
- jQuery(' ')
- .append(
- jQuery('',
- {
- 'type': 'checkbox',
- 'id':sidebar[s][0],
- 'value':sidebar[s][0]
- }).bind('click',function(){
- self.reload_gantt(self.color_field,self.model)
- }),
- sidebar[s][1]
- )
- .css('background-color',sidebar[s][sidebar[s].length-1])
- )
- )
- )
+ },
+
+ get_events: function() {
+
+ var self = this;
+ this.dataset.read_ids(this.dataset.ids, {}, function(result) {
+ self.load_event(result);
+ });
+
+ },
+
+ load_event: function(events) {
+
+ var self = this;
+
+ var result = events;
+ var project = {};
+ var project_smalldate = {};
+ var proj_id = [];
+ var proj_id_text = [];
+
+ COLOR_PALETTE = ['#ccccff', '#cc99ff', '#75507b', '#3465a4', '#73d216', '#c17d11', '#edd400',
+ '#fcaf3e', '#ef2929', '#ff00c9', '#ad7fa8', '#729fcf', '#8ae234', '#e9b96e', '#fce94f',
+ '#ff8e00', '#ff0000', '#b0008c', '#9000ff', '#0078ff', '#00ff00', '#e6ff00', '#ffff00',
+ '#905000', '#9b0000', '#840067', '#510090', '#0000c9', '#009b00', '#9abe00', '#ffc900']
+
+ //Smallest date of child is parent start date
+ for (i in result){
+ var res = result[i];
+
+ if (res[this.date_start] != false){
+
+ var parent_id = res[this.parent][0] || res[this.parent];
+ var parent_name = res[this.parent][1];
+ var start_date = this.convert_str_date(res[this.date_start]);
+
+ if (project_smalldate[parent_id] == undefined){
+ project_smalldate[parent_id] = start_date;
+ proj_id.push(parent_id);
+
+ if (parent_name != undefined){
+ proj_id_text.push(res[this.parent]);
+ }
+ }
+ else{
+ if (start_date < project_smalldate[parent_id]){
+ project_smalldate[parent_id] = start_date;
+ }
+ }
+
}
}
+
+ //get parent text
+ if (parent_name == undefined){
+
+ var ajax = {
+ url: '/base/dataset/call',
+ async: false
+ };
+
+ this.rpc(ajax, {
+ model: this.dataset.model,
+ method: "name_get",
+ ids: proj_id,
+ args: ""
+ }, function(response) {
+ proj_id_text = response.result;
+
+ });
+ }
+
+ //create parents
+ for (i in proj_id){
+
+ var id = proj_id_text[i][0];
+ var text = proj_id_text[i][1];
+
+ project[id] = new GanttProjectInfo(id, text, project_smalldate[id]);
+ }
+
+ //create childs
+ var k = 0;
+ var color_box = {};
+ for (i in result) {
+
+ var res = result[i];
+ if (res[this.date_start] != false){
+
+ var parent_id = res[this.parent][0] || res[this.parent];
+ var id = res['id'];
+ var text = res[this.text];
+
+ var start_date = this.convert_str_date(res[this.date_start]);
+
+ var color = res[this.color_field][0] || res[this.color_field];
+ if (color_box[color] == undefined){
+ color_box[color] = COLOR_PALETTE[k];
+ k = k + 1;
+ }
+
+ if (this.date_stop != undefined){
+ if (res[this.date_stop] != false){
+ var stop_date = this.convert_str_date(res[this.date_stop]);
+ var duration= self.hours_between(start_date, stop_date);
+ }
+ else{
+ var duration = 0;
+ }
+ }
+ else{
+ var duration = res[this.date_delay];
+ }
+ if (duration == false)
+ duration = 0
+ task = new GanttTaskInfo(id, text, start_date, duration, 100, "", color_box[color]);
+ project[parent_id].addTask(task);
+
+ }
+ }
+
+ //Add parent
+ for (i in proj_id){
+ ganttChartControl.addProject(project[proj_id[i]]);
+ }
+
+ ganttChartControl.create("GanttDiv");
+ ganttChartControl.attachEvent("onTaskStartDrag", function(task) {self.on_drag_start(task);});
+ ganttChartControl.attachEvent("onTaskEndResize", function(task) {self.on_resize_drag_end(task, "resize");});
+ ganttChartControl.attachEvent("onTaskEndDrag", function(task) {self.on_resize_drag_end(task, "drag");});
+ ganttChartControl.attachEvent("onTaskDblClick", function(task) {self.open_popup(task);});
+
},
- reload_gantt: function(color_field, model) {
- var domain = [];
+
+ hours_between: function(date1, date2) {
+
+ var ONE_DAY = 1000 * 60 * 60 * 24;
+ var date1_ms = date1.getTime();
+ var date2_ms = date2.getTime();
+ var difference_ms = Math.abs(date1_ms - date2_ms);
+
+ d = Math.round(difference_ms / ONE_DAY);
+ h = Math.round((difference_ms % ONE_DAY)/(1000 * 60 * 60));
+
+ return (d * this.day_length) + h;
+
+ },
+
+ open_popup : function(task) {
+ var event_id = task.getId();
+ if (event_id) {
+ event_id = parseInt(event_id, 10);
+ var dataset_event_index = jQuery.inArray(event_id, this.ids);
+ } else {
+ var dataset_event_index = null;
+ }
+ this.dataset.index = dataset_event_index;
+ var element_id = _.uniqueId("act_window_dialog");
+ var dialog = jQuery(' ',
+ {'id': element_id
+ }).dialog({
+ title: 'Gantt Chart',
+ modal: true,
+ minWidth: 800,
+ position: 'top'
+ });
+ var event_form = new openerp.base.FormView(this.view_manager, this.session, element_id, this.dataset, false);
+ event_form.start();
+ },
+
+ on_drag_start : function(task){
+ st_date = task.getEST();
+ if(st_date.getHours()){
+ self.hh = st_date.getHours();
+ self.mm = st_date.getMinutes();
+ }
+ },
+
+ on_resize_drag_end : function(task, evt){
+
+ var event_id = task.getId();
+ var data = {};
+
+ if (evt == "drag"){
+ full_date = task.getEST().set({hour: self.hh, minute : self.mm, second:0});
+ data[this.date_start] = this.convert_date_str(full_date);
+ }
+ if (this.date_stop != undefined){
+ tm = (task.getDuration() % this.day_length);
+ stp = task.getFinishDate().add(tm).hour();
+ data[this.date_stop] = this.convert_date_str(stp);
+ }else{
+ data[this.date_delay] = task.getDuration();
+ }
+ this.dataset.write(event_id, data, function(result) {});
+
+ },
+
+ do_show: function () {
+ this.$element.show();
+ },
+
+ do_hide: function () {
+ this.$element.hide();
+ },
+
+ convert_str_date: function (str){
+ if (str.length == 19){
+ this.format = "yyyy-MM-dd HH:mm:ss";
+ return openerp.base.parse_datetime(str);
+ } else if (str.length == 10){
+ this.format = "yyyy-MM-dd";
+ return openerp.base.parse_date(str);
+ } else if (str.length == 8){
+ this.format = "HH:mm:ss";
+ return openerp.base.parse_time(str);
+ }
+ throw "Unrecognized date/time format";
+ },
+
+ convert_date_str: function(full_date) {
+ if (this.format == "yyyy-MM-dd HH:mm:ss"){
+ return openerp.base.format_datetime(full_date);
+ } else if (this.format == "yyyy-MM-dd"){
+ return openerp.base.format_date(full_date);
+ } else if (this.format == "HH:mm:ss"){
+ return openerp.base.format_time(full_date);
+ }
+ throw "Unrecognized date/time format";
+ },
+
+ reload_gantt: function(domain) {
var self = this;
- jQuery('input[type=checkbox]:checked','#cal-sidebar-option').each(function() {
- domain.push(parseInt(jQuery(this).attr('id')))
+ var ajax = {
+ url: '/base/dataset/search_read',
+ async: false
+ };
+ this.rpc(ajax, {
+ model: this.dataset.model,
+ domain: self.dataset.domain,
+ context :self.dataset.context
+ }, function(response) {
+ ganttChartControl.clearAll();
+ jQuery("#GanttDiv").children().remove();
+ self.load_event(response);
+ });
+ },
+
+ do_search: function (domains, contexts, groupbys) {
+
+ var self = this;
+
+ return this.rpc('/base/session/eval_domain_and_context', {
+ domains: domains,
+ contexts: contexts,
+ group_by_seq: groupbys
+ }, function (results) {
+ self.dataset.context = results.context;
+ self.dataset.domain = results.domain;
+ return self.reload_gantt(self.dataset.domain);
});
- this.rpc('/base_gantt/ganttview/reload_gantt',{
- 'domain':domain,
- 'color_field':color_field,
- 'model': model
- },function(res) {
- ganttChartControl.clearAll();
- jQuery("#GanttDiv").children().remove();
- self.load_event(res);
- });
- },
- reverse_convert_date_format: function(date) {
- return date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate();
- },
-
- on_task_end_resize : function(task) {
- this.rpc('/base_gantt/ganttview/on_event_resize',
- {'id' : task.getId(),
- 'end_date' : this.reverse_convert_date_format(task.getFinishDate()),
- 'duration' : task.getDuration()
- },
- function(result) {
- })
- },
- on_task_end_drag : function(task) {
- this.rpc('/base_gantt/ganttview/on_event_drag',
- {'id' : task.getId(),
- 'start_date' : this.reverse_convert_date_format(task.getEST()),
- 'end_date' : this.reverse_convert_date_format(task.getFinishDate()),
- 'duration' : task.getDuration()
- },
- function(result) {
- })
}
});
@@ -224,5 +344,4 @@ openerp.base_gantt.GanttView = openerp.base.Controller.extend({
// here you may tweak globals object, if any, and play with on_* or do_* callbacks on them
};
-
// vim:et fdc=0 fdl=0:
diff --git a/addons/base_gantt/static/src/xml/base_gantt.xml b/addons/base_gantt/static/src/xml/base_gantt.xml
index 72c14ceb16c..c85abf0cad8 100644
--- a/addons/base_gantt/static/src/xml/base_gantt.xml
+++ b/addons/base_gantt/static/src/xml/base_gantt.xml
@@ -3,12 +3,9 @@
|