Пример #1
0
    def _renderTag(self, ctx, key, value, readonly):
        tag = T.invisible()
        ta = T.textarea(name=key, id=render_cssid(key), cols=self.cols, rows=self.rows)[value or ""]
        if readonly:
            ta(class_="readonly", readonly="readonly")
        tag[ta]

        if not readonly:
            try:
                import docutils
            except ImportError:
                raise
            else:
                form = iformal.IForm(ctx)
                srcId = render_cssid(key)
                previewDiv = render_cssid(key, "preview-div")
                frameId = render_cssid(key, "preview-frame")
                targetURL = widgetResourceURLFromContext(ctx, form.name).child(key).child(srcId)
                tag[T.br()]
                onclick = ["return Forms.Util.previewShow('", previewDiv, "', '", frameId, "', '", targetURL, "');"]
                tag[T.button(onclick=onclick)["Preview ..."]]
                tag[
                    T.div(id=previewDiv, class_="preview-hidden")[
                        T.iframe(class_="preview-frame", name=frameId, id=frameId),
                        T.br(),
                        T.button(onclick=["return Forms.Util.previewHide('", previewDiv, "');"])["Close"],
                    ]
                ]

        return tag
Пример #2
0
    def _renderTag(self, ctx, tparser, tvalue, namer, readonly):
        tag=T.invisible()
        if len(self.parsers) > 1:
            tp = T.select(name=namer('tparser'),id=render_cssid(namer('tparser')))
            if readonly:
                tp(class_='disabled', disabled='disabled')        
            
            for k,v in self.parsers:
                if k == tparser:
                    tp[T.option(selected='selected',value=k)[ v ]]
                else:
                    tp[T.option(value=k)[ v ]]
        else:
            tp = T.input(type='hidden',name=namer('tparser'),id=render_cssid(namer('tparser')),value=self.parsers[0][0])
        tag[tp]     
               
        if self.itemTypes is not None:
            tag[ T.input(type='hidden',class_="itemTypes",name=namer('itemTypes'),id=render_cssid(namer('itemTypes')),value=encodeTypes(self.itemTypes)) ]
        if self.itemTemplates is not None:
            tag[ T.input(type='hidden',class_="itemTemplates",name=namer('itemTemplates'),id=render_cssid(namer('itemTemplates')),value=','.join(self.itemTemplates)) ]

        ta=T.textarea(name=namer('tvalue'), id=render_cssid(namer('tvalue')), cols=self.cols, rows=self.rows)[tvalue or '']
        if readonly:
            ta(class_='readonly', readonly='readonly')
        tag[ [T.br,ta ]]
        return tag
Пример #3
0
    def _renderTag(self, ctx, tparser, tvalue, namer, readonly):
        tag = T.invisible()
        if len(self.parsers) > 1:
            tp = T.select(name=namer('tparser'),
                          id=render_cssid(namer('tparser')))
            if readonly:
                tp(class_='disabled', disabled='disabled')

            for k, v in self.parsers:
                if k == tparser:
                    tp[T.option(selected='selected', value=k)[v]]
                else:
                    tp[T.option(value=k)[v]]
        else:
            tp = T.input(type='hidden',
                         name=namer('tparser'),
                         id=render_cssid(namer('tparser')),
                         value=self.parsers[0][0])
        ta = T.textarea(name=namer('tvalue'),
                        id=render_cssid(namer('tvalue')),
                        cols=self.cols,
                        rows=self.rows)[tvalue or '']
        if readonly:
            ta(class_='readonly', readonly='readonly')
        tag[tp, T.br, ta]
        return tag
Пример #4
0
    def _renderTag(self, ctx, key, value, readonly):
        html = []
        tag = T.textarea(name=key,
                         id=render_cssid(key),
                         cols=self.cols,
                         rows=self.rows)[value or '']
        if readonly:
            tag(class_='readonly', readonly='readonly')
        html.append(tag)
        if self.values is None:
            return html

        def renderOptions(ctx, options):
            for value, label in options:
                yield T.option(value=value)[label]

        selecttrigger = T.select(name='%s__selecttrigger' % key,
                                 data=self.values)[renderOptions]

        form = iformal.IForm(ctx)
        js = T.xml(
            "var x = document.getElementById('%(form)s');x.%(key)s.value += x.%(key)s__selecttrigger.options[x.%(key)s__selecttrigger.options.selectedIndex].value + "\\n";"
            % {
                'key': key,
                'form': form.name
            })
        aonclick = T.a(onclick=js)['add']
        html.append(T.div(class_="add")[selecttrigger, aonclick])
        return html
Пример #5
0
        def _renderReSTTag(self, ctx, content, key, readonly):
            namer = self._namer(key)

            tag=T.invisible()
            ta=T.textarea(name=namer('content'), id=formal_keytocssid(namer('content')), cols=self.cols, rows=self.rows)[content or '']
            if readonly:
                ta(class_='readonly', readonly='readonly')
            tag[ta]

            if not readonly:
                try:
                    import docutils
                except ImportError:
                    raise
                else:
                    form = iformal.IForm( ctx )
                    srcId = formal_keytocssid(namer('content'))
                    previewDiv = srcId + '-preview-div'
                    frameId = srcId + '-preview-frame'
                    targetURL = formal_widgetResourceURLFromContext(ctx, form.name).child(key).child( srcId )
                    tag[T.br()]
                    tag[T.button(onClick="return Forms.Util.previewShow('%s', '%s', '%s');"%(previewDiv, frameId, targetURL))['Preview ...']]
                    if self.withImagePicker:
                        tag[T.button(onclick=["return Cms.Forms.ImagePicker.popup('",srcId,"','tag')"])['Choose image ...']]

                    tag[T.div(id=previewDiv, class_="preview-hidden")[
                            T.iframe(class_="preview-frame", name=frameId, id=frameId),
                            T.br(),
                            T.button(onClick=["return Forms.Util.previewHide('",previewDiv,"');"])['Close']
                        ]
                    ]

            return tag
Пример #6
0
 def render(self, ctx, key, args, errors):
     if errors:
         value = args.get(key, [''])[0]
     else:
         value = iformal.IStringConvertible(self.original).fromType(
             args.get(key))
     return T.textarea(name=key, id=key, mce_editable='true')[value or '']
Пример #7
0
 def _renderTag(self, ctx, key, value, readonly):
     tag = T.textarea(name=key,
                      id=render_cssid(key),
                      cols=self.cols,
                      rows=self.rows)[value or '']
     if readonly:
         tag(class_='readonly', readonly='readonly')
     return tag
Пример #8
0
 def body(self, ctx, data):
     d = data.get('pbody').split('\r\n')
     text_content = '\n> '.join(d)
     if not text_content.startswith('>'):
         text_content = '> '+text_content
     text = t.textarea(id="content_", name="content",
                       cols="70", rows="8", size="70")[
             text_content
         ]
     return text
Пример #9
0
    def render_lines_input(self, data):
        '''Use to automatically render a textarea for lines of input

        Pass in a dictionary with keys:

        name: name of the textarea
        lines: list of default content lines
        editmode: False if the element should be disabled
        '''

        name = data['name']
        _id = name
        lines = '\n'.join(data['lines'])
        editmode = data.get('editmode', True)

        if editmode:
            area = T.textarea(name=name, _id=_id)[lines]
        else:
            area = T.textarea(name=name, _id=_id, disabled='disabled')[lines]

        return area
Пример #10
0
    def str_widget(self, name, data, size=40):
        disabled = ''
        if name=='name':
            if self.bse=='Player':
                disabled = 'disabled'

        if len(data) < 50:
            size = unicode(size)
            if disabled:
                return T.input(name=name, value=data, size=size, disabled=disabled)
            else:
                return T.input(name=name, value=data, size=size)
        else:
            return T.textarea(name=name, rows="4", cols="60")[data]
Пример #11
0
    def liveElement(self, request, tag):
        """
        Render framework-level boilerplate for making sure the Widget for this
        Element is created and added to the page properly.
        """
        requiredModules = self._getRequiredModules()

        # Add required attributes to the top widget node
        tag(
            **{
                'xmlns:athena': ATHENA_XMLNS_URI,
                'id': 'athena:%d' % self._athenaID,
                'athena:class': self.jsClass
            })

        # This will only be set if _structured() is being run.
        if context.get('children') is not None:
            context.get('children').append({
                u'class':
                self.jsClass,
                u'id':
                self._athenaID,
                u'initArguments':
                self.getInitialArguments()
            })
            context.get('requiredModules').extend(requiredModules)
            return tag

        return (
            # Import stuff
            [self.getImportStan(name) for (name, url) in requiredModules],

            # Dump some data for our client-side __init__ into a text area
            # where it can easily be found.
            tags.textarea(id='athena-init-args-' + str(self._athenaID),
                          style="display: none")
            [json.serialize(self.getInitialArguments())],

            # Arrange to be instantiated
            tags.script(type='text/javascript')
            ["""
                Nevow.Athena.Widget._widgetNodeAdded(%(athenaID)d);
                """ % {
                'athenaID': self._athenaID,
                'pythonClass': self.__class__.__name__
            }],

            # Okay, application stuff, plus metadata
            tag,
        )
Пример #12
0
    def render_maybeEdit(self, ctx, _):
        """Render the edit buttons if the item can be edited."""
        if manages_list(ctx, must_user(ctx), self.list):

            # pylint: disable-msg=E1101
            def _make_option(value, comment):
                """Build on choice of a score."""
                if value == self.item.score:
                    checked = 'yes'
                else:
                    checked = None
                return T.li[T.input(
                    type="radio",
                    name="score",
                    value=str(value),
                    checked=checked)[T.span(
                        style="padding-right:1ex")[self._make_score(value)],
                                     comment]],

            scores = T.ul[_make_option(1, u'Pourquoi pas...'),
                          _make_option(2, u'Chouette\xa0!'),
                          _make_option(3, u'Oh oui, Oh oui\xa0!')]

            return ctx.tag(_class="editable", render=self.render_rounded_box)[
                T.form(name='edit',
                       action=url.here.child('edit'),
                       method='POST')
                [T.input(type='text',
                         name='title',
                         _class='inputfield',
                         value=self.item.title or self.defaultValues['title']),
                 T.br,
                 T.textarea(name='description', _class='inputfield', rows='5'
                            )[self.item.description
                              or self.defaultValues['description']], T.br,
                 T.input(type='text',
                         name='url',
                         _class='inputfield',
                         value=self.item.url or self.defaultValues['url']),
                 scores,
                 T.input(type='submit',
                         name='edit',
                         value=u'Enregistrer les modifications'),
                 T.input(type='submit', name='cancel', value=u'Annuler'), ]]
        else:
            return ''
Пример #13
0
    def renderImmutable(self, ctx, key, args, errors):
        if errors:
            images = args.get(key, [''])[0]
            images = self._parseValue(images)
        else:
            images = iforms.ISequenceConvertible(self.original).fromType(args.get(key))
            if images is None:
                images = []

        imgs = T.invisible()

        for image in images:
            imgs[ T.img(src='/artwork/system/assets/%s/mainImage?size=100x100'%image , class_="preview") ]

        return T.div()[
            imgs, T.br(),
            T.textarea(class_="readonly", readonly="readonly", name=key, id=keytocssid(ctx.key))['\n'.join(images)],
            ]
Пример #14
0
 def _renderTag(self, ctx, tparser, tvalue, namer, readonly):
     tag=T.invisible()
     if len(self.parsers) > 1:
         tp = T.select(name=namer('tparser'),id=render_cssid(namer('tparser')))
         if readonly:
             tp(class_='disabled', disabled='disabled')        
         
         for k,v in self.parsers:
             if k == tparser:
                 tp[T.option(selected='selected',value=k)[ v ]]
             else:
                 tp[T.option(value=k)[ v ]]
     else:
         tp = T.input(type='hidden',name=namer('tparser'),id=render_cssid(namer('tparser')),value=self.parsers[0][0])
     ta=T.textarea(name=namer('tvalue'), id=render_cssid(namer('tvalue')), cols=self.cols, rows=self.rows)[tvalue or '']
     if readonly:
         ta(class_='readonly', readonly='readonly')
     tag[tp,T.br,ta]
     return tag
Пример #15
0
    def _renderTag(self, ctx, key, value, readonly):
        html = []
        tag=T.textarea(name=key, id=render_cssid(key), cols=self.cols, rows=self.rows)[value or '']
        if readonly:
            tag(class_='readonly', readonly='readonly')
        html.append(tag)
        if self.values is None:
            return html
        
        def renderOptions(ctx,options):
            for value,label in options:
                yield T.option(value=value)[label] 

            
        selecttrigger = T.select(name='%s__selecttrigger'%key, data=self.values)[ renderOptions ]


            
        form = iformal.IForm( ctx )
        js = T.xml("var x = document.getElementById('%(form)s');x.%(key)s.value += x.%(key)s__selecttrigger.options[x.%(key)s__selecttrigger.options.selectedIndex].value + &quot;\\n&quot;;"%{'key':key,'form':form.name})
        aonclick = T.a(onclick=js)[ 'add' ]
        html.append(T.div(class_="add")[selecttrigger,aonclick])
        return html
Пример #16
0
    def render_maybeAdd(self, ctx, _):
        """Render the 'new item' form if the user can change the list."""
        avatar = maybe_user(ctx)

        if manages_list(ctx, avatar, self.list):
            req = IRequest(ctx)
            if ctx.arg('back'):
                back = u'Ajouter ce souhait et revenir au site précédent'
            else:
                back = u'Ajouter ce souhait'
            # pylint: disable-msg=E1101
            return T.div(_class="editable bl")[T.div(_class="br")[T.div(
                _class="tl"
            )[T.div(_class="tr")[T.div(_class="edcontent")[
                u'Ajouter un souhait\xa0:',
                T.form(name='add',
                       action=url.here.child('add'),
                       method='POST',
                       _class="edititem")
                [T.input(type='text',
                         name='title',
                         _class='inputfield',
                         value=arg(req, 'title', self.defaultValues['title'])),
                 T.br,
                 T.textarea(name='description', _class='inputfield', rows='5'
                            )[self.defaultValues['description']], T.br,
                 T.input(type='text',
                         name='url',
                         _class='inputfield',
                         value=arg(req, 'url', self.defaultValues['url'])),
                 T.br,
                 T.
                 input(type='hidden', name='back', value=arg(req, 'back', '')),
                 T.input(type='submit', name='add', value=back)]]]]]]
        else:
            return ''
Пример #17
0
    def _renderTag(self, ctx, key, value, readonly):
        tag = T.invisible()
        ta = T.textarea(name=key,
                        id=render_cssid(key),
                        cols=self.cols,
                        rows=self.rows)[value or '']
        if readonly:
            ta(class_='readonly', readonly='readonly')
        tag[ta]

        if not readonly:
            try:
                import docutils
            except ImportError:
                raise
            else:
                form = iformal.IForm(ctx)
                srcId = render_cssid(key)
                previewDiv = render_cssid(key, 'preview-div')
                frameId = render_cssid(key, 'preview-frame')
                targetURL = widgetResourceURLFromContext(
                    ctx, form.name).child(key).child(srcId)
                tag[T.br()]
                onclick = [
                    "return Forms.Util.previewShow('", previewDiv, "', '",
                    frameId, "', '", targetURL, "');"
                ]
                tag[T.button(onclick=onclick)['Preview ...']]
                tag[T.div(id=previewDiv, class_="preview-hidden")[
                    T.iframe(class_="preview-frame", name=frameId, id=frameId),
                    T.br(),
                    T.button(onclick=[
                        "return Forms.Util.previewHide('", previewDiv, "');"
                    ])['Close']]]

        return tag
Пример #18
0
 def input(self, context, slot, data, name, value):
     return slot[
         tags.textarea(id=keyToXMLID(context.key), name=name, _class="freeform-textarea", rows=8, cols=40)[
             value or '']]
Пример #19
0
 def input(self, context, slot, data, name, value):
     return slot[tags.textarea(id=keyToXMLID(context.key),
                               name=name,
                               _class="freeform-textarea",
                               rows=8,
                               cols=40)[value or '']]
Пример #20
0
 def render(self, ctx, key, args, errors):
     if errors:
         value = args.get(key, [''])[0]
     else:
         value = iformal.IStringConvertible(self.original).fromType(args.get(key))
     return T.textarea(name=key, id=key, mce_editable='true')[value or '']
Пример #21
0
 def _renderTag(self, ctx, key, value, readonly):
     tag=T.textarea(name=key, id=render_cssid(key), cols=self.cols, rows=self.rows)[value or '']
     if readonly:
         tag(class_='readonly', readonly='readonly')
     return tag
Пример #22
0
    def render(self, ctx, key, args, errors):

        if errors:
            images = args.get(key, [''])[0]
            images = self._parseValue(images)
        else:
            images = iforms.ISequenceConvertible(self.original).fromType(args.get(key))
            if images is None:
                images = []

        imgs = T.ul(id="artwork_list_"+keytocssid(ctx.key))

        for image in images:
            imgs[ T.li(id='item_%s'%image)[
                T.img(src='/artwork/system/assets/%s/mainImage?size=100x100'%image , class_="preview"),
                T.a(onClick='delete_item(%s);'%image)['delete']
            ] ]

        return T.div()[
            imgs, T.br(),
            T.textarea(name=key, id=keytocssid(ctx.key))['\n'.join(images)], T.br(),
            T.button(onclick="return ArtworkPicker('%s')"%keytocssid(ctx.key))['Choose artwork ...'],
            T.script(type="text/javascript")[
            T.xml("""
            function ArtworkPicker(elementId, type) {
                var url = '/artwork/system/assets/artworkbrowser';
                url = url + '?searchOwningId='+elementId+'&searchType='+type;
                var popup = window.open(url, 'ArtworkPicker', 'height=500,width=900,resizable,scrollbars');
                popup.focus();
                return false;
            }
            function imageListChanged(sortable) {
              var items = MochiKit.Sortable.Sortable.serialize(sortable).split('&');
              var newOrder=[];
              for(i=0;i<items.length;i++){
                var item = items[i];
                var id = item.split('=')[1];
                newOrder.push(id);
              }
              var ta=document.getElementById('%(key)s');
              ta.value='';
              for(i=0;i<newOrder.length;i++) {
                ta.value=ta.value+'\\n'+newOrder[i];
              }
            }

            function itemAdded() {
              MochiKit.Sortable.Sortable.create('artwork_list_%(key)s',{onUpdate:imageListChanged});
            }

            function delete_item(delete_id) {
              var element=document.getElementById('item_'+delete_id);
              removeElement(element);
              var ta=document.getElementById('%(key)s');
              var ids = ta.value.split('\\n');

              ta.value='';
              for(i=0;i<ids.length;i++) {
                id = ids[i];
                if(delete_id==id) {
                  continue;
                } 
                ta.value=ta.value+'\\n'+id;
              }
            }
            function setup() {
                connect('artwork_list_%(key)s', 'itemAdded', itemAdded); 
                signal('artwork_list_%(key)s', 'itemAdded');
            }
            setup();
            """%{'key': keytocssid(ctx.key)})
            ]
            ]
Пример #23
0
	def _renderTag(self, ctx, key, value, readonly):
		tag=T.textarea(name=key, id=render_cssid(key), rows=self.rows,
			style="width:100% !important")[value or '']
		if readonly:
			tag(class_='readonly', readonly='readonly')
		return tag