Esempio n. 1
0
 def next(self, request):
     url = make_url(request.request, node=self.model)
     if request.get('ajax'):
         return [
             AjaxAction(url, 'leftcolumn', 'replace', '.left_column'),
             AjaxAction(url, 'rightcolumn', 'replace', '.right_column'),
         ]
     return HTTPFound(location=url)
Esempio n. 2
0
 def next(self, request):
     came_from = request.get('came_from')
     if came_from:
         came_from = compat.unquote(came_from)
         url = '{}?pid={}'.format(came_from, self.model.name)
     else:
         url = make_url(request.request, node=self.model)
     if self.ajax_request:
         return [
             AjaxAction(url, 'leftcolumn', 'replace', '.left_column'),
             AjaxAction(url, 'rightcolumn', 'replace', '.right_column'),
         ]
     return HTTPFound(location=url)
Esempio n. 3
0
 def next(self, request):
     next_resource = self.request.environ.get('next_resource')
     if next_resource:
         query = make_query(pid=next_resource)
         url = make_url(request.request, node=self.model.parent, query=query)
     else:
         url = make_url(request.request, node=self.model.parent)
     if self.ajax_request:
         return [
             AjaxAction(url, 'leftcolumn', 'replace', '.left_column'),
             AjaxAction(url, 'rightcolumn', 'replace', '.right_column'),
         ]
     return HTTPFound(location=url)
Esempio n. 4
0
 def next(self, request):
     next_resource = self.request.environ.get('next_resource')
     if next_resource:
         url = make_url(request.request,
                        node=self.model,
                        resource=next_resource)
     else:
         url = make_url(request.request, node=self.model)
     if request.get('ajax'):
         return [
             AjaxAction(url, 'leftcolumn', 'replace', '.left_column'),
             AjaxAction(url, 'rightcolumn', 'replace', '.right_column'),
         ]
     return HTTPFound(location=url)
Esempio n. 5
0
 def test_AjaxAction(self):
     target = 'http://example.com'
     actionname = 'tilename'
     mode = 'replace'
     selector = '.someselector'
     action = AjaxAction(target, actionname, mode, selector)
     self.assertEqual(
         (action.name, action.selector, action.mode, action.target),
         (actionname, selector, mode, target))
Esempio n. 6
0
 def next(self, request):
     url = 'http://example.com'
     if self.ajax_request:
         # return as single value, gets list on request.environ
         cont = AjaxAction(url, 'content', 'inner', '#content')
         if self.continuation_as_list:
             return [cont]
         else:
             return cont
     if self.next_as_redirect:
         return HTTPFound(url)
     # return anything else to be rendered
     return '<div>success!</div>'
Esempio n. 7
0
 def next(self, request):
     url = 'http://example.com'
     return [
         AjaxAction(url, 'content', 'inner', '#content'),
         AjaxEvent(url, 'contextchanged', '.contextsensitiv')
     ]
Esempio n. 8
0
    def test_AjaxFormContinue(self):
        # AjaxFormContinue object. This object is used by ``render_ajax_form``
        result = ''
        continuation = []
        afc = AjaxFormContinue(result, continuation)
        self.assertEqual(afc.form, '')
        self.assertEqual(afc.next, 'false')

        # If no continuation definitions, ``form`` returns result and ``next``
        # returns 'false'
        result = 'rendered form'
        afc = AjaxFormContinue(result, [])
        self.assertEqual(afc.form, 'rendered form')
        self.assertEqual(afc.next, 'false')

        # If continuation definitions and result, ``form`` returns empty
        # string, because form processing was successful. ``next`` returns a
        # JSON dump of given actions, which gets interpreted and executed on
        # client side
        action = AjaxAction(
            'http://example.com',
            'tilename',
            'replace',
            '.someselector'
        )
        event = AjaxEvent(
            'http://example.com',
            'contextchanged',
            '.contextsensitiv'
        )
        message = AjaxMessage(
            'Some info message',
            'info',
            'None'
        )
        overlay = AjaxOverlay(
            selector='#ajax-overlay',
            action='someaction',
            target='http://example.com',
            close=False,
            content_selector='.overlay_content',
            css='additional-css-class'
        )
        path = AjaxPath(
            'foo/bar',
            target='http://example.com/foo/bar',
            action='layout:#layout:replace',
            event='contextchanged:#someid',
            overlay='acionname:#custom-overlay:.custom_overlay_content',
            overlay_css='additional-overlay-css-class'
        )

        continuation = [action, event, message, overlay, path]
        afc = AjaxFormContinue(result, continuation)
        self.assertEqual(afc.form, '')

        afc_next = json.loads(afc.next)
        self.assertEqual(afc_next, [{
            "mode": "replace",
            "selector": ".someselector",
            "type": "action",
            "target": "http://example.com",
            "name": "tilename"
        }, {
            "selector": ".contextsensitiv",
            "type": "event",
            "target": "http://example.com",
            "name": "contextchanged"
        }, {
            "flavor": "info",
            "type": "message",
            "payload": "Some info message",
            "selector": "None"
        }, {
            "target": "http://example.com",
            "content_selector": ".overlay_content",
            "selector": "#ajax-overlay",
            "action": "someaction",
            "close": False,
            "type": "overlay",
            "css": "additional-css-class"
        }, {
            "overlay_css": "additional-overlay-css-class",
            "target": "http://example.com/foo/bar",
            "overlay": "acionname:#custom-overlay:.custom_overlay_content",
            "action": "layout:#layout:replace",
            "path": "foo/bar",
            "type": "path",
            "event": "contextchanged:#someid"
        }])
Esempio n. 9
0
 def render(self):
     ajax_continue(
         self.request,
         AjaxAction('target', 'name', 'mode', 'selector')
     )
     return u''
Esempio n. 10
0
 def continuation(self):
     url = make_url(self.request, node=self.model)
     return AjaxAction(url, 'content', 'inner', '.ldap_roles')
Esempio n. 11
0
 def next(self, request):
     url = make_url(request.request, node=self.model)
     selector = '.%s' % self.model.name
     return [AjaxAction(url, 'content', 'inner', selector)]
Esempio n. 12
0
 def render(self):
     cut = extract_copysupport_cookie(self.request, 'cut')
     copy = extract_copysupport_cookie(self.request, 'copy')
     localizer = get_localizer(self.request)
     if not cut and not copy:
         message = localizer.translate(
             _('nothing_to_paste', default='Nothing to paste'))
         ajax_message(self.request, message)
         return u''
     urls = copy and copy or cut
     paths = paths_from_urls(urls)
     call_sources = set()
     errors = list()
     success = 0
     for path in paths:
         node = self.model.root
         for key in path:
             node = node[key]
         if not node.node_info_name:
             message = localizer.translate(
                 _(
                     'cannot_paste_unknown_source',
                     default="Cannot paste '${name}'. Unknown source"
                 ),
                 mapping={'name': node.name}
             )
             errors.append(message)
             continue
         if not self.model.node_info_name:
             message = localizer.translate(
                 _(
                     'cannot_paste_unknown_target',
                     default="Cannot paste to '${name}'. Unknown target"
                 ),
                 mapping={'name': self.model.name}
             )
             errors.append(message)
             continue
         if node.node_info_name not in self.model.nodeinfo.addables:
             message = localizer.translate(
                 _(
                     'cannot_paste_cardinality_violation',
                     default=(
                         "Violation. '${target}' is not allowed to "
                         "contain '${source}'"
                     )
                 ),
                 mapping={
                     'target': self.model.nodeinfo.title,
                     'source': node.nodeinfo.title
                 }
             )
             errors.append(message)
             continue
         source = node.parent
         if copy:
             node = source[node.name].deepcopy()
         else:
             in_model = False
             for parent in LocationIterator(self.model):
                 if parent is node:
                     message = localizer.translate(
                         _(
                             'cannot_paste_self_containment',
                             default=(
                                 "Cannot paste cut object to child "
                                 "of it: ${name}"
                             )
                         ),
                         mapping={'name': parent.name}
                     )
                     errors.append(message)
                     in_model = True
                     break
             if in_model:
                 continue
             node = source.detach(node.name)
         node.__parent__ = self.model
         self.model[choose_name(self.model, node.name)] = node
         if cut:
             call_sources.add(source)
         success += 1
     if success > 0:
         self.model()
     for source in call_sources:
         source()
     message = localizer.translate(
         _(
             'pasted_items',
             default="Pasted ${count} items"
         ),
         mapping={'count': success}
     )
     if errors:
         failed = localizer.translate(
             _(
                 'pasting_items_failed',
                 default="Pasting of ${count} items failed"
             ),
             mapping={'count': len(errors)}
         )
         failed = "<br /><strong>%s</strong>" % failed
         message += "<br />".join([failed] + errors)
     ajax_message(self.request, message)
     url = make_url(self.request, node=self.model)
     action = AjaxAction(url, 'content', 'inner', '#content')
     event = AjaxEvent(url, 'contextchanged', '.contextsensitiv')
     continuation = [action, event]
     ajax_continue(self.request, continuation)
     res = self.request.response
     res.delete_cookie(cookie_name(copy and 'copy' or 'cut'))
     return u''