public function saveLayout(DashCols_LayoutModel $dashColsLayout)
 {
     $existingLayout = false;
     if ($dashColsLayout->id) {
         if (!($dashColsLayoutRecord = DashCols_LayoutRecord::model()->findById($dashColsLayout->id))) {
             throw new Exception(Craft::t('Could not find layout with ID "{id}"', array('id' => $dashColsLayout->id)));
         }
         $existingLayout = DashCols_LayoutModel::populateModel($dashColsLayoutRecord);
     } else {
         $dashColsLayoutRecord = new DashCols_LayoutRecord();
     }
     if ($dashColsLayout->sectionId) {
         $dashColsLayoutRecord->sectionId = $dashColsLayout->sectionId;
     } else {
         if ($dashColsLayout->categoryGroupId) {
             $dashColsLayoutRecord->categoryGroupId = $dashColsLayout->categoryGroupId;
         } else {
             if ($dashColsLayout->listingHandle) {
                 $dashColsLayoutRecord->listingHandle = $dashColsLayout->listingHandle;
             } else {
                 throw new Exception(Craft::t('Unknown target for layout'));
             }
         }
     }
     $dashColsLayoutRecord->hiddenFields = $dashColsLayout->hiddenFields;
     $dashColsLayoutRecord->metaFields = $dashColsLayout->metaFields;
     $dashColsLayoutRecord->validate();
     $dashColsLayout->addErrors($dashColsLayoutRecord->getErrors());
     if (!$dashColsLayout->hasErrors()) {
         $transaction = craft()->db->getCurrentTransaction() === null ? craft()->db->beginTransaction() : null;
         try {
             if ($existingLayout && $existingLayout->fieldLayoutId) {
                 craft()->fields->deleteLayoutById($existingLayout->fieldLayoutId);
             }
             $fieldLayout = $dashColsLayout->getFieldLayout();
             craft()->fields->saveLayout($fieldLayout);
             $dashColsLayout->fieldLayoutId = $fieldLayout->id;
             $dashColsLayoutRecord->fieldLayoutId = $fieldLayout->id;
             if (!$dashColsLayout->id) {
                 $dashColsLayoutRecord->save();
             } else {
                 $dashColsLayoutRecord->update();
             }
             $dashColsLayout->id = $dashColsLayoutRecord->id;
             if ($transaction !== null) {
                 $transaction->commit();
             }
         } catch (\Exception $e) {
             if ($transaction !== null) {
                 $transaction->rollback();
             }
             throw $e;
         }
         return true;
     }
     return false;
 }