acceptAndAdmin.php 9.76 KB
Newer Older
Tibor Katelbach's avatar
Tibor Katelbach committed
1
<script type="text/javascript">
Tibor Katelbach's avatar
Tibor Katelbach committed
2 3 4 5 6 7 8 9 10 11 12
	//contains all dynform definitions for complexe inputs
	//it also carries sub dynforms, when an input needs extra parameters to 
	var sectionDyf = {};
	var tplCtx = {};
	
	var DFdata = {
		'tpl'  : '<?php echo $tpl ?>',
		"id"   : "<?php echo Yii::app()->session["costum"]["contextId"] ?>"
	};
	costum.col = "<?php echo Yii::app()->session["costum"]["contextType"]  ?>";
	costum.ctrl = "<?php echo Element::getControlerByCollection(Yii::app()->session["costum"]["contextType"]) ?>";
Clément Damiens's avatar
 
Clément Damiens committed
13

14 15
	var configDynForm = <?php echo json_encode($this->costum['dynForm']); ?>;
	var tplsList = <?php echo json_encode((isset($this->costum['tpls'])) ? $this->costum['tpls']:null); ?>;
Clément Damiens's avatar
 
Clément Damiens committed
16 17 18

		//contains all dynform definitions for complexe inputs
		//it also carries sub dynforms, when an input needs extra parameters to 
Raph El's avatar
Raph El committed
19
		//var sectionDyf = {};
Clément Damiens's avatar
 
Clément Damiens committed
20 21 22 23
		var tplCtx = {};
		
		var DFdata = {
			'tpl'  : '<?php echo $tpl ?>',
24
			"id"   : "<?php echo $this->costum["contextId"] ?>"
Clément Damiens's avatar
 
Clément Damiens committed
25
		};
26 27
		costum.col = "<?php echo $this->costum["contextType"]  ?>";
		costum.ctrl = "<?php echo Element::getControlerByCollection($this->costum["contextType"]) ?>";
Clément Damiens's avatar
 
Clément Damiens committed
28

29 30
		var configDynForm = <?php echo json_encode($this->costum['dynForm']); ?>;
		var tplsList = <?php echo json_encode((isset($this->costum['tpls'])) ? $this->costum['tpls']:null); ?>;
Raph El's avatar
Raph El committed
31

Tibor Katelbach's avatar
Tibor Katelbach committed
32
</script>
Clément Damiens's avatar
 
Clément Damiens committed
33
		
Tibor Katelbach's avatar
Tibor Katelbach committed
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
<?php 
if( !isset( $el["costum"]["slug"] ) || (isset( $el["costum"]["slug"]) && $el["costum"]["slug"] != $tpl ) ) 
  $test=$tpl;
if( isset($test) || $canEdit ) 
{
?>

<script type="text/javascript">

	
	function saveThisTpl (slug) { 
		data = {
			collection : costum.contextType,
			id : costum.contextId,
			path : "costum.slug",
			value : '<?php echo $tpl ?>'
Clément Damiens's avatar
 
Clément Damiens committed
50
		}
Tibor Katelbach's avatar
Tibor Katelbach committed
51 52 53 54 55 56 57 58 59 60 61 62 63
		mylog.log(".saveThisTpl","data",data);
		// http://127.0.0.1/costum/co/index/slug/administration-opal/test/campagne#
		dataHelper.path2Value( data, function(params) { 
			var s = location.href;
			var a = s.split('/');
			s = s.replace(a[a.length-2] + '/', '');
			s = s.replace(a[a.length-1], '');
			location.href = s;
		} );
	}
	function previewTpl () { 
		$('#acceptAndAdmin,.editBtn,.editQuestion,.addQuestion,.deleteLine, .previewTpl').fadeOut(); 
	}
Clément Damiens's avatar
 
Clément Damiens committed
64 65 66 67

jQuery(document).ready(function() {


Tibor Katelbach's avatar
Tibor Katelbach committed
68 69 70 71 72 73 74 75
    mylog.log("render","/modules/costum/views/tpls/acceptAndAdmin.php");
        $(".editBtn").off().on("click",function() { 
            var activeForm = {
                "jsonSchema" : {
                    "title" : "Template config",
                    "type" : "object",
                    "properties" : {
                        
Clément Damiens's avatar
 
Clément Damiens committed
76
                    }
Tibor Katelbach's avatar
Tibor Katelbach committed
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
                }
            };
            if(configDynForm.jsonSchema.properties[ $(this).data("key") ])
            	activeForm.jsonSchema.properties[ $(this).data("key") ] = configDynForm.jsonSchema.properties[ $(this).data("key") ];
            else
            	activeForm.jsonSchema.properties[ $(this).data("key") ] = { label : $(this).data("label") };
            
            if($(this).data("label"))
            	activeForm.jsonSchema.properties[ $(this).data("key") ].label = $(this).data("label");
            if($(this).data("type")){
            	activeForm.jsonSchema.properties[ $(this).data("key") ].inputType = $(this).data("type");
            	if($(this).data("type") == "textarea" && $(this).data("markdown") )
            		activeForm.jsonSchema.properties[ $(this).data("key") ].markdown = true;
            }

            
            tplCtx.id = contextData.id;
			tplCtx.collection = contextData.type;
            tplCtx.key = $(this).data("key");
            tplCtx.path = $(this).data("path");
            
            activeForm.jsonSchema.save = function () {  
                tplCtx.value = $( "#"+tplCtx.key ).val();
                    //alert("#"+tplCtx.key+" : "+$( "#"+tplCtx.key ).val());
                console.log("activeForm save tplCtx",tplCtx);
                if(typeof tplCtx.value == "undefined")
                	toastr.error('value cannot be empty!');
                else {
                    dataHelper.path2Value( tplCtx, function(params) { 
                        $("#ajax-modal").modal('hide');
                        location.reload();
                    } );
Clément Damiens's avatar
 
Clément Damiens committed
109 110
                }

Tibor Katelbach's avatar
Tibor Katelbach committed
111 112 113
        	}
            dyFObj.openForm( activeForm );
    });
Clément Damiens's avatar
 
Clément Damiens committed
114

Tibor Katelbach's avatar
Tibor Katelbach committed
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
    $('.deleteLine').off().click( function(){
      formId = $(this).data("id");
      key = $(this).data("key");
      pathLine = $(this).data("path");
      collection = $(this).data("collection");
      bootbox.dialog({
          title: "Confirmez la suppression",
          message: "<span class='text-red bold'><i class='fa fa-warning'></i> Cette action sera irréversible</span>",
          buttons: [
            {
              label: "Ok",
              className: "btn btn-primary pull-left",
              callback: function() {
                var formQ = {
				  	value:null,
				  	collection : collection,
				  	id : formId,
				  	path : pathLine
				  };
				  
				  dataHelper.path2Value( formQ , function(params) { 
						$("#"+key).remove();
                        //location.reload();
					} );
              }
            },
            {
              label: "Annuler",
              className: "btn btn-default pull-left",
              callback: function() {}
            }
          ]
      });
Clément Damiens's avatar
 
Clément Damiens committed
148
    });
Tibor Katelbach's avatar
Tibor Katelbach committed
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244

	$(".editTpl").off().on("click",function() { 
		var activeForm = {
            "jsonSchema" : {
                "title" : "Edit Question config",
                "type" : "object",
                "properties" : {}
            }
        };
    
    	$.each( formTpls [ $(this).data("key") ] , function(k,val) { 
    		console.log("formTpls",k,val); 
    		activeForm.jsonSchema.properties[ k ] = {
    			label : k,
    			value : val
    		};
    	 });
        
        console.log("formTpls activeForm.jsonSchema.properties",activeForm.jsonSchema.properties); 
        tplCtx.id = $(this).data("id");
        tplCtx.key = $(this).data("key");
        tplCtx.collection = $(this).data("collection");            
        tplCtx.path = $(this).data("path");
        
        activeForm.jsonSchema.save = function () {  
            tplCtx.value = {};
            $.each( formTpls [ tplCtx.key ] , function(k,val) { 
        		tplCtx.value[k] = $("#"+k).val();
        	 });
                //alert("#"+tplCtx.key+" : "+$( "#"+tplCtx.key ).val());
            console.log("save tplCtx",tplCtx);
            if(typeof tplCtx.value == "undefined")
            	toastr.error('value cannot be empty!');
            else {
                dataHelper.path2Value( tplCtx, function(params) { 
                    $("#ajax-modal").modal('hide');
                    location.reload();
                } );
            }

    	}
        dyFObj.openForm( activeForm );
    });

    $(".addTpl").off().on("click",function() { 
        var tplCtx = {};
        var activeForm = {
            "jsonSchema" : {
                "title" : "Ajouter une section",
                "type" : "object",
                "properties" : {
                    type : { label : "Choisir le template",
                    		 inputType : "select",
                    		 options : {
								"blockevent"    : "Les blocs d'évènements",
                                "eventCarousel" : "Les évènements en carousel",
								"blockwithimg"  : "Un bloc avec un texte et une image",
								"communityblock"     : "Les blocs communautés",
								"communityCaroussel"      : "Communauté en carousel",
                                "news" : "L'actualité"
                    		 },
                    		 value : "text" }
                }
            }
        };          
        
        tplCtx.id = $(this).data("id");
        tplCtx.key = $(this).data("key");
        tplCtx.collection = $(this).data("collection");
        
        activeForm.jsonSchema.save = function () {  
            tplCtx.path = "costum.tpls."+$("#type").val();
            tplCtx.value = {
                defaultcolor : "white"
            };
            console.log("activeForm save tplCtx",tplCtx);
            if(typeof tplCtx.value == "undefined")
            	toastr.error('value cannot be empty!');
            else {
                dataHelper.path2Value( tplCtx, function(params) { 
                    $("#ajax-modal").modal('hide');
                    location.reload();
                } );
            }

    	}

        dyFObj.openForm( activeForm );
    });

    
});
</script>

<div class="alert alert-danger text-center"  id="acceptAndAdmin" >
  
245 246 247 248
  	<?php //echo $this->costum["contextId"]."<br/>" ?>
	<?php //echo $this->costum["contextType"]."<br/>" ?>
	<?php //echo $this->costum["contextSlug"]."<br/>" ?>
	<?php //var_dump($this->costum) ?>
Tibor Katelbach's avatar
Tibor Katelbach committed
249 250 251 252 253

  	<?php if(isset($test)  ){ ?>
  	<strong>Hey!</strong> Is this what you want ? 
	<a href="javascript:;" onclick=" saveThisTpl('<?php echo $tpl ?>') " class="btn btn-danger"> Save This Template</a> <a href="/costum/co/index/slug/<?php echo $slug ?>/test/costumBuilder" class="btn btn-default"> Try another Template </a>
	
254
	<?php } else if(isset($this->costum["dynForm"])) {
Tibor Katelbach's avatar
Tibor Katelbach committed
255 256 257
        ?>
	<!-- <strong>Configure</strong> your Costum Template <a href="/costum/co/config/slug/<?php //echo $slug ?>" class="btn btn-danger"><i class="fa fa-pencil"></i> here </a> -->
	<a class="btn btn-default" href="javascript:previewTpl();"><i class="fa fa-eye"></i> Preview</a>
258
    <a class="btn btn-default" href="#@<?= $this->costum["contextSlug"] ?>" data-hash="#page.type.<?= $this->costum["contextType"] ?>.id.<?= $this->costum["contextId"] ?>" target="_blank"><i class="fa fa-id-card-o" aria-hidden="true"></i>
Tibor Katelbach's avatar
Tibor Katelbach committed
259 260 261 262 263 264 265
Element </a>
    <?php echo $this->renderPartial("costum.views.tpls.blocCss", array("canEdit" => $canEdit));   ?>
    <?php echo $this->renderPartial("costum.views.tpls.blocApp", array("canEdit" => $canEdit));   ?>
	<?php } else  { ?>
	<strong>hey petit pixel</strong> rajoute une balise dynform sur ton template pour le rendre editable. 
	<?php } ?>
</div>
Clément Damiens's avatar
 
Clément Damiens committed
266 267

<?php } ?>