[widgets] fix rendering of the sendmail widget, still to functional though tls-sprint
authorAdrien Di Mascio <Adrien.DiMascio@logilab.fr>
Fri, 24 Apr 2009 09:06:56 +0200
branchtls-sprint
changeset 1466 07a2d0c387ca
parent 1465 42f13c790f11
child 1467 972517be96dc
[widgets] fix rendering of the sendmail widget, still to functional though
web/data/cubicweb.mailform.css
web/data/cubicweb.widgets.js
web/views/massmailing.py
--- a/web/data/cubicweb.mailform.css	Fri Apr 24 09:04:45 2009 +0200
+++ b/web/data/cubicweb.mailform.css	Fri Apr 24 09:06:56 2009 +0200
@@ -5,7 +5,7 @@
  *  :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
  */
 
-div#compose {
+form#sendmail {
   border: 1px solid #DBDCE3;
   background-color: #E9F5F7;
   font-family:Verdana,Tahoma,Arial,sans-serif;
@@ -16,7 +16,7 @@
   width: 100%;
 }
 
-div#compose td#buttonbar {
+form#sendmail td#buttonbar {
   padding: 0.5ex 0ex;
 }
 
@@ -36,12 +36,12 @@
   width: 47em; 
 }
 
-div#compose div#toolbar {
+form#sendmail div#toolbar {
   margin: 0.5em 0em;
   height: 29px;
 }
 
-div#compose div#toolbar ul {
+form#sendmail div#toolbar ul {
   list-style-image: none;
   list-style-position: outside;
   list-style-type:none;
@@ -50,13 +50,13 @@
   /* border: 1px solid #DBDCE3; */
 }
 
-div#compose div#toolbar li {
+form#sendmail div#toolbar li {
   background: none;
   padding-left: 1em;
   float: left;
 }
 
-div#compose div#toolbar li a {
+form#sendmail div#toolbar li a {
   font-family: Verdana,Tahoma,Arial,sans-serif;
   color: #444444;
 }
--- a/web/data/cubicweb.widgets.js	Fri Apr 24 09:04:45 2009 +0200
+++ b/web/data/cubicweb.widgets.js	Fri Apr 24 09:06:56 2009 +0200
@@ -228,35 +228,41 @@
 			'cols' : wdgnode.getAttribute('cubicweb:cols') || 80
 		       };
 	// this.variableRegexp = /%\((\w+)\)s/;
-	this.errorField = DIV({'class' : "textfieldErrors"});
+	this.errorField = DIV({'class' : "errorMessage"});
 	this.textField = TEXTAREA(this.options);
 	jQuery(this.textField).bind('keyup', {'self': this}, this.highlightInvalidVariables);
+	jQuery('#substitutions').prepend(this.errorField);
+	jQuery('#substitutions .errorMessage').hide();
 	wdgnode.appendChild(this.textField);
-	wdgnode.appendChild(this.errorField);
     },
 
     /* signal callbacks */
 
-    highlightInvalidVariables : function() {
-	var text = this.textField.value;
+    highlightInvalidVariables : function(event) {
+	var self = event.data.self;
+	var text = self.textField.value;
 	var unknownVariables = [];
-	var it=0;
+	var it = 0;
 	var group = null;
 	var variableRegexp = /%\((\w+)\)s/g;
 	// emulates rgx.findAll()
 	while ( group=variableRegexp.exec(text) ) {
-	    if ( !this.variables.contains(group[1]) ) {
+	    if ( !self.variables.contains(group[1]) ) {
 		unknownVariables.push(group[1]);
 	    }
 	    it++;
-	    if (it > 5)
+	    if (it > 5) {
 		break;
+	    }
 	}
 	var errText = '';
 	if (unknownVariables.length) {
 	    errText = "Detected invalid variables : " + ", ".join(unknownVariables);
+	    jQuery('#substitutions .errorMessage').show();
+	} else {
+	    jQuery('#substitutions .errorMessage').hide();
 	}
-	this.errorField.innerHTML = errText;
+	self.errorField.innerHTML = errText;
     }
 
 });
@@ -279,12 +285,12 @@
           this.etype_from = wdgnode.getAttribute('cubicweb:etype_from');
      	  var d = asyncRemoteExec('add_and_link_new_entity', this.etype_to, this.rel, this.eid_to, this.etype_from, 'new_val');
           d.addCallback(function (eid) {
-          jQuery(wdgnode).find("option[selected]").removeAttr("selected");
-          var new_option = OPTION({'value':eid, 'selected':'selected'}, value=new_val);
-          wdgnode.appendChild(new_option);
+	      jQuery(wdgnode).find("option[selected]").removeAttr("selected");
+              var new_option = OPTION({'value':eid, 'selected':'selected'}, value=new_val);
+              wdgnode.appendChild(new_option);
           });
           d.addErrback(function (xxx) {
-             log('xxx =', xxx);
+              log('xxx =', xxx);
           });
      });
    }
--- a/web/views/massmailing.py	Fri Apr 24 09:04:45 2009 +0200
+++ b/web/views/massmailing.py	Fri Apr 24 09:06:56 2009 +0200
@@ -34,33 +34,33 @@
         return self.build_url(self.req.relative_path(includeparams=False),
                               **params)
 
-            
+
 class MassMailingForm(FieldsForm):
     id = 'massmailing'
-    
+
     sender = StringField(widget=TextInput({'disabled': 'disabled'}), label=_('From:'))
     recipient = StringField(widget=CheckBox(), label=_('Recipients:'))
     subject = StringField(label=_('Subject:'))
     mailbody = StringField(widget=AjaxWidget(wdgtype='TemplateTextField',
                                              inputid='mailarea'))
-    form_buttons = [ImgButton('sendbutton', "javascript: $('sendmail').submit()",
+    form_buttons = [ImgButton('sendbutton', "javascript: $('#sendmail').submit()",
                               _('send email'), 'SEND_EMAIL_ICON'),
                     ImgButton('cancelbutton', "javascript: history.back()",
-                              stdmsgs.BUTTON_CANCEL, 'CANCEL_EMAIL_ICON')]                    
-                              
+                              stdmsgs.BUTTON_CANCEL, 'CANCEL_EMAIL_ICON')]
+
     def form_field_vocabulary(self, field):
         if field.name == 'recipient':
             vocab = [(entity.get_email(), entity.eid) for entity in self.rset.entities()]
             return [(label, value) for label, value in vocab if label]
         return super(MassMailingForm, self).form_field_vocabulary(field)
-    
+
     def form_field_value(self, field, values):
         if field.name == 'recipient':
             return [entity.eid for entity in self.rset.entities() if entity.get_email()]
         elif field.name == 'mailbody':
-            field.widget.attrs['cubicweb:variables'] = self.get_allowed_substitutions()
+            field.widget.attrs['cubicweb:variables'] = ','.join(self.get_allowed_substitutions())
         return super(MassMailingForm, self).form_field_value(field, values)
-    
+
     def get_allowed_substitutions(self):
         attrs = []
         for coltype in self.rset.column_types(0):
@@ -79,12 +79,13 @@
 
 class MassMailingFormRenderer(FormRenderer):
     button_bar_class = u'toolbar'
-    
+
     def _render_fields(self, fields, w, form):
         w(u'<table class="headersform">')
         for field in fields:
             if field.name == 'mailbody':
                 w(u'</table>')
+                self._render_toolbar(w, form)
                 w(u'<table>')
                 w(u'<tr><td><div>')
             else:
@@ -100,7 +101,17 @@
                 w(u'</td></tr>')
         w(u'</table>')
 
-    
+    def _render_toolbar(self, w, form):
+        w(u'<div id="toolbar">')
+        w(u'<ul>')
+        for button in form.form_buttons:
+            w(u'<li>%s</li>' % button.render(form))
+        w(u'</ul>')
+        w(u'</div>')
+
+    def render_buttons(self, w, form):
+        pass
+
 class MassMailingFormView(FormViewMixIn, EntityView):
     id = 'massmailing'
     __select__ = implements(IEmailable) & match_user_groups('managers', 'users')
@@ -113,6 +124,3 @@
         form = self.vreg.select_object('forms', 'massmailing', self.req, self.rset,
                                        action='sendmail', domid='sendmail')
         self.w(form.form_render(sender=from_addr, renderer=MassMailingFormRenderer()))
-
-
-