acceptAndAdmin.php 9.33 KB
Newer Older
Tibor Katelbach's avatar
Tibor Katelbach committed
1
<script type="text/javascript">
Clément Damiens's avatar
 
Clément Damiens committed
2 3 4

		//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
5
		//var sectionDyf = {};
Clément Damiens's avatar
 
Clément Damiens committed
6 7 8 9 10 11 12 13 14 15 16
		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"]) ?>";

		var configDynForm = <?php echo json_encode(Yii::app()->session['costum']['dynForm']); ?>;
		var tplsList = <?php echo json_encode((isset(Yii::app()->session['costum']['tpls'])) ? Yii::app()->session['costum']['tpls']:null); ?>;
Tibor Katelbach's avatar
Tibor Katelbach committed
17
</script>
Clément Damiens's avatar
 
Clément Damiens committed
18
		
Tibor Katelbach's avatar
Tibor Katelbach committed
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
<?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
35
		}
Tibor Katelbach's avatar
Tibor Katelbach committed
36 37 38 39 40 41 42 43 44 45 46 47 48
		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
49 50 51 52

jQuery(document).ready(function() {


Tibor Katelbach's avatar
Tibor Katelbach committed
53 54 55 56 57 58 59 60
    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
61
                    }
Tibor Katelbach's avatar
Tibor Katelbach committed
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
                }
            };
            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
94 95
                }

Tibor Katelbach's avatar
Tibor Katelbach committed
96 97 98
        	}
            dyFObj.openForm( activeForm );
    });
Clément Damiens's avatar
 
Clément Damiens committed
99

Tibor Katelbach's avatar
Tibor Katelbach committed
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
    $('.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
133
    });
Tibor Katelbach's avatar
Tibor Katelbach committed
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 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 245 246 247 248 249 250

	$(".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" >
  
  	<?php //echo Yii::app()->session["costum"]["contextId"]."<br/>" ?>
	<?php //echo Yii::app()->session["costum"]["contextType"]."<br/>" ?>
	<?php //echo Yii::app()->session["costum"]["contextSlug"]."<br/>" ?>
	<?php //var_dump(Yii::app()->session["costum"]) ?>

  	<?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>
	
	<?php } else if(isset(Yii::app()->session['costum']["dynForm"])) {
        ?>
	<!-- <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>
    <a class="btn btn-default" href="#@<?= Yii::app()->session["costum"]["contextSlug"] ?>" data-hash="#page.type.<?= Yii::app()->session["costum"]["contextType"] ?>.id.<?= Yii::app()->session["costum"]["contextId"] ?>" target="_blank"><i class="fa fa-id-card-o" aria-hidden="true"></i>
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
251 252

<?php } ?>