Changeset 373


Ignore:
Timestamp:
Apr 22, 2010, 5:07:09 PM (14 years ago)
Author:
duh
Message:
  • template editor dynamically instantiates entities
  • dialog changes
Location:
trunk
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/controllers/dbnp/studycapturing/TemplateEditorController.groovy

    r372 r373  
    3838        def pagesFlow = {
    3939                // start the flow
    40                 onStart {
    41                         println params
    42                         if (params.entity) {
    43                                 //def name = params.entity
    44                                 //def name = "java.lang.Integer"
    45                                 //println name.class
    46                                 //def S = new dbnp.studycapturing.Study()
     40                start {
     41                        action {
     42                                // define initial flow variables
     43                                flow.entity = null
     44                                flow.templates = []
    4745
    48                                 //def name = "dbnp.studycapturing.Study" as Class
    49                                 //println name.newInstance()
    50                                 println Class.forName(new GString("dbnp.studycapturing.Study"))
    51                                 //flow.entity = (name as Class).newInstance()
    52                                 //flow.templates = Template.findAllByEntity(flow.entity)
    53                         } else {
    54                                 // all templates for all entities; note that normally
    55                                 // this shouldn't happen as this flow is designed to
    56                                 // launch in a jquery dialog, passing an encoded entity
    57                                 flow.templates = Template.findAll()
     46                                // define success variable
     47                                def errors = true
     48
     49                                // got an entity parameter?
     50                                if (params.entity && params.entity instanceof String) {
     51                                        // yes, try to dynamicall load the entity
     52                                        try {
     53                                                // dynamically load the entity
     54                                                def entity = Class.forName(params.entity, true, this.getClass().getClassLoader())
     55
     56                                                // succes, is entity an instance of TemplateEntity?
     57                                                if (entity.superclass =~ /TemplateEntity$/) {
     58                                                        errors = false
     59
     60                                                        // yes, assign entity to the flow
     61                                                        flow.entity = entity
     62
     63                                                        // fetch all templates to this entity
     64                                                        flow.templates = Template.findAllByEntity(entity)
     65                                                }
     66                                        } catch (Exception e) { }
     67                                }
     68
     69                                // success?
     70                                if (errors) {
     71                                        error()
     72                                } else {
     73                                        success()
     74                                }
    5875                        }
    59                         flow.templates = Template.findAll()
     76                        on("success").to "templates"
     77                        on("error").to "errorInvalidEntity"
     78                }
     79
     80                // error dynamically loading entity
     81                errorInvalidEntity {
     82                        render(view: "_errorInvalidEntity")
    6083                }
    6184
  • trunk/grails-app/views/templateEditor/templates.gsp

    r372 r373  
    2424
    2525 <g:if test="${templates}">
     26  <ul>
    2627  <g:each in="${templates}">
    27      ${it}<br/>
     28     <li>${it}</li>
    2829  </g:each>
     30  </ul>
    2931 </g:if>
    3032 
  • trunk/web-app/css/dialog.css

    r372 r373  
    22        margin: 0; padding: 0;
    33        font: 10px normal Arial, Helvetica, sans-serif;
    4         background-color: #fff;
    54}
  • trunk/web-app/js/SelectAddMore.js

    r372 r373  
    4848        class   : 'addmore',
    4949        width   : 800,
    50         height  : 500,
     50        height  : 400,
     51        position: 'center',
    5152        onClose : function(scope) {
    5253            // onClose handler does nothing by default
     
    8687        var height  = that.options.height;
    8788        var onClose = that.options.onClose;
     89        var position= that.options.position;
    8890
    8991        // add a magic option to the end of the select element
     
    104106                    height  : height,
    105107                    modal   : true,
     108                    position: position,
    106109                    buttons : {
    107110                                Ok  : function() { $(this).dialog('close'); }
  • trunk/web-app/js/SelectAddMore.min.js

    r359 r373  
    1 function SelectAddMore(){}SelectAddMore.prototype={rel:"myRel",url:"http://www.youtube.com/watch?v=2WNrx2jq184",vars:"myVar",width:800,height:500,onClose:function(a){alert("the dialog was closed! --> "+a)},init:function(a,c,e,b){var d=this;d.rel=a;d.url=c;d.vars=e;d.onClose=b;$("select[rel*='"+d.rel+"']").each(function(){d.addTermEditorOption(this)})},addTermEditorOption:function(a){var c=this;var d=$(a);var b=d.children().size();d.append('<option value="" class="addTerm">add more...</option>');d.bind("change",function(){if(this.selectedIndex==b){$('<iframe src="'+c.url+"?"+c.vars+"="+d.attr(c.vars)+'" sanbox="allow-same-origin" seamless />').dialog({title:"Add more...",autoOpen:true,width:c.width,height:c.height,modal:true,close:function(){c.onClose(this)}}).width(c.width-10).height(c.height)}})}};
     1function SelectAddMore(){}SelectAddMore.prototype={options:{rel:'addmore',url:'http://www.youtube.com/watch?v=2WNrx2jq184',vars:'vars',label:'add more...',class:'addmore',width:800,height:400,position:'center',onClose:function(scope){}},init:function(options){var that=this;$.each(options,function(key,value){that.options[key]=value});$("select[rel*='"+that.options.rel+"']").each(function(){that.addOpenDialogOption(this)})},addOpenDialogOption:function(element){var that=this;var e=$(element);var s=e.children().size();var class=that.options.class;var label=that.options.label;var vars=that.options.vars;var url=that.options.url;var width=that.options.width;var height=that.options.height;var onClose=that.options.onClose;var position=that.options.position;e.append('<option value="" class="'+class+'">'+label+'</option>');e.bind('change',function(){if(this.selectedIndex==s){$('<iframe src="'+url+'?'+vars+'='+e.attr(vars)+'" sanbox="allow-same-origin" seamless />').dialog({title:label,autoOpen:true,width:width,height:height,modal:true,position:position,buttons:{Ok:function(){$(this).dialog('close')}},close:function(){onClose(this)}}).width(width-10).height(height)}})}}
Note: See TracChangeset for help on using the changeset viewer.