Prevent changes to created_by and version tags on changesets
authorAndy Allan <gravitystorm@gmail.com>
Tue, 17 Aug 2010 17:23:12 +0000 (17:23 +0000)
committerAndy Allan <gravitystorm@gmail.com>
Tue, 17 Aug 2010 17:23:12 +0000 (17:23 +0000)
TODO.txt
net/systemeD/potlatch2/save/SaveDialog.mxml

index f1cb4fa..8426297 100644 (file)
--- a/TODO.txt
+++ b/TODO.txt
@@ -19,7 +19,6 @@ Potlatch 2: main outstanding issues
 == Saving ==
 
 * Should be able to reuse changesets
-* Shouldn't be able to change created_by and version on changeset
 
 == Tag editing ==
 
index a3fa522..c8ab631 100644 (file)
@@ -30,7 +30,9 @@
         <mx:VBox width="100%" height="100%" label="Advanced">
           <mx:Label text="Changeset tags:"/>
           <mx:DataGrid editable="true" width="100%" id="advancedTagGrid"
-              dataProvider="{changesetTags}">
+              dataProvider="{changesetTags}"
+              itemEditBeginning="allowForEdit(event)"
+              itemEditEnd="verifyInput(event)">
             <mx:columns>
                 <mx:DataGridColumn editable="true" dataField="k" headerText="Key"/>
                 <mx:DataGridColumn editable="true" dataField="v" headerText="Value"/>
@@ -75,6 +77,8 @@
     import mx.controls.*;
     import mx.managers.PopUpManager;
        import mx.core.Application;
+    import mx.events.DataGridEvent;
+    import mx.events.DataGridEventReason;
     
     import net.systemeD.halcyon.connection.*;
     
         conn.createChangeset(tags);
     }
 
+    private function allowForEdit(event:DataGridEvent):void {
+        /* check before editing the tag grid that it's neither created_by nor version tags */
+        var item:Object = ((event.currentTarget as DataGrid).dataProvider as ArrayCollection)[event.rowIndex];
+        if(item.k == 'created_by' || item.k == 'version') {
+          event.preventDefault();
+        }
+    }
+
+    private function verifyInput(event:DataGridEvent):void {
+        /* check before saving any change that the new key isn't created_by nor version */
+        // it is OK if the user cancels the edit
+        if( event.reason == DataGridEventReason.CANCELLED ) return;
+
+        var editor:TextInput = (event.currentTarget as DataGrid).itemEditorInstance as TextInput;
+
+        if( event.dataField == "k" ) {
+          if( editor.text == 'created_by' || editor.text == 'version' ) {
+            event.preventDefault();
+          }
+        }
+    }
+
     private function changesetCreated(event:EntityEvent):void {
         var changeset:Changeset = conn.getActiveChangeset();
         addStatus("Changeset created (id: "+changeset.id+")");