/*# encoding: utf-8
##############################################################################
#
#     patch for download preview
#     Copyright (C) 2014  zkjiao@gmail.com
# 
#     This program is free software: you can redistribute it and/or modify
#     it under the terms of the GNU Affero General Public License as
#     published by the Free Software Foundation, either version 3 of the
#     License, or (at your option) any later version.
# 
#     This program is distributed in the hope that it will be useful,
#     but WITHOUT ANY WARRANTY; without even the implied warranty of
#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#     GNU Affero General Public License for more details.
# 
#     You should have received a copy of the GNU Affero General Public License
#     along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################*/
openerp.patch_download_preview = function(instance) {
	var _t = instance.web._t, _lt = instance.web._lt;
	var QWeb = instance.web.qweb;

	instance.web.Session.include({
		get_file : function(options) {
			return this.open_preview(options);
		},
		open_preview : function(options) {
			var token = new Date().getTime();
			var id = _.uniqueId('get_file_frame');

			var params = _.extend({}, options.data || {}, {
				token : token
			});
			var url = this.url(options.url, params);
			// iOS devices doesn't allow iframe use the way we do it,
			// opening a new window seems the best way to workaround
			if (navigator.userAgent.match(/(iPod|iPhone|iPad)/)) {
				instance.web.unblockUI();
				return window.open(url);
			}
			$preview = $(QWeb.render('PreviewWidget', {
				title : _lt("Preview"),
				url : url,
				id : id,
				name : id
			})).appendTo(document.body);
			$preview.find("iframe").load(function() {
				$preview.find(".preview_header").show();
				if (options.success) {
					options.success();
				}
				if (options.complete) {
					options.complete();
				}
			});
			$preview.on('hidden.bs.modal', this, function() {
				$preview.remove();
			});
			$preview.modal({
				'backdrop' : false,
			});
			$preview.modal('show');
			return;
		}
	});
};
@@ -1864,32 +1864,527 @@
 ad(function() %7B%0A
+%09%09%09%09var body = this.contentDocument.body;%0A%09%09%09%09if (body.innerText)%7B%0A%09%09%09%09%09try %7B%0A%09                    if (options.error) %7B%09                        %0A%09                        var node = body.childNodes%5B1%5D %7C%7C body.childNodes%5B0%5D;%0A%09                        options.error(JSON.parse(node.textContent));%0A%09                    %7D%0A%09                %7D finally %7B%0A%09                %09if (options.complete) %7B%0A%09%09%09%09%09%09%09options.complete();%0A%09%09%09%09%09%09%7D%0A%09                %09$preview.remove();%0A%09                %7D%0A%09%09%09%09%7D%0A%09%09%09%09else%7B%0A%09
 %09%09%09%09$preview.fin
@@ -2408,24 +2408,25 @@
 r%22).show();%0A
+%09
 %09%09%09%09if (opti
@@ -2437,32 +2437,33 @@
 success) %7B%0A%09%09%09%09%09
+%09
 options.success(
@@ -2461,24 +2461,25 @@
 .success();%0A
+%09
 %09%09%09%09%7D%0A%09%09%09%09if
@@ -2472,24 +2472,25 @@
 %0A%09%09%09%09%09%7D%0A%09%09%09%09
+%09
 if (options.
@@ -2497,24 +2497,25 @@
 complete) %7B%0A
+%09
 %09%09%09%09%09options
@@ -2523,24 +2523,31 @@
 complete();%0A
+%09%09%09%09%09%7D%0A
 %09%09%09%09%7D%0A%09%09%09%7D);

fix error process