Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Coopdevs OCB mirror
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Coopdevs
Odoo
Coopdevs OCB mirror
Commits
519b0350
Commit
519b0350
authored
13 years ago
by
Antony Lesuisse
Browse files
Options
Downloads
Patches
Plain Diff
[IMP] more controller cleanups
bzr revid: al@openerp.com-20110722112108-2p57tmro0l05floq
parent
d844fd13
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
addons/base/static/src/js/chrome.js
+109
-140
109 additions, 140 deletions
addons/base/static/src/js/chrome.js
addons/base/static/src/js/controller.js
+35
-12
35 additions, 12 deletions
addons/base/static/src/js/controller.js
with
144 additions
and
152 deletions
addons/base/static/src/js/chrome.js
+
109
−
140
View file @
519b0350
...
...
@@ -137,57 +137,109 @@ openerp.base.Registry = openerp.base.Class.extend( /** @lends openerp.base.Regis
});
/**
* Generates an inherited class that replaces all the methods by null methods (methods
* that does nothing and always return undefined).
*
* @param {Class} claz
* @param {dict} add Additional functions to override.
* @return {Class}
* OpenERP session aware controller
* a controller takes an already existing dom element and manage it
*/
openerp
.
base
.
generate_null_object_class
=
function
(
claz
,
add
)
{
var
newer
=
{};
var
copy_proto
=
function
(
prototype
)
{
for
(
var
name
in
prototype
)
{
if
(
typeof
prototype
[
name
]
==
"
function
"
)
{
newer
[
name
]
=
function
()
{};
}
}
if
(
prototype
.
prototype
)
copy_proto
(
prototype
.
prototype
);
};
copy_proto
(
claz
.
prototype
);
newer
.
init
=
openerp
.
base
.
BasicController
.
prototype
.
init
;
var
tmpclass
=
claz
.
extend
(
newer
);
return
tmpclass
.
extend
(
add
||
{});
};
openerp
.
base
.
Notification
=
openerp
.
base
.
BasicController
.
extend
({
openerp
.
base
.
Controller
=
openerp
.
base
.
Controller
.
extend
(
/** @lends openerp.base.Controller# */
{
init
:
function
(
parent
,
element_id
)
{
this
.
_super
(
parent
,
element_id
);
this
.
$element
.
notify
({
speed
:
500
,
expires
:
1500
});
if
(
this
.
controller_parent
&&
this
.
controller_parent
.
session
)
{
this
.
session
=
this
.
controller_parent
.
session
;
}
},
notify
:
function
(
title
,
text
)
{
this
.
$element
.
notify
(
'
create
'
,
{
title
:
title
,
text
:
text
});
/**
* Performs a JSON-RPC call
*
* @param {String} url endpoint url
* @param {Object} data RPC parameters
* @param {Function} success RPC call success callback
* @param {Function} error RPC call error callback
* @returns {jQuery.Deferred} deferred object for the RPC call
*/
rpc
:
function
(
url
,
data
,
success
,
error
)
{
return
this
.
session
.
rpc
(
url
,
data
,
success
,
error
);
},
warn
:
function
(
title
,
text
)
{
this
.
$element
.
notify
(
'
create
'
,
'
oe_notification_alert
'
,
{
title
:
title
,
text
:
text
});
do_action
:
function
(
action
,
on_finished
)
{
return
this
.
parent
.
do_action
(
action
,
on_finished
);
}
});
// Session should be a Class not Controller
openerp
.
base
.
Session
=
openerp
.
base
.
BasicController
.
extend
(
/** @lends openerp.base.Session# */
{
/**
* OpenERP session aware widget
* A widget is a controller that doesnt take an element_id
* it render its own html render() that you should insert into the dom
* and bind it at start()
*/
openerp
.
base
.
BaseWidget
=
openerp
.
base
.
Controller
.
extend
({
/**
* The name of the QWeb template that will be used for rendering. Must be
* redefined in subclasses or the render() method can not be used.
*
* @type string
*/
template
:
null
,
/**
* The prefix used to generate an id automatically. Should be redefined in
* subclasses. If it is not defined, a default identifier will be used.
*
* @type string
*/
identifier_prefix
:
'
generic-identifier
'
,
/**
* Base class for widgets. Handle rendering (based on a QWeb template),
* identifier generation, parenting and destruction of the widget.
* Also initialize the identifier.
*
* @constructs
* @params {openerp.base.search.BaseWidget} parent The parent widget.
*/
init
:
function
(
parent
)
{
this
.
_super
(
parent
);
this
.
make_id
(
this
.
identifier_prefix
);
},
/**
* Sets and returns a globally unique identifier for the widget.
*
* If a prefix is appended, the identifier will be appended to it.
*
* @params sections prefix sections, empty/falsy sections will be removed
*/
make_id
:
function
()
{
this
.
element_id
=
_
.
uniqueId
(
_
.
toArray
(
arguments
).
join
(
'
_
'
));
return
this
.
element_id
;
},
/**
* Render the widget. This.template must be defined.
* The content of the current object is passed as context to the template.
*
* @param {object} additional Additional context arguments to pass to the template.
*/
render
:
function
(
additional
)
{
return
QWeb
.
render
(
this
.
template
,
_
.
extend
({},
this
,
additional
!=
null
?
additional
:
{}));
},
/**
* "Starts" the widgets. Called at the end of the rendering, this allows
* to get a jQuery object referring to the DOM ($element attribute).
*/
start
:
function
()
{
this
.
_super
();
var
tmp
=
document
.
getElementById
(
this
.
element_id
);
this
.
$element
=
tmp
?
$
(
tmp
)
:
null
;
},
/**
* "Stops" the widgets. Called when the view destroys itself, this
* lets the widgets clean up after themselves.
*/
stop
:
function
()
{
if
(
this
.
$element
!=
null
)
{
this
.
$element
.
remove
();
}
}
});
openerp
.
base
.
Session
=
openerp
.
base
.
Controller
.
extend
(
/** @lends openerp.base.Session# */
{
/**
* @constructs
* @extends openerp.base.BasicController
* @param element_id to use for exception reporting
* @param server
* @param port
...
...
@@ -441,108 +493,25 @@ openerp.base.Session = openerp.base.BasicController.extend( /** @lends openerp.b
}
});
/**
* OpenERP session aware controller
* a controller takes an already existing dom element and manage it
*/
openerp
.
base
.
Controller
=
openerp
.
base
.
BasicController
.
extend
(
/** @lends openerp.base.Controller# */
{
/**
* @constructs
* @extends openerp.base.BasicController
*/
openerp
.
base
.
Notification
=
openerp
.
base
.
Controller
.
extend
({
init
:
function
(
parent
,
element_id
)
{
this
.
_super
(
parent
,
element_id
);
if
(
this
.
parent
&&
this
.
parent
.
session
)
{
this
.
session
=
this
.
parent
.
session
;
}
},
/**
* Performs a JSON-RPC call
*
* @param {String} url endpoint url
* @param {Object} data RPC parameters
* @param {Function} success RPC call success callback
* @param {Function} error RPC call error callback
* @returns {jQuery.Deferred} deferred object for the RPC call
*/
rpc
:
function
(
url
,
data
,
success
,
error
)
{
return
this
.
session
.
rpc
(
url
,
data
,
success
,
error
);
},
do_action
:
function
(
action
,
on_finished
)
{
return
this
.
parent
.
do_action
(
action
,
on_finished
);
}
});
/**
* OpenERP session aware widget
* A widget is a controller that doesnt take an element_id
* it render its own html render() that you should insert into the dom
* and bind it a start()
*/
openerp
.
base
.
BaseWidget
=
openerp
.
base
.
Controller
.
extend
({
/**
* The name of the QWeb template that will be used for rendering. Must be
* redefined in subclasses or the render() method can not be used.
*
* @type string
*/
template
:
null
,
/**
* The prefix used to generate an id automatically. Should be redefined in
* subclasses. If it is not defined, a default identifier will be used.
*
* @type string
*/
identifier_prefix
:
'
generic-identifier
'
,
/**
* Base class for widgets. Handle rendering (based on a QWeb template),
* identifier generation, parenting and destruction of the widget.
* Also initialize the identifier.
*
* @constructs
* @params {openerp.base.search.BaseWidget} parent The parent widget.
*/
init
:
function
(
parent
)
{
this
.
_super
(
parent
);
this
.
make_id
(
this
.
identifier_prefix
);
},
/**
* Sets and returns a globally unique identifier for the widget.
*
* If a prefix is appended, the identifier will be appended to it.
*
* @params sections prefix sections, empty/falsy sections will be removed
*/
make_id
:
function
()
{
this
.
element_id
=
_
.
uniqueId
(
_
.
toArray
(
arguments
).
join
(
'
_
'
));
return
this
.
element_id
;
},
/**
* "Starts" the widgets. Called at the end of the rendering, this allows
* to get a jQuery object referring to the DOM ($element attribute).
*/
start
:
function
()
{
this
.
_super
();
var
tmp
=
document
.
getElementById
(
this
.
element_id
);
this
.
$element
=
tmp
?
$
(
tmp
)
:
null
;
this
.
$element
.
notify
({
speed
:
500
,
expires
:
1500
});
},
/**
* "Stops" the widgets. Called when the view destroys itself, this
* lets the widgets clean up after themselves.
*/
stop
:
function
()
{
if
(
this
.
$element
!=
null
)
{
this
.
$element
.
remove
();
}
notify
:
function
(
title
,
text
)
{
this
.
$element
.
notify
(
'
create
'
,
{
title
:
title
,
text
:
text
});
},
/**
* Render the widget. This.template must be defined.
* The content of the current object is passed as context to the template.
*
* @param {object} additional Additional context arguments to pass to the template.
*/
render
:
function
(
additional
)
{
return
QWeb
.
render
(
this
.
template
,
_
.
extend
({},
this
,
additional
!=
null
?
additional
:
{}));
warn
:
function
(
title
,
text
)
{
this
.
$element
.
notify
(
'
create
'
,
'
oe_notification_alert
'
,
{
title
:
title
,
text
:
text
});
}
});
...
...
@@ -888,7 +857,7 @@ openerp.base.WebClient = openerp.base.Controller.extend({
this
.
crashmanager
=
new
openerp
.
base
.
CrashManager
(
this
);
this
.
crashmanager
.
start
(
false
);
// Do you autorize this ?
// Do you autorize this ?
will be replaced by notify() in controller
openerp
.
base
.
Controller
.
prototype
.
notification
=
new
openerp
.
base
.
Notification
(
this
,
"
oe_notification
"
);
this
.
header
=
new
openerp
.
base
.
Header
(
this
,
"
oe_header
"
);
...
...
This diff is collapsed.
Click to expand it.
addons/base/static/src/js/controller.js
+
35
−
12
View file @
519b0350
...
...
@@ -66,7 +66,7 @@ openerp.base.controller = function(instance) {
return
Class
;
};
})(
instance
.
base
);
})();
// todo change john resig class to keep window clean
instance
.
base
.
Class
=
window
.
Class
...
...
@@ -120,15 +120,40 @@ instance.base.callback = function(obj, method) {
});
};
/**
* Generates an inherited class that replaces all the methods by null methods (methods
* that does nothing and always return undefined).
*
* @param {Class} claz
* @param {dict} add Additional functions to override.
* @return {Class}
*/
instance
.
base
.
generate_null_object_class
=
function
(
claz
,
add
)
{
var
newer
=
{};
var
copy_proto
=
function
(
prototype
)
{
for
(
var
name
in
prototype
)
{
if
(
typeof
prototype
[
name
]
==
"
function
"
)
{
newer
[
name
]
=
function
()
{};
}
}
if
(
prototype
.
prototype
)
copy_proto
(
prototype
.
prototype
);
};
copy_proto
(
claz
.
prototype
);
newer
.
init
=
instance
.
base
.
Controller
.
prototype
.
init
;
var
tmpclass
=
claz
.
extend
(
newer
);
return
tmpclass
.
extend
(
add
||
{});
};
/**
* OpenERP Controller
* TODO merge BaseWidget with Controller
*/
instance
.
base
.
Basic
Controller
=
instance
.
base
.
Class
.
extend
(
/** @lends instance.base.
Basic
Controller# */
{
instance
.
base
.
Controller
=
instance
.
base
.
Class
.
extend
(
/** @lends instance.base.Controller# */
{
/**
* @constructs
* rpc operations, event binding and callback calling should be done in
* start() instead of init so that event can be hooked in between.
*
* @constructs
* start() instead of init so that events can be hooked in between.
*/
init
:
function
(
parent
,
element_id
)
{
this
.
element_id
=
element_id
;
...
...
@@ -137,11 +162,10 @@ instance.base.BasicController = instance.base.Class.extend( /** @lends instance.
instance
.
screen
[
element_id
]
=
this
;
}
// save the parent children relationship
this
.
controller_parent
=
null
;
this
.
controller_parent
=
parent
;
this
.
controller_children
=
[];
this
.
parent
=
parent
;
if
(
this
.
parent
&&
this
.
parent
.
children
)
{
this
.
parent
.
children
.
push
(
this
);
if
(
parent
&&
parent
.
controller_children
)
{
parent
.
controller_children
.
push
(
this
);
}
// Transform on_* method into openerp.base.callbacks
...
...
@@ -156,9 +180,8 @@ instance.base.BasicController = instance.base.Class.extend( /** @lends instance.
}
},
/**
* Controller start
* event binding, rpc and callback calling required to initialize the
* object can happen here
* Event binding, rpc and callback calling required to initialize the
* object should happen here
*
* Returns a promise object letting callers (subclasses and direct callers)
* know when this component is done starting
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment