mirror of
https://github.com/OCA/knowledge.git
synced 2025-12-23 05:42:13 -06:00
[ADD] port document_choose_directory
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
.openerp .oe_sidebar .oe_dropdown_menu .oe_sidebar_add_attachment .oe_hidden_input_file,
|
||||
.oe_sidebar_add_attachment .oe_form_binary_form
|
||||
{
|
||||
width: 100%;
|
||||
}
|
||||
.oe_sidebar_add_attachment .oe_form_binary_form select
|
||||
{
|
||||
display: block;
|
||||
min-width: 100%;
|
||||
}
|
||||
.openerp .oe_sidebar_add_attachment .oe_hidden_input_file input.oe_form_binary_file
|
||||
{
|
||||
top: 2em;
|
||||
}
|
||||
.openerp .oe_sidebar .oe_dropdown_menu .oe_sidebar_add_attachment
|
||||
{
|
||||
height: 3.5em;
|
||||
}
|
||||
li.oe_attachment_directory
|
||||
{
|
||||
font-weight: bold;
|
||||
}
|
||||
.openerp .oe_dropdown_menu > li.oe_attachment_directory:hover
|
||||
{
|
||||
background-color: inherit;
|
||||
background-image: inherit;
|
||||
box-shadow: none;
|
||||
}
|
||||
.openerp .oe_dropdown_menu > li.oe_attachment_directory a:hover
|
||||
{
|
||||
cursor: default !important;
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
//-*- coding: utf-8 -*-
|
||||
//############################################################################
|
||||
//
|
||||
// OpenERP, Open Source Management Solution
|
||||
// This module copyright (C) 2014 Therp BV (<http://therp.nl>).
|
||||
//
|
||||
// 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.document_choose_directory = function(instance)
|
||||
{
|
||||
instance.web.Sidebar.include(
|
||||
{
|
||||
init: function()
|
||||
{
|
||||
this._super.apply(this, arguments);
|
||||
this.directory_candidates = [];
|
||||
},
|
||||
do_attachement_update: function(dataset, model_id, args)
|
||||
{
|
||||
var document_folder = new instance.web.Model(
|
||||
'document.directory', dataset.get_context()),
|
||||
self = this,
|
||||
_super = this._super;
|
||||
return document_folder.call(
|
||||
'get_candidates_for_resource', [dataset.model, model_id])
|
||||
.then(function(records)
|
||||
{
|
||||
self.directory_candidates = records;
|
||||
self.$el.on(
|
||||
//suppress html's onclick event that would close the
|
||||
//menu
|
||||
'click', 'select[name="directory_id"]',
|
||||
function(e) {e.stopPropagation()});
|
||||
})
|
||||
.then(function()
|
||||
{
|
||||
_super.apply(self, [dataset, model_id, args]);
|
||||
});
|
||||
},
|
||||
on_attachments_loaded: function(attachments)
|
||||
{
|
||||
var attachments_per_directory = [];
|
||||
_.chain(attachments)
|
||||
.groupBy(
|
||||
function(a) { return a.parent_id[0] })
|
||||
.each(
|
||||
function(group)
|
||||
{
|
||||
attachments_per_directory.push({
|
||||
name: _.first(group).parent_id[1] ||
|
||||
instance.web._t('No directory'),
|
||||
classname: 'oe_attachment_directory',
|
||||
});
|
||||
_(group).each(function(a)
|
||||
{
|
||||
attachments_per_directory.push(a);
|
||||
});
|
||||
});
|
||||
|
||||
return this._super(attachments_per_directory);
|
||||
},
|
||||
get_directory_items: function(items)
|
||||
{
|
||||
return _(items).filter(
|
||||
function(i)
|
||||
{
|
||||
return i.classname == 'oe_attachment_directory';
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<templates>
|
||||
<t t-extend="Sidebar">
|
||||
<t t-jquery=".oe_sidebar_add_attachment span" t-operation="before">
|
||||
<select name="directory_id">
|
||||
<option value="" selected="selected">Choose directory</option>
|
||||
<option t-foreach="widget.directory_candidates" t-as="directory" t-att-value="directory.id">
|
||||
<t t-esc="directory.name" />
|
||||
</option>
|
||||
</select>
|
||||
</t>
|
||||
<t t-jquery=".oe_sidebar_delete_item">
|
||||
this.attr('t-if', "section.name == 'files' and !item.callback and item.classname != 'oe_attachment_directory'");
|
||||
</t>
|
||||
<t t-jquery="button.oe_dropdown_toggle t[t-if]">
|
||||
this.attr('t-raw', "(widget.items[section.name].length - widget.get_directory_items(widget.items[section.name]).length) || ''");
|
||||
</t>
|
||||
</t>
|
||||
</templates>
|
||||
Reference in New Issue
Block a user