Trying to set specific events to read-only but to no avail

Hi,

I just began experimenting with dhtmlxScheduler and was trying to set specific events to read-only. I have a “user” field I’ve added for each event in mysql and I want users to only be able to edit/delete the events that have their id in the user field. Whenever I try to add the following snippet of code (I have an event_id of 7 in my table):

scheduler.getEvent(7).readonly = true;

the page stops rendering.

Here is my more complete code:

<script type="text/javascript" charset="utf-8">
        function init() {

        var locations = [
        <?php
         include("mysql.php");
         connect_to_database();
         $result = mysql_query("select * from locations order by city asc;");
         for ($i=0 ; $i<mysql_num_rows($result)-1; $i++) {
            echo "{ key: ".mysql_result($result,$i,"id").", label: \"".
              mysql_result($result,$i,"name_long")."\" },";
         }
         echo "{ key: ".mysql_result($result,$i,"id").", label: \"".
            mysql_result($result,$i,"name_long")."\" }";
?>
];
                scheduler.config.xml_date="%Y-%m-%d %H:%i";
                scheduler.config.prevent_cache = true;

                scheduler.config.lightbox.sections=[
                        {name:"description", height:130, map_to:"text", type:"textarea" , focus:true},
                        {name:"location", options: locations, map_to:"location", type:"select",
                          image_path: "../../../dhtmlxcombo/codebase/imgs/", cache:false },
                        {name:"time", height:72, type:"time", map_to:"auto"}
                ]
                scheduler.config.first_hour=4;
                scheduler.locale.labels.section_location="Location";
                scheduler.config.details_on_create=true;
                scheduler.config.details_on_dblclick=true;
                scheduler.config.start_on_monday=false;
                scheduler.config.hour_date="%h:%i %A";

<?php
if ($_GET["user"] == -1) { // <-- works great (-1 signifies "public user/unregistered")
  echo "scheduler.config.readonly_form = true;";
}
//echo "scheduler.getEvent(7).readonly = true;"; <-- this is the troublesome line

 ?>
                scheduler.init('scheduler_here',new Date(<?php echo date("Y,m-1,d"); ?>),"month");

                scheduler.setLoadMode("month")
                scheduler.load("php/events.php?user=<?php echo $_GET["user"]; ?>");

                var dp = new dataProcessor("php/events.php?user=<?php echo $_GET["user"]; ?>");
                dp.init(scheduler);
        }
</script>

You need to call that line only after events are loaded from server side

scheduler.load(“php/events.php?user=<?php echo $_GET["user"]; ?>”, function(){
scheduler.getEvent(7).readonly = true;
});

i tried it after the .load() initially but outside of the callback and was not able to get it to work. i tried your way and it did work, though. not quite sure why. but thank you for your help! :smiley:

Loading is async, so placing command just after load is not enough, you need to catch the moment when data is fully loaded, using callback is one of the ways to do so.

I’m having a problem with this. I’m loading multiple sources and it doesn’t seem to work. Here is the code I’m using

[code]scheduler.load([“calendar_data_extra_xml.php?project_id=<?=$_GET['project_id']?>”, “calendar_data.php?project_id=<?=$_GET['project_id']?>”], function(){
scheduler.getEvent(2).readonly = true;
scheduler.getEvent(3).readonly = true;
scheduler.getEvent(4).readonly = true;
scheduler.config.readonly_form = true;
});

	var dp = new dataProcessor("calendar_data.php?project_id=<?=$_GET['project_id']?>");[/code]

However when I look at the log, it’s still running a query when I move the readonly ones. The readonly source should be calendar_data_extra_xml.php.

Hello,

So in your case event with ids 2, 3 and 4 didn’t become readonly?

How exactly do you check that?

If all events from that source should be readonly then you can do following: set some custom property for such events during select and then make simply check if (ev.that_property) then ev.readonly = true in the onBeforeLightbox event.

Kind regards,
Ilya

On the server page I’m logging the queries so I can see what it’s doing.

Can you provide an example of this?

Hello,

calendar_data_extra_xml.php:

... if ($scheduler->is_select_mode()) //code for loading data $scheduler->render_sql("SELECT text, start_date, end_date, event_id, 'true' as readonly FROM events", "event_id", "text, start_date, end_date, readonly");
Now events from that source will already have ‘readonly’ flag set to true.

Kind regards,
Ilya

Hi all,

I met some trouble by passing the readonly param from server-side.

I show you how my Json flux is structured

{
“id”: “43”,
“user_id”: “68”,
“start_date”: “2011-11-14 10:40”,
“end_date”: “2011-11-14 10:55”,
“text”: “New event”,
“color”: “#B6FBE2”,
“readonly”: “true”
}

The readonly property does not seems to be set by this way.

Does anyone tried to set this param directly inside the events flux or anybody have an idea if this behavior is logic?

Thank you for your responses